我正在使用Primefaces 3.4和JSF 2.1,我試圖讓一個p:面板項目出現並消除關於p:oneselectmenu
的選擇。我在面板內有一個p:datatable
,我想要顯示並動態填充,這就是我使用面板的原因。數據表的工作很好,但面板沒有。我嘗試將面板上的「渲染」選項與隨菜單的每個選項更改而變化的變量進行鏈接,但沒有發生任何事情。我也嘗試過p:outputpanel
,但沒有發生任何事情。所以我試着用同樣的動作按鈕,但它失敗了。這是我的代碼:如何渲染一個p:面板,由選擇p:selectonemenu觸發?
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="/template.xhtml">
<ui:define name="title">
#{msg.teaching}: #{msg.socialSecurity}
</ui:define>
<ui:define name="body">
<h:form id="form">
<p:messages id="messages" autoUpdate="true"/>
<p:panel id="selectSocialSecurityPanel" rendered="true">
<p:panelGrid>
<p:row>
<p:column>
<p:selectOneMenu value="#{selectOneMenuSocialSecurityTeachingBean.choice}">
<p:ajax update="socialSecurityDataTablePanel, socialSecurityDataTable, toUpdate" listener="#{dataTableSocialSecurityBean.updateTable()}"/>
<f:selectItem itemLabel="#{msg.select}" itemValue=""/>
<f:selectItems value="#{selectOneMenuSocialSecurityTeachingBean.socialSecurityTeachingList}"/>
</p:selectOneMenu>
</p:column>
<p:column>
<p:commandButton value="#{msg.find}" actionListener="#{dataTableSocialSecurityBean.updateTable()}" update="socialSecurityDataTablePanel, socialSecurityDataTable, toUpdate" id="button">
<f:ajax render="toUpdate"/>
</p:commandButton>
</p:column>
</p:row>
</p:panelGrid>
</p:panel>
<p:outputPanel id="toUpdate" rendered="#{dataTableSocialSecurityBean.rendered}" autoUpdate="true">
<p:panel id="socialSecurityDataTablePanel">
<p:dataTable id="socialSecurityDataTable" var="unit" value="#{dataTableSocialSecurityBean.socialSecurityList}">
<p:columns value="#{dataTableSocialSecurityBean.columns}" var="column" columnIndexVar="colIndex">
<f:facet name="header">
#{column.header}
</f:facet>
#{unit[column.property]}
</p:columns>
</p:dataTable>
</p:panel>
</p:outputPanel>
</h:form>
</ui:define>
</ui:composition>
</h:body>
這:
@ManagedBean
@ViewScoped
public final class DataTableSocialSecurityBean implements Serializable {
private String choice;
private List<Unit> socialSecurityList;
private boolean rendered;
private List<ColumnModel> columns = new ArrayList<ColumnModel>();
public boolean getRendered(){
System.out.println("DataTableSocialSecurityBean getRendered");
System.out.println("DataTableSocialSecurityBean getRendered="+rendered);
return rendered;
}
public void updateTable() {
rendered=true;
socialSecurityList = new ArrayList<Unit>();
createDynamicColumns();
populateDataTable(socialSecurityList);
}
}
任何想法?
謝謝,它工作的很好。 –
不客氣。 – partlov
你知道是否有可能在面板出現/消失時發揮作用,而不是從無到有? –