Using a LabelValueBean properly(正确使用 LabelValueBean)
问题描述
我有一个变量:
private ArrayList<LabelValueBean> circleNameIdList;
在我的 Action
类中填充它的值.
inside my Action
class where it's value get populated.
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 circleNameIdList
to be passed to the server.例如:如果标签:NewYork
被选中,那么它对应的id = 5
,被发送到服务器.
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 circleNameIdList
to be passed to the server.
Eg.: If label: NewYork
is selected then it's corresponding id = 5
, is sent to the server.
我怎样才能做到这一点?
How can I achieve this?
到目前为止,我在 JSP 中都是这样做的:
Up till now I was doing like this in JSP:
<s:select list="#session.circleNameIdList" label="Select Circle:" name="circleNameIdList" id="circleNameIdList"></s:select>
但是显示不正确.
推荐答案
我看到您正在使用 LableValueBean
来填充和显示下拉列表.它是一个以前的 bean,最后用于显示对象列表.在 Struts2 中,您不再需要这样的辅助 bean.您可以通过指定一个键字段来显示对象列表,该键字段将包含所选选项的唯一值以及要显示为选项文本的值.例如,如果您的对象
I see you are using a LableValueBean
to populate and show a dropdown. It's a former bean used at last to display a list of objects. In Struts2 you're no longer required such a helper bean. You can display a list of objects by specifying a key field that would hold a unique value of the selected option and a value to be shown as the option text. For example if your object
public class Circle {
private Long id;
//getter and setter here
private String name;
//getter and setter here
}
你在动作类中
private List<Circle> circleNameIdList;
//getter and setter here
/**
* Hold the selected value
*/
private Long circleId;
//getter and setter here
然后
<s:select id="circleNameIdListID" label="Circle:" name="circleId"
list="circleNameIdList" listKey="id" listValue="name" headerKey="-1" headerValue="Select Circle"/>
可用于显示下拉菜单.
这篇关于正确使用 LabelValueBean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:正确使用 LabelValueBean
基础教程推荐
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01