Jsf h:selectManyListBox设置器未设置所有选定值
支持Bean有:Jsf h:selectManyListBox设置器未设置所有选定值,jsf,Jsf,支持Bean有: <h:selectManyListbox id="sectorsListBox" size="2" multiple="multiple" value="#{Mybean.classificationSelectedItems}"> <f:selectItems id="sectors" value="#{Mybean.classificationSelectItems}"/> </h:selectManyListbox> 公
<h:selectManyListbox id="sectorsListBox" size="2" multiple="multiple" value="#{Mybean.classificationSelectedItems}">
<f:selectItems id="sectors" value="#{Mybean.classificationSelectItems}"/>
</h:selectManyListbox>
公共类Mybean
{
私有映射classificationSelectItems=新建LinkedHashMap();
私有列表classificationSelectedItems=new ArrayList();
//二者兼得。
}
init()
{
分类选择项目。投入(“投入”,“保险”)
分类选择项。put(“HLC”、“医疗保健”)
}
使用这两个值初始化“选择多个”框,但问题是只有最后选择的条目存储在classificationSelectedItems中。为什么会这样?我如何获取存储在classificationSelectedItems列表中的所有选定条目
添加仅供参考,init方法是按Spring分类的。我已经用examle(参考:)进行了测试,祝你好运:) Facelets:
public class Mybean
{
private Map<String,String> classificationSelectItems = new LinkedHashMap<String,String>();
private List<String> classificationSelectedItems = new ArrayList<String>();
//getter and setter for both.
}
init()
{
classificationSelectItems.put("INS","Insurance")
classificationSelectItems.put("HLC","HealthCare")
}
<h:form id="form">
<h:selectManyListbox value="#{user.favFood1}" >
<f:selectItems value="#{user.favFood2Value}" />
</h:selectManyListbox>
<h:commandButton value="test"/>
</h:form>
Bean:
public class Mybean
{
private Map<String,String> classificationSelectItems = new LinkedHashMap<String,String>();
private List<String> classificationSelectedItems = new ArrayList<String>();
//getter and setter for both.
}
init()
{
classificationSelectItems.put("INS","Insurance")
classificationSelectItems.put("HLC","HealthCare")
}
<h:form id="form">
<h:selectManyListbox value="#{user.favFood1}" >
<f:selectItems value="#{user.favFood2Value}" />
</h:selectManyListbox>
<h:commandButton value="test"/>
</h:form>
@ManagedBean(name=“user”)
@视域
公共类UserBean实现了可序列化{
私有静态最终长serialVersionUID=1L;
公开名单favFood1;
私有地图价值;
公共用户bean(){
favFood1=新的ArrayList();
food2Value=newlinkedhashmap();
food2Value.put(“Food2-frychecken”,“frychecken1”);//标签,值
food2Value.put(“Food2-汤圆汤”、“汤圆汤2”);
food2Value.put(“Food2-混合大米”、“混合大米3”);
}
公共列表getFavFood1(){
返回favFood1;
}
公共作废设置favFood1(列表favFood1){
this.favFood1=favFood1;
}
公共地图getFavFood2Value(){
返回值;
}
}
在setter方法中使用集合时,我注意到了这种行为,如
@ManagedBean(name = "user")
@ViewScoped
public class UserBean implements Serializable {
private static final long serialVersionUID = 1L;
public List<String> favFood1;
private Map<String, Object> food2Value;
public UserBean() {
favFood1 = new ArrayList<String>();
food2Value = new LinkedHashMap<String, Object>();
food2Value.put("Food2 - Fry Checken", "Fry Checken1"); //label, value
food2Value.put("Food2 - Tomyam Soup", "Tomyam Soup2");
food2Value.put("Food2 - Mixed Rice", "Mixed Rice3");
}
public List<String> getFavFood1() {
return favFood1;
}
public void setFavFood1(List<String> favFood1) {
this.favFood1 = favFood1;
}
public Map<String, Object> getFavFood2Value() {
return food2Value;
}
}
请注意,更改后需要重新部署应用程序,因为JSP需要重新编译,但这并不是自动完成的。我刚刚用示例进行了测试,效果良好(我使用List alter String[]):如果同时选择保险和医疗,两个都在你的classificationSelectedItems中设置了吗?你能发布代码吗?当然,两个都有。我也是,我正在使用mojarra 2.1.21:)