-2

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.

Cœur
  • 32,421
  • 21
  • 173
  • 232
Seroga
  • 1
  • 3
  • You didn't have defined any rendered tag? Is your chart visible? – Paul Wasilewski Oct 19 '15 at 06:53
  • Sorry, I did define the rendered tag. In my example i simply used the wrong code. But i did not properly updated the value as you described in your answer. Thanks a lot – Seroga Oct 19 '15 at 07:28

1 Answers1

1

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>
Paul Wasilewski
  • 7,810
  • 4
  • 38
  • 49