I have a JSP page with 1 text box like: <html:text property="testVal" />
I have linked a form with this JSP page to hold the property and defined the getters and setters.
Now on submitting the form, an action is being called and i pull the data from DB depending upon the value received from the FORM.
I put all the values got from the DB to a bean and set this bean to Request scope and then forward to another JSP to display these values.
In that JSP i display values as read only but for one value i have to show a drop down list and depending upon one value got from DB, i have to select the text in that drop down. For Example if i have drop down list with values 1,2,3 and i get value 2 from DB, then i want to select the text against value 2.
So how can i achieve that? As it is required by STRUTS that to select a specific value, we need to set it in the form. But in this case how can i set the value in the FORM? I have attached a form with this later JSP too but in that previous action where i pull the data from DB i have the instance of other form with 1 value.
Struts will populate the options of the dropdown by calling getList() on your form bean, which should return an array or collection of values. Struts will then use the value returned by getX() to decide which option is selected. For example, if getList() returns 1, 2, and 3 and getX()returns 2, option 2 will display as selected. [ November 01, 2005: Message edited by: Merrill Higginson ]
I know that and I have defined that <html:select> the same way but how can i set the property of that form bean as i don't get that form bean instance in the action. I get the instance of previous form which is submitted to the action.
As long as you have created a bean that extends ActionForm, you can instantiate that bean any time you want, populate it's properties, and put it in the desired scope. The solution, then is in the Action class that is called by the first page, instantiate the form bean used by the second page, populate it's properties, and place it in the appropriate scope (request, session, appplication). The second page will then display the values properly.