简体   繁体   中英

PrimeFaces CommandButton does not Update

I'm trieng to update a gridPanel by pressing a Button(the Pie/Bar chart should not be shown):

<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>

My code somehow does not seem to work.

To hide and show the chart you have to define the rendered attribute rendered . The rendered attribute takes a boolean value.

<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>

The value should be set in your Backing Bean for example in buttonView .

public class ButtonView {
...
   private boolean isShowPieChart;
   private boolean isShowBarChart;
...
}

Finally toggle the boolean values.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM