dynamic "message" of p:confirm - Primefaces

Asked

Viewed 499 times

1

Can anyone tell me how to change the message of <p:confirm>? When you click the button I want the value of message is returned by the method messageCount().

...

<p:outputLabel value="Teste:" />                        
<p:inputText value="#{testeController.campoTeste}" id="campoTeste"/>

...

<p:commandButton value="Ok" action="#{testeController.cadastrarTest()}">
    <p:confirm header="Confirmação" message="Confirmar?"/>
</p:commandButton>

 ...

<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
    <p:commandButton value="Sim" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
    <p:commandButton value="Não" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>



...


public Integer messageCount() {
    return count++;
}

1 answer

2


Declare a variable in your bean, String message = "Confirmar?"

Put an id on p:confirm, id="message" and also value="{{testeController.message}}"

That part of the code {{testeController.message}} calls the method in its Testecontroller class, getMessage().

Change/implement the method getMessage() to make the modifications you need

  • Right... But I think this is the problem. I need to use a message that will vary depending on the click on the button. In this example you gave me will always be the value set at the beginning. How can I change the value of String message every click?

  • I’ll edit the answer

  • But the action will be executed only after I accept p:confirmDialog. Isn’t it? If so, I need to change the message before I give the Submit in the form. Thank you

  • When do you want to change the message??? From what I understand.. every time you click the button would change the message.... as you want then ?

  • Let’s see if I can explain myself better now... In the example I posted has the button OK, when I click on it is shown p:confirm message with the options Yes and Not. When I click on Yes executes action="#{testeController.cadastrarTest()}". Well that’s the normal way it works. What I need, considering what I described, is that by clicking the button OK before executing the cadastrarTest() I can go to the controller and get the updated text to use on the Confirmation. Thank you

  • I’ll edit the answer then

  • Perfect... now ok... I will "work" on getMessage(). Thank you very much...

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.