gpt4 book ai didi

jsf - h :selectManyListBox setter not setting all the values selected

转载 作者:行者123 更新时间:2023-12-04 19:37:52 25 4
gpt4 key购买 nike

<h:selectManyListbox id="sectorsListBox"  size="2" multiple="multiple" value="#{Mybean.classificationSelectedItems}">
<f:selectItems id="sectors" value="#{Mybean.classificationSelectItems}"/>
</h:selectManyListbox>

Backing 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")
}

使用这两个值初始化多选框,但问题是只有最后选择的条目存储在 classificationSelectedItems 中。为什么 ?以及如何将所有选定条目存储在 classificationSelectedItems 列表中?

添加仅供引用,init 方法是 Spring 类。

最佳答案

我已经用examle测试了(引用:http://www.mkyong.com/jsf2/jsf-2-multiple-select-listbox-example/),祝你好运:)

小面:

<h:form id="form">
<h:selectManyListbox value="#{user.favFood1}" >
<f:selectItems value="#{user.favFood2Value}" />
</h:selectManyListbox>
<h:commandButton value="test"/>
</h:form>

bean 类:

@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;
}
}

关于jsf - h :selectManyListBox setter not setting all the values selected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16269734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com