我有一个代码:
<h:panelGroup>
<p:panel>
<p:commandButton value="Go" style="background:#25A6E1;color:#fff;font-family:'Helvetica Neue',sans-serif;font-size:10px;border-radius:4px;"
actionListener="#{customCalender.searchUserofList}" update="picklist">
<f:attribute name="trigram" value="#{customCalender.listTrig}"/>
<f:attribute name="firstName" value="#{customCalender.listFname}"/>
<f:attribute name="lastName" value="#{customCalender.listLname}"/>
<f:attribute name="teamName" value="#{customCalender.selectedTeam}"/>
</p:commandButton>
</p:panel>
</h:panelGroup>
<h:panelGroup id="picklist" rendered="#{not empty customCalender.searchList}">
<p:pickList value="#{customCalender.searchList}" var="user" itemLabel="#{user}" itemValue="#{user}"/>
</h:panelGroup>
并在方法searchList
中按下按钮生成searchUserofList()
。
我将searchList
声明为:
私有DualListModel searchList;
public DualListModel<String> getSearchList() {
return searchList;
}
public void setSearchList(DualListModel<String> searchList) {
this.searchList = searchList;
}
并在方法searchUserofList
方法中定义,如:
List<EmpBean> list = new ArrayList<EmpBean>();
list = getSearchResult("people",trigram,firstName,lastName,teamName);
Iterator<EmpBean> iterator = list.iterator();
List<String> userList = new ArrayList<String>();
List<String> userTarget = new ArrayList<String>();
while(iterator.hasNext()){
String userName = iterator.next().getStrUserid();
System.out.println("Name :: "+userName);
userList.add(userName);
}
searchList = new DualListModel<String>(userList, userTarget);
但是当点击按钮时,它会获得列表,但是没有显示带有值的选项列表。 如何才能正确显示选项列表?请提出建议。
答案 0 :(得分:0)
您无法动态更新未呈现的组件,您应移动rendered
属性,以便组件始终存在。
<h:panelGroup id="picklist">
<p:pickList rendered="#{not empty customCalender.searchList}" value="#{customCalender.searchList}" var="user" itemLabel="#{user}" itemValue="#{user}"/>
</h:panelGroup>