How an actionForm bean is created?
A form bean is a simple java class which is an instance of a subclass of an ActionForm class, which stores HTML form data from a submitted client request or that can store input data from a Struts action link that a user clicked. A form-bean mapping is an entry in a Struts configuration file that maps the form-bean name to an ActionForm class.
form type is a normal java class extending the ActionForm class.
Example:
public class StudentForm extends ActionForm {}
Once it is created, you have to specify a
name for the FormBean in the struts configuration file
Example:
<form-beans >
<form-bean name=“studentForm†type=“stu.pack.StudentForm†/>
</form-beans>
The form bean can be used in an Struts
action. Below there is an example of an ActionMapping using our form
bean.
Example:
<action attribute=“studentFormâ€
name=“studentFormâ€
path=“/formâ€
scope=“requestâ€
type=“stu.pack.StudentAction†/>
Example:
public class StudentForm extends ActionForm {
//properties
private String name;
private int age;
//Getter and Setter methods
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Read More →