jsf - Update bean message value before displaying it in a <p:confirmDialog> -


can tell me how change message of <p: confirm>? when click button want message of value returned messagecount () method.

...  <p:outputlabel value="test:" />                         <p:inputtext value="#{testcontroller.fieldtest}" id="fieldtest"/>  ...  <p:commandbutton value="ok" action="#{testcontroller.cadtest()}">     <p:confirm id="messageconfirm" header="test" /> </p:commandbutton>  ...  <p:confirmdialog global="true" showeffect="fade" hideeffect="fade">     <f:facet name="message">         <p:outputpanel>             <h:outputformat id="message" value="#{testcontroller.mensagemconfirm}" escape="false"/>         </p:outputpanel>     </f:facet>     <p:commandbutton value="yes" type="button" styleclass="ui-confirmdialog-yes" icon="ui-icon-check" />     <p:commandbutton value="no" type="button" styleclass="ui-confirmdialog-no" icon="ui-icon-close" /> </p:confirmdialog>  ...   //testcontroller  private string mensagemconfirm; private integer count = 0;   public integer messagecount() {     return count++; }  public string getmensagemconfirm() {     setmessageconfirm("count: " + messagecount());     return mensagemconfirm; }  public void setmensagemconfirm(string mensagemconfirm) {     this.mensagemconfirm = mensagemconfirm; } 

example:

  • first click "ok" (<p:commandbutton>)

    -> message of confirmdialog: count: 1 (click in "no")

  • secound click "ok" (<p:commandbutton>)

    -> message of confirmdialog: count: 2 (click in "no")

  • third click "ok" (<p:commandbutton>)

    -> message of confirmdialog: count: 3 (click in "no")

the problem here p:confirm not execute server side code until press "yes" in confirmdialog. have in order execute server side code first, , show confirm dialog after ajax request has been completed.

you can showing confirm dialog oncomplete attribute:

    <p:commandbutton value="ok" update="conf" action="#{testcontroller.increasecount()}" oncomplete="pf('confirmvar').show()"/>      <p:confirmdialog id="conf" global="true" showeffect="fade" hideeffect="fade" widgetvar="confirmvar">          <p:commandbutton value="yes" action="#{testcontroller.cadtest()}" styleclass="ui-confirmdialog-yes" icon="ui-icon-check" oncomplete="pf('confirmvar').hide()"/>         <p:commandbutton value="no" styleclass="ui-confirmdialog-no" icon="ui-icon-close" oncomplete="pf('confirmvar').hide()"/>          <f:facet name="message">             <p:outputpanel>                 <h:outputformat value="count: #{testcontroller.count}" escape="false"/>             </p:outputpanel>         </f:facet>     </p:confirmdialog> 

also bad design execute application logic code in pure getters/setters. use dedicated methods that.

testcontroller bean:

private int count;  public int getcount() {     return count; }  public void setcount(int count) {     this.count = count; }  public void increasecount() {    count++; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -