1
<p:messages id="lockMessage"
            for="lockMessage"
            redisplay="false"
            showDetail="true"
            autoUpdate="true"
            closable="true"/>

<h:form id="form">
    <p:remoteCommand name="updateTable" update="dataTable" process="@this"/>

    <p:commandButton oncomplete="if(args &amp;&amp;!args.validationFailed) {updateTable();}"
                     actionListener="#{bean.action}"
                     value="Save"/>

    <p:dataTable id="dataTable"/>
</h:form>

The bean :

@Named
@ViewScoped
public class Bean implements Serializable {

    private static final long serialVersionUID = 1L;

    public Bean() {}

    public void action() {
        FacesContext facesContext = FacesContext.getCurrentInstance();

        // This is needed somewhere.

        Collection<String> renderIds = facesContext.getPartialViewContext().getRenderIds();
        renderIds.clear();
        renderIds.add("lockMessage");

        // Render the message using some conditional check.

        FacesMessage message = new FacesMessage();
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        message.setSummary("Summary");
        message.setDetail("Message");
        facesContext.addMessage("lockMessage", message);
    }
}

The message appears for a very short while and soon vanishes into thin air, when the given <p:commandButton> is clicked.

The message is displayed as usual, if oncomplete="if(args &amp;&amp;!args.validationFailed) {updateTable();}" is removed from the <p:commandButton>.

Omitting the <p:remoteCommand> or setting the autoUpdate attribute associated with the <p:messages> to false is not possible for other certain reasons.

What is to be done for the message to display normally, when the given <p:commandButton> is pressed?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Tiny
  • 27,221
  • 105
  • 339
  • 599
  • 3
    The messages *are* displayed normally, but since you immediately do another ajax call, the messages are updated again and since they are not kind of 'sticky', they disappear. Have your tried adding `ignoreAutoUpdate="true"` to the ``? – Kukeltje Aug 04 '15 at 11:40
  • Effectively, [this](http://stackoverflow.com/questions/17298913/how-to-prevent-primefaces-poll-from-clearing-facesmessages) is a duplicate – Kukeltje Aug 04 '15 at 11:43
  • O/T: Does a remote command without actually calling something on the server 'work'/'do something'? Or did you remove it for brevity? – Kukeltje Aug 04 '15 at 11:50
  • @Kukeltje: that's indeed the answer :) – BalusC Aug 04 '15 at 12:15
  • Kindly mark it as duplicate and/or add an answer. – Tiny Aug 04 '15 at 12:22
  • I'll generalize the other Q/A a little and mark it as a duplicate. Reputation points are not important ;-) – Kukeltje Aug 04 '15 at 12:24

0 Answers0