In struts1.2 how to populate dropdown according to

2019-07-20 10:44发布

问题:

I have a textboxes and one dropdown on html whose value is getting saved to database on clicking save button but on searching for the value all textboxes and radio button are getting populated except the foloowing dropdown ..

      <td align= "right" nowrap> 
                            <html:select property="standard">

                                <html:option value="I">I</html:option>

                                <html:option value="II">II</html:option>

                                <html:option value="III">III</html:option> ...

and for populating the values i am using th following code..

        stuform.setStandard((String)tempmap.get("STANDARD"));

Note: I have checked stuform.getStandard() value is there but it is not getting displayed on jsp.

回答1:

The dropdown list should be represented by a list of LabelValueBean objects in your form class as follows.

List<LabelValueBean> listOfStandards = new ArrayList<LabelValueBean>();
//popoulate the list
myForm.setStandardList(listOfStandards);

And in your jsp you can access the list in your drop down list as follows:

<html:select property="standard" styleId="standard">
    <html:optionsCollection name="myForm" property="standardList" label="label" value="value"  />
</html:select>

Note: Make sure you have a "standard" property in your form. The "standard" property will be set with the value of the selected item from the dropdown list.