Struts 2 Model Driven Approach

Struts 2 Model Driven Approach

In this demo you will see how to implement model driven approach in struts 2 application. Basically when use struts application there is two way to populate request:

  • Bound request parameters directly into the fields in your action class.
  • Implements interface com.opensymphony.xwork2.ModelDriven in your action class and override its method getModel() method and return object from it, then struts framework populate fields of this object with request parameters

Steps:

  • Create maven project name: Struts2ModelDriven
  • Final project structure:

Struts 2 Model Driven Approach

  • pom.xml dependency:

  • index.jsp:

  • success.jsp:

  •  Person.java

  •  ModelDrivenAction.java

Struts 2 Model Driven Approach

  • Enter data in input fields:

Struts 2 Model Driven Approach

  • Click Submit button you will see output of entered data as below:

Struts 2 Model Driven Approach

For more information on Model driven approach please read from struts 2 site here

download Download Project:  Struts2ModelDriven

Leave a Reply

Your email address will not be published. Required fields are marked *