Search code examples
jsfjsf-2primefaces

How to hide/show a panel conditionally in primefaces/jsf2 on commandButton click?


I want to hide/show <p:panel> on commandButton click with some condition ,I tried following

<h:form>
// some tag here
<p:commandButton value="EDIT" ajax="false"
                        onclick="if(#{bean.status == 'ACTIVE'}){editable.show();}"
                        actionListener="#{beanMgnt.edit}">
</h:form>

and editable is a panel as

<p:panel widgetVar="editable" closable="true"
                toggleable="true" visible="false">
                // some tags here
            </p:panel

edit method is doing only sysout.

What I want when enduser clicks the button this panel will be visible with bean data populated with Editable text boxes.

I want to make visible this panel visible with button click.How to do that?


Solution

  • I think you could use a boolean attribute in your backing bean. In the panel you put : visible="backingbean.yourAttribute" and you use a method in your bean to control it via onclick.

    onclick="backingbean.theMethod"
    

    In the method, if your condition is verified, you can set the attribute to "true".