This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
In the modelDriven approach in struts2 corresponding to an action there is a model object that is returned from within the action class.
Is it neccessary that there is only one type of model object required to be returned. why not more than one.
say a user enters the information in a form. this information can be divided into 2 different chunks one portion related to his personal details that goes to UserTable another related to "question" asked by him that goes to QuestionsTable. Correspondingly for personal details of every Visitor we have a VisitorBean and Question details are stored in the QuestionBean. now in a single action how can we invoke both the beans using a ModelDriven approach when we can have only single Bean object to returned using getModel() method.
Such situations are very common where a single form is used to populate several different Beans? What is the best way to do it ?
I faced the similar problem and I made it work in very low level.
I placed a if-else check in prepare() and handle the beans by the parameter values..
Maybe I could have done it with some patterns for the higher level. But it seems meaningless to me.
In your example, I think each different cases should be connected to each different actions..or separate each cases to two forms.
I think two irrelevant cases are in one form and that's where the problem begins..
Well, I'm not sure my thoughts are right and wanna know how the ohters think about this..
Joined: Aug 03, 2008
Yes there are ways to handle it but then the basic purpose behind the modelDriven approach is defeated. here is the problem that i am really facing. i am thinking of somthing like action chaining.
what if a particular action requires more than one model objects to be pushed to the value stack. say i am creating an application for online forums. Any visitor can post a question without registering, all they need to do is provide few personal details.
now they need to provide following information through the form. PostThread.jsp
1. Name of User
2. Email Id of the User
3. City they belong to
5. Subject of the Question
6. Topic it belongs to
7. Question in detail
Now the data no. 1,2,3,4 are his personal information that must populate the Model called Visitor.java and the information 5,6,7 must populate the model object called Question.java. the action that must populate the two models is PostThreadAction.java. The result jsp i.e. will display all the details entered by the user from 1 to 7. now for this my Action class PostThreadAction.java requires to return more than one Model Object - Visitor object and Question object to the value stack using getModel().