I am using JSF 2.3 (Mojarra 2.3.9.SP02) and PrimeFaces 7.0 running on WildFly 17 (Ubuntu 18.04 TLS / or Windows 10).
In my action method weiterBid()
in the backing bean (which is a ViewScoped) I perform a check if the user has just checked a checkbox. If not, then an error message is shown in red in the component <p:panel id="errorMsgPanelId"
(see below the facelet) and the user remains on the same page. This check is performed each time the user clicks on the "Next" button.
Now, my understanding is, that even when the user closes the error message panel, each time when he/she clicks on the "Next" button, the action method is invoked, and the check whether hte user has checked the checkbox is performed again and again. If the check-box has not been checked, then the error message should be shown again in the same <p:panel id="errorMsgPanelId">
component as before.
Is this really the supposed behaviour? If yes, than I am having a bug that the error message is only shown on the first click on the "Next" button and is never showhn again, once the user closes the panel showing it.
The minimal working example project on github:
https://github.com/alexmivonwien/pf.error.msg
My backing bean:
@Named("aveBidUnterlagenBean")
@javax.faces.view.ViewScoped
public class AveBidUnterlagenBean implements Serializable {
private boolean confirmationDocumentsGiven;
private FacesMessage errorMessageOnDocumentConfirmation;
public boolean isConfirmationDocumentsGiven() {
return confirmationDocumentsGiven;
}
public void setConfirmationDocumentsGiven(boolean confirmationDocumentsGiven) {
this.confirmationDocumentsGiven = confirmationDocumentsGiven;
}
public String weiterBid() {
if (!confirmationDocumentsGiven) {
String errorMessage = "Please confirm documents for the real estate";
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, null);
FacesContext.getCurrentInstance().addMessage(null, message);
this.errorMessageOnDocumentConfirmation = message;
return null;
}
return null;
}
public FacesMessage getErrorMessageOnDocumentConfirmation() {
return errorMessageOnDocumentConfirmation;
}
public void onCloseErrorMsgPanel(CloseEvent event) {
this.errorMessageOnDocumentConfirmation = null;
}
}
In the facelet I have the component
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</h:head>
<h:outputStylesheet name="primeicons/primeicons.css" library="primefaces"/>
<h:form id="persDatenForm">
<p:panel id="errorMsgPanelId" styleClass="errorMsgPanel" closable="true" widgetVar="errorMsgPanel" rendered="#{aveBidUnterlagenBean.getErrorMessageOnDocumentConfirmation()!=null}">
<p:ajax event="close" listener="#{aveBidUnterlagenBean.onCloseErrorMsgPanel}" update="@parent" />
<h:outputText style="color:red;" value="#{aveBidUnterlagenBean.errorMessageOnDocumentConfirmation.detail}"/>
<p:commandLink outcome="#" style="background-color:white;" onclick="PF('errorMsgPanel').close()">
<i class="pi pi-times"></i>
</p:commandLink>
</p:panel>
<br/>
<p:outputLabel value="Documents overwiev"/>
<br/>
<br/>
<p:selectBooleanCheckbox value="#{aveBidUnterlagenBean.confirmationDocumentsGiven}" itemLabel="I confirm that I read the documents"/>
<br/>
<br/>
<p:commandButton icon = "pi pi-check" value="Next" action="#{aveBidUnterlagenBean.weiterBid}" update="@form"/>
</h:form>
</html>
Now , my problem is that if I do not check the check-box and I click on the "Next" button for the first time, the action method is invoked and the error message is shown. If I close the error message panel, and then click on the same "Next" button again, without having checked the checkbox, the error message is never shown again.
Is it a bug or a feature? How could I overcome it?
Thank you and kind regards: Alex