gpt4 book ai didi

jsf - 如何呈现从选择 p :panel, 触发的 p :selectonemenu?

转载 作者:行者123 更新时间:2023-11-30 23:49:02 26 4
gpt4 key购买 nike

我正在使用 Primefaces 3.4 和 JSF 2.1,并且我正在尝试让一个 p: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>

还有这个:

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

}
}

有什么想法吗?

最佳答案

您的 rendered 字段最初是 false 因此面板不会在第一个 View 中呈现。在初始 HTML 的 View 中,没有带有 id toUpdate 的标记,因此无法呈现它。我建议你将这个 panel 放在一些 h:panelGroup 中并重新渲染这个组件:

<h:panelGroup id="myContainer" layout="block">
<p:outputPanel id="toUpdate" rendered="#{dataTableSocialSecurityBean.rendered}" autoUpdate="true">
</p:outputPanel>
</h:panelGroup>

并且您使用 render="myContainer"。我还建议您对 primefaces 组件使用 p:ajax 而不是 f:ajax

您可以尝试添加效果,将 p:effect 组件添加为 p:outputPanel 的子组件:

<p:effect type="explode" event="load"/>

有关事件的完整列表,请参阅 PrimeFaces 用户指南。

关于jsf - 如何呈现从选择 p :panel, 触发的 p :selectonemenu?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15743099/

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