Sid*_*kha 5 java jsp struts2 ognl jakarta-ee
我有一个变量:
private ArrayList<LabelValueBean> circleNameIdList;
Run Code Online (Sandbox Code Playgroud)
在我的Action班级中,它的价值被填充。
I want to display the label in my drop-down in JSP and when one label is selected, the corresponding value to that particular label in circleNameIdListto be passed to the server. 例如:如果 label:NewYork被选中,那么它是对应的id = 5,被发送到服务器。
我怎样才能做到这一点?
到目前为止,我在 JSP 中是这样做的:
<s:select list="#session.circleNameIdList" label="Select Circle:" name="circleNameIdList" id="circleNameIdList"></s:select>
Run Code Online (Sandbox Code Playgroud)
但是,显示不正确。
我看到您正在使用 aLableValueBean来填充并显示下拉列表。它是一个以前的 bean,最后用于显示对象列表。在 Struts2 中,您不再需要这样的辅助 bean。您可以通过指定一个键字段来显示对象列表,该键字段将保存所选选项的唯一值和要显示为选项文本的值。例如,如果您的对象
public class Circle {
private Long id;
//getter and setter here
private String name;
//getter and setter here
}
Run Code Online (Sandbox Code Playgroud)
你在行动课上
private List<Circle> circleNameIdList;
//getter and setter here
/**
* Hold the selected value
*/
private Long circleId;
//getter and setter here
Run Code Online (Sandbox Code Playgroud)
然后
<s:select id="circleNameIdListID" label="Circle:" name="circleId"
list="circleNameIdList" listKey="id" listValue="name" headerKey="-1" headerValue="Select Circle"/>
Run Code Online (Sandbox Code Playgroud)
可用于显示下拉列表。
| 归档时间: |
|
| 查看次数: |
7524 次 |
| 最近记录: |