Reputation: 395
I don't want to declare those variables in Action class again
Employee POJO:
package com.pojo;
import java.io.Serializable;
public class Employee{
String name;
Address address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}
AddressPOJO:
package com.pojo;
import java.io.Serializable;
public class Address{
String email;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
JSP:
<body>
<s:form action="beanEx">
<s:textfield label="name" name="name"/>
<s:textfield label="email" name="email"/>
<s:submit value="Submit"/>
</s:form>
</body>
I want to populate the values automatically set the values in Action class
Can anybody help me out........
Upvotes: 0
Views: 7251
Reputation: 20323
Have two objects in your action class with getter/setter
private Address address = new Address();
private Employee employee = new Employee();;
then in your jsp do like this:
<body>
<s:form action="beanEx">
<s:textfield name="employee.name" label="name"/>
<s:textfield name="address.email" label="email"/>
<s:submit value="Submit"/>
</s:form>
</body>
Basically earlier you were pointing to the field now you are pointing to the field inside an object.
Upvotes: 1