PrimeFaces 命令按钮不更新
PrimeFaces CommandButton does not Update
我正在尝试通过按下按钮来更新网格面板(不应显示 Pie/Bar 图表):
<h:form>
<div class="ui-grid ui-grid-responsive">
<div class="ui-grid-row">
<div class="ui-grid-col-4">
<p:panelGrid columns="1" layout="grid"
styleClass="ui-panelgrid-blank">
...
<p:panelGrid columns="2" layout="grid" id="buttons"
styleClass="ui-panelgrid-blank">
<p:commandButton update="@form"
actionListener="#{buttonView.pieChart}" icon="ui-icon-disk"
title="Zeige Pie an" />
<p:commandButton update="@form"
actionListener="#{buttonView.barChart}" icon="ui-icon-disk"
title="Zeige Bar an" />
</p:panelGrid>
</p:panelGrid>
</div>
<div class="ui-grid-col-8">
<p>...</p>
<p:panelGrid columns="1" layout="grid"
styleClass="ui-panelgrid-blank" id="charts">
<p:chart id="pie" type="pie" model="#{userBean.model}"
responsive="true" />
<p:chart id="bar" type="bar" model="#{chartView.barModel}"
style="height:300px" responsive="true" />
</p:panelGrid>
</div>
</div>
</div>
</h:form>
我的代码似乎无法正常工作。
要隐藏和显示图表,您必须定义渲染属性 rendered
。 rendered
属性采用布尔值。
<p:panelGrid columns="1" layout="grid" styleClass="ui-panelgrid-blank" id="charts">
<p:chart id="pie" type="pie" rendered="#{buttonView.showPieChart}" model="#{userBean.model}" responsive="true" />
<p:chart id="bar" type="bar" rendered="#{buttonView.showBarChart}" model="#{chartView.barModel}" style="height:300px" responsive="true" />
</p:panelGrid>
该值应该在您的 Backing Bean 中设置,例如 buttonView
。
public class ButtonView {
...
private boolean isShowPieChart;
private boolean isShowBarChart;
...
}
最后切换布尔值。
<p:commandButton update="@form" actionListener="#{buttonView.pieChart}" icon="ui-icon-disk" title="Zeige Pie an" >
<f:setActionPropertyListener target="#{buttonView.showPieChart}" value="#{!buttonView.showPieChart}" />
</p:commandButton>
<p:commandButton update="@form" actionListener="#{buttonView.barChart}" icon="ui-icon-disk" title="Zeige Bar an" >
<f:setActionPropertyListener target="#{buttonView.showBarChart}" value="#{!buttonView.showBarChart}" />
</p:commandButton>
我正在尝试通过按下按钮来更新网格面板(不应显示 Pie/Bar 图表):
<h:form>
<div class="ui-grid ui-grid-responsive">
<div class="ui-grid-row">
<div class="ui-grid-col-4">
<p:panelGrid columns="1" layout="grid"
styleClass="ui-panelgrid-blank">
...
<p:panelGrid columns="2" layout="grid" id="buttons"
styleClass="ui-panelgrid-blank">
<p:commandButton update="@form"
actionListener="#{buttonView.pieChart}" icon="ui-icon-disk"
title="Zeige Pie an" />
<p:commandButton update="@form"
actionListener="#{buttonView.barChart}" icon="ui-icon-disk"
title="Zeige Bar an" />
</p:panelGrid>
</p:panelGrid>
</div>
<div class="ui-grid-col-8">
<p>...</p>
<p:panelGrid columns="1" layout="grid"
styleClass="ui-panelgrid-blank" id="charts">
<p:chart id="pie" type="pie" model="#{userBean.model}"
responsive="true" />
<p:chart id="bar" type="bar" model="#{chartView.barModel}"
style="height:300px" responsive="true" />
</p:panelGrid>
</div>
</div>
</div>
</h:form>
我的代码似乎无法正常工作。
要隐藏和显示图表,您必须定义渲染属性 rendered
。 rendered
属性采用布尔值。
<p:panelGrid columns="1" layout="grid" styleClass="ui-panelgrid-blank" id="charts">
<p:chart id="pie" type="pie" rendered="#{buttonView.showPieChart}" model="#{userBean.model}" responsive="true" />
<p:chart id="bar" type="bar" rendered="#{buttonView.showBarChart}" model="#{chartView.barModel}" style="height:300px" responsive="true" />
</p:panelGrid>
该值应该在您的 Backing Bean 中设置,例如 buttonView
。
public class ButtonView {
...
private boolean isShowPieChart;
private boolean isShowBarChart;
...
}
最后切换布尔值。
<p:commandButton update="@form" actionListener="#{buttonView.pieChart}" icon="ui-icon-disk" title="Zeige Pie an" >
<f:setActionPropertyListener target="#{buttonView.showPieChart}" value="#{!buttonView.showPieChart}" />
</p:commandButton>
<p:commandButton update="@form" actionListener="#{buttonView.barChart}" icon="ui-icon-disk" title="Zeige Bar an" >
<f:setActionPropertyListener target="#{buttonView.showBarChart}" value="#{!buttonView.showBarChart}" />
</p:commandButton>