我通过按下按钮来更新gridPanel(不应显示饼图/条形图):
<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>
我的代码似乎无法正常工作。
答案 0 :(得分:1)
要隐藏和显示图表,您必须定义渲染的属性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>