How to conditionally show p: dialog based on bean condition

Is there any way (or the right way) to conditionally display a dialog on grids based on a bean condition. The code is as follows:

<!-- dialog declaration --> <p:dialog id="dialogTest" widgetVar="dialogTest" header="#{text['modal.header']}" modal="true" > <h:outputText value="Test output" /> </p:dialog> <!-- caller --> <p:menuitem value="Check" actionListener="#{backingBean.performCheck}" oncomplete="PF('dialogTest').show()" icon="ui-icon-arrowthick-1-e"/> 

My bean support is as follows:

 private boolean conditionFlag; // ... +getter public void performCheck() { // ... access managers (database) this.conditionFlag = dao.check();// some check; } 

I just want to show a dialog if conditionFlag is true . How can I do something like this on p:menuitem after performCheck works?

 oncomplete="if (#{backingBean.conditionFlag}) { PF('dialogTest').show() }" 
  • Jsf 2.0
  • Charts 5
  • Java 1.7
+5
source share
3 answers

just add update="@this" to p:menuitem . then your oncomplete unit will work as you expect.

+3
source

I got this to work as follows

 <!-- dialog declaration --> <h:form id="dialogForm"> <p:dialog id="dialogTest" widgetVar="dialogTest" header="#{text['modal.header']}" modal="true"> <h:outputText value="Test output" /> </p:dialog> </h:form> <!-- caller --> <p:menuitem value="Check" actionListener="#{backingBean.performCheck}" oncomplete="if (#{backingBean.conditionFlag}) { PF('dialogTest').show() }" icon="ui-icon-arrowthick-1-e" update="@this, :dialogForm, :dialogForm:dialogTest"/> 

Bean support remains unchanged (as in the question).

The main difference is the oncomplete attribute and the ajax update () attribute

+4
source

Just bind the boolean variable to the visible attribute of the dialog box.

 <p:dialog id="dialogTest" visible="#{backingBean.conditionFlag}" widgetVar="dialogTest" header="#{text['modal.header']}" modal="true" > <h:outputText value="Test output" /> </p:dialog> 

and then let the menu item execute as usual:

 <p:menuitem value="Check" actionListener="#{backingBean.performCheck}" oncomplete="PF('dialogTest').show()" icon="ui-icon-arrowthick-1-e" update="dialogTest"/> 

No extra work required. For best results, use @ViewScoped bean.

+2
source

Source: https://habr.com/ru/post/1200333/


All Articles