<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 &&!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 &&!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?