In struts1.2 how to populate dropdown according to database value

瘦欲@ 提交于 2019-12-11 01:34:34

问题


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.



来源:https://stackoverflow.com/questions/17273849/in-struts1-2-how-to-populate-dropdown-according-to-database-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!