我正在使用Primefaces的PickList,如下所示:
在xhtml ....
<p:pickList valueChangeListener="#{bean.handlePickList}" onTransfer="submit()" value="#{bean.currentField.PICK_VALUES" id="myPickVals" var="pickVals" itemLabel="#{pickVals}" itemValue="#{pickVals}"/>
在豆......
public class MyFields{
public void handlePickList(ValueChangeEvent e) {
System.out.println("in handlePickList routine of MyFields.java. ");
}
}
我收到错误....
Property 'handlePickList' not found on type com.myproj.common.MyFields
如何从PickList的目标列表中获取用户选择的值?
答案 0 :(得分:0)
per showcase example:
提供给列表的值必须放在primeface的DaulListModel中。
在你的bean中:
private DualListModel<yourObjectType> listItems;
public DualListModel<yourObjectType> getListItems() {
if(listItems == null){
List<yourObjectType> listItemsSource = new ArrayList<yourObjectType>();
List<yourObjectType> listItemsTarget = new ArrayList<yourObjectType>();
... populate the source and target accordingly ...
listItems= new DualListModel<yourObjectType>(listItemsSource , listItemsTarget );
}
return listItems;
}
public void setListItems(DualListModel<yourObjectType> listItems) {
this.listItems = listItems;
}
将listItems放入jsf标记的值属性
value="#{bean.listItems}"
在提交时,只需访问所选的列表项,如下所示:
getListItems().getTarget()
fyi,您可能需要创建并提供转换器才能使用所需的对象类型。