I have a doubt. How the Struts2 Modeldriven
interface works. In my application I used for a single form. And I placed setters and getters as same as form names. Is it possible to place multiple ModelDriven
objects with setter and getter. If I placed like that then how it will recognize?
相关问题
- Java/Struts2: How to get action name from current
- NPE in StrutsTestCase after enabling Tiles
- In Tiles,Struts2 java.lang.NoClassDefFoundError: o
- Validating double field in struts 2
- How to use multiple forms / actions in a single vi
相关文章
- Struts2 file upload max size
- Current URL /web/guest/HTML generates exception: n
- UrlRewrite Struts2 setting parameter variables
- How to Set a HashMap from jsp to Action
- Struts 2 jQuery plugin isSubscribe not working
- How to set the values in session?
- Null values are insering in data base using Struts
- Why do we use struts tags and not the old HTML tag
In case of
ModelDriven
, you can populate only one pojo at a time. You can not use multipleModelDriven
in single action class. BecausegetModel()
method populate the Object of the Pojo which is specified inModelDrive<Pojo>
.It will try to find the getter in this pojo. The name of the field should be matched with the form names.Any action implementing the
ModelDriven
interface must supply agetModel()
method which returns the object that represents the action's model. Any parameters passed to the action are assumed to be sub-properties of the model. You may only have one model per action in a ModelDriven action.For example, lets assume we have a model called
Profile
and an action to edit our profile. In our form, we have a text field for our website. Without usingModelDriven
, you would havegetWebsite
andsetWebsite
methods on your action. WithModelDriven
, the getter and setter on the model would be called instead. Effectively,getModel().setWebsite("http://stackoverflow.com")
.Example
Agree... ModelDriven looks similar to ActionForm in Struts1 and to have the similarity i believe this approach is provided. Even then if u have your model, with many composition u would have to follow the ObjectBacked approach to set the contained object values in the model.