I got a page with a single_selection datatable and a commandbutton. The commandbutton invokes a bean method that verifies if a selection was made. If not it should display a message warning the user. If a selection was made it navigates to another page.
The problem is that no message is displayed when there's no selection. If a selection was made it works fine.
Here's the code for the page:
<h:body>
<h:form id="form">
<p:dataTable id="TablaSociedades" var="soc" value="#{Sesion.tablaSociedades}" emptyMessage="No hay Registros que Mostrar" selection="#{Sesion.sociedadUsuario}">
<f:facet name="header">Sociedades asociadas al Usuario</f:facet>
<p:column selectionMode="single" style="width:18px" />
<p:column>
<f:facet name="header">
<h:outputText value="Sociedad" />
</f:facet>
<h:outputText value="#{soc.nombreSociedad}" />
</p:column>
<f:facet name="footer">
<p:commandButton action="#{Sesion.mostrarMenu()}" value="Continuar" process=":form" />
</f:facet>
</p:dataTable>
<br/>
<div>
<p:messages id="messages2" showDetail="true" autoUpdate="false" closable="true" />
</div>
</h:form>
</h:body>
And the code for the bean method:
public boolean mostrarMenu()
{
boolean resp = true;
if (sociedadUsuario.getNombreSociedad().equals("")) //no selection
{
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage (FacesMessage.SEVERITY_WARN,"Seleccione una Sociedad", "No puede Continuar"));
resp = false;
}
return resp;
}
I must mention that the commandbutton must be clicked twice but i'll post another question for that problem.
I did another page with bean validation where the messages are displayed correctly, the only difference with this page is that the other page contains only inputText, commandbutton and messages.
Thanks for your time
02/25/13 Code for the faces-config.xml file.
<navigation-rule>
<from-view-id>/elegirSociedad.xhtml</from-view-id>
<navigation-case>
<from-action>#{Sesion.mostrarMenu()}</from-action>
<from-outcome>true</from-outcome>
<to-view-id>/principal.xhtml</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
I used redirect to avoid the "click twice" problem that i comment before but to no avail