Primefaces Confirm Message Updated Value

14,115

Solution 1

Take a look at the user guide of primefaces in the confirm dialog section, in the Non-Global mode the document mentioned:

Message facet is useful if you need to place custom content instead of simple text.

While in the Global mode, I can't find similar sentences like that, and I've tried using the facet in Global mode and it doesn't work.So,

Do you really use this confirm dialog multiple times?

If not:

I suggest you take away the global parameter and change your code like this:

<h:form>
        <p:inputText value="#{bean.object.amount}"/>
        <p:commandButton value="CALCULATE" update="cal" actionListener="#{bean.calculate()}"/>

        <h:panelGroup id="cal">
            <h:outputText value="#{bean.object.amount}"/>
            <p:commandButton value="SUBMIT" actionListener="#{bean.submit()}" oncomplete="PF('confirmDlg').show()"/>

            <p:confirmDialog header="Confirmation" widgetVar="confirmDlg">
                <f:facet name="message">
                    <h:outputText value='Amount is : #{bean.object.amount} ?'/>
                </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>
        </h:panelGroup>

</h:form>

.


If so:

(You do use the confirm dialog multiple times and tired of writing several dialogs with same form but different message.)

I suggest you write a dialog on your own,and you can also change the message in the dialog from backing bean like what you did:

<h:form id="myForm">
        <p:inputText value="#{bean.object.amount}"/>
        <p:commandButton value="CALCULATE" update="cal" actionListener="#{bean.calculate()}"/>

        <h:panelGroup id="cal">
            <h:outputText value="#{bean.object.amount}"/>
            <ui:param name="message" value="Amount is :#{bean.object.amount}?" />
            <p:commandButton value="SUBMIT" actionListener="#{bean.setMessage(message)}" action="#{bean.submit()}" update="myForm:myDialog" oncomplete="PF('myDlg').show()"/>
        </h:panelGroup>

        <p:dialog id='myDialog' widgetVar="myDlg" header="Confirmation" modal="true" resizable="false">
            <h:panelGrid columns="3">
                <h:panelGroup styleClass="ui-icon ui-icon-alert" style="float:right"/>
                <h:outputText value="#{bean.message}"/>
                <h:outputText/>

                <h:outputText/>
                <p:commandButton value="Yes" type="button" icon="ui-icon-check" oncomplete="PF('myDlg').hide()"/>
                <p:commandButton value="No" type="button" icon="ui-icon-close" onclick="PF('myDlg').hide()"/>
            </h:panelGrid>
        </p:dialog>
</h:form>

Solution 2

p:confirm does not implement state saving, thus it loses its attributes' values after the first JSF lifecycle. It also evaluates EL only once at view build time.

I posted the solution in this answer.

Share:
14,115

Related videos on Youtube

fareed
Author by

fareed

coder, builder, maker, for the past 10 years

Updated on June 04, 2022

Comments

  • fareed
    fareed almost 2 years

    I'm trying to show an updated value in confirm dialog message but I keep getting the old value as in this scenario

    <h:form>
        <p:inputText value="#{bean.object.amount}"/>
        <p:commandButton value="CALCULATE" update="cal" actionListener="#{bean.calculate()}"/>
    
        <h:panelGroup id="cal">
            <h:outputText value="#{bean.object.amount}"/>
            <p:commandButton value="SUBMIT" actionListener="#{bean.submit()}">
                 <p:confirm header="Confirmation" message="Amount is : #{bean.object.amount} ?"/>
            </p:commandButton>
    
            <p:confirmDialog global="true">
                 <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>
        </h:panelgGroup/>
    
    </h:form>
    

    Bean code:

    @ManagedBean(name="bean")
    @ViewScoped
    public class Bean implements Serializable {
           private SomeClass object;
    
           @PostConstruct
           public void init(){
                this.object = new SomeClass();
           }
    
            public void calculate(){
                //do some colculation (not related to amount field in object)
            }
    
            public void submit(){
                 //submit to database
            }
    
            //getter setter
    
    }
    

    When I enter a value in amount, lets say 50. and update the cal component I get the updated amount in the outputtext "50". However, in the confirm button message I get amount as 0 instead 50. How can I show the updated value in the confirm message?

    PS: Primefaces-4.0

    • Makky
      Makky almost 10 years
      I don't see any messsage in your confirmDialog ??
    • nosnhoj
      nosnhoj almost 10 years
      Can you show your backing bean?
    • fareed
      fareed almost 10 years
      @Makky its in the confirm component inside the button
    • fareed
      fareed almost 10 years
      @nosnhoj I have updated my question, but I think its a client side issue. I'm getting the updated value in the output text, but I don't get it in the confirm message.