Skip to main content


Showing posts from March, 2012

Struts 2 | ModelDriven to handle Form Data

In struts2, values of request parameters(HTML form's fields) are mapped to matching properties of the action class . Struts populates the values come in Http Request to the variables having same name of input fields of the HTML form. When we want to persist the data received form request, it needs to be in model object that can be persisted by ORM framework like JPA or Hibernate. So if we are using the Action class to handle the values from form, we have to mark it as Entity for JPA/Hibernate to persist its data. Therefore using the action class as Entity class is not a best practice. Struts2 provides another option to handle to form data. We can use separate Entity bean/Object to receive the form data rather than Action class. In terms of struts, it is called Model object. This is the same thing as Entity object in terms of JPA/Hibernate. In struts, we have to implement the ModelDriven interface that has the getModel method. This method returns the model object an