I am having a strange issue with the Faces messages.
Sometimes, the <p:growl>, <p:messages>
display correctly the notification after executing some method. But there are specific JSF pages where no notification is shown.
For example:
public String create() {
try {
getFacade().create(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("NotaCreated"));
return prepareCreate();
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
The method is called in
<h:commandLink action="#{notaController.create}" value="#{bundle.CreateNotaSaveLink}"/>
And it does not show the notification. But for other entities as well as for other operations the messages are displayed correctly. This happens also in other functions, where I need feedback and it is not shown as expected.
I've been searching around and read this post and tried some of the suggested solutions, including setting the ajax=false
attribute in commandButtons and commandLinks or using the scripts posted, but none of that worked for me, so I ask this question hoping that someone can help me.
Do I have to configure something to make it work correctly? I need this to get fixed by tomorrow and I don't know what else to do.
Update:
These are the JsfUtil methods:
public static void addSuccessMessage(String msg) {
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
FacesContext.getCurrentInstance().addMessage("successInfo", facesMsg);
}
public static void addErrorMessage(Exception ex, String defaultMsg) {
String msg = ex.getLocalizedMessage();
if (msg != null && msg.length() > 0) {
addErrorMessage(msg);
} else {
addErrorMessage(defaultMsg);
}
}
This is the Create.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/template.xhtml">
<ui:define name="title">
<h:outputText value="#{bundle.CreateNotaTitle}"></h:outputText>
</ui:define>
<ui:define name="body">
<h:panelGroup id="messagePanel" layout="block">
<h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
</h:panelGroup>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="#{bundle.CreateNotaLabel_fecha}" for="fecha" />
<p:calendar value="#{notaController.selected.fecha}" id="fecha"/>
<h:outputLabel value="#{bundle.CreateNotaLabel_observaciones}" for="observaciones" />
<p:inputTextarea rows="4" cols="30" id="observaciones" value="#{notaController.selected.observaciones}" title="#{bundle.CreateNotaTitle_observaciones}" />
<h:outputLabel value="#{bundle.CreateNotaLabel_tipoNota}" for="tipoNota" />
<p:selectOneMenu id="tipoNota" value="#{notaController.selected.tipoNota}" required="true" requiredMessage="#{bundle.CreateNotaRequiredMessage_tipoNota}">
<f:selectItem itemLabel="---"/>
<f:selectItem itemValue="debito" itemLabel="Débito"/>
<f:selectItem itemValue="credito" itemLabel="Crédito"/>
</p:selectOneMenu>
<h:outputLabel value="#{bundle.CreateNotaLabel_monto}" for="monto" />
<p:inputText id="monto" value="#{notaController.selected.monto}" title="#{bundle.CreateNotaTitle_monto}" required="true" requiredMessage="#{bundle.CreateNotaRequiredMessage_monto}"/>
<h:outputLabel value="#{bundle.CreateNotaLabel_factura}" for="factura" />
<p:selectOneMenu id="factura" converter="#{facturaController.convertidor}" value="#{notaController.selected.factura}" filter="true" filterMatchMode="startsWith" required="true" requiredMessage="#{bundle.CreateNotaRequiredMessage_factura}">
<f:selectItem itemLabel="---"/>
<f:selectItems value="#{facturaController.facturas}" var="factura" itemValue="#{factura}" itemLabel="#{factura.idFactura}" />
</p:selectOneMenu>
</h:panelGrid>
<br />
<h:commandLink action="#{notaController.create}" value="#{bundle.CreateNotaSaveLink}">
<f:setPropertyActionListener value="#{cargaController.crearCargaDefault(sesionMB.usuario)}"
target="#{notaController.selected.carga}"/>
</h:commandLink>
<br />
<br />
<h:commandLink action="#{notaController.prepareList}" value="#{bundle.CreateNotaShowAllLink}" immediate="true"/>
<br />
<br />
<h:link outcome="/inicio" value="#{bundle.CreateNotaIndexLink}"/>
</h:form>
</ui:define>
</ui:composition>