正确使用LabelValueBean [英] Using a LabelValueBean properly

查看:310
本文介绍了正确使用LabelValueBean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量:

private ArrayList<LabelValueBean> circleNameIdList;

在我的行动类中,它的价值得到填充。

inside my Action class where it's value get populated.

我想在JSP的下拉列表中显示标签,当选择一个标签时, circleNameIdList中该特定标签的相应值要传递给服务器。
Eg。:如果标签: 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>

然而,它显示不正确。

However, it display is not correct.

推荐答案

我看到您正在使用 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
} 

你有行动class

private List<Circle> circleNameIdList;
//getter and setter here

/**
 * Hold the selected value
 */
private Long circleId;
//getter and setter here

then

<s:select id="circleNameIdListID" label="Circle:" name="circleId" 
  list="circleNameIdList"   listKey="id" listValue="name" headerKey="-1" headerValue="Select Circle"/>

可用于显示下拉列表。

这篇关于正确使用LabelValueBean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆