Spy*_*iam 2 jsf panel selectonemenu primefaces
我正在使用Primefaces 3.4和JSF 2.1,我试图让ap:panel项目出现并消除选择p:oneselectmenu.我有一个p:datatable面板,我想要出现并动态填充,这就是我使用面板的原因.数据表的功能很好,但是面板没有.我尝试将面板上的"呈现"选项与一个变量相关联,该变量随着菜单的每个选择的变化而变化,但没有发生任何事情.我也尝试过,p:outputpanel但没有发生任何事情.所以我尝试使用具有相同操作的按钮但又失败了.这是我的代码:
<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>
Run Code Online (Sandbox Code Playgroud)
还有这个:
@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);
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
您的rendered字段最初是false因为面板不会在第一个视图上呈现.在初始HTML的视图中,没有带id的标记,toUpdate因此无法呈现.我建议你把它panel放在一些h:panelGroup并重新渲染这个组件:
<h:panelGroup id="myContainer" layout="block">
<p:outputPanel id="toUpdate" rendered="#{dataTableSocialSecurityBean.rendered}" autoUpdate="true">
</p:outputPanel>
</h:panelGroup>
Run Code Online (Sandbox Code Playgroud)
你用render="myContainer".我还建议你使用p:ajax而不是f:ajaxprimefaces组件.
您可以尝试添加效果添加p:effect组件作为子项p:outputPanel:
<p:effect type="explode" event="load"/>
Run Code Online (Sandbox Code Playgroud)
有关完整事件列表,请参阅PrimeFaces用户指南.
| 归档时间: |
|
| 查看次数: |
8816 次 |
| 最近记录: |