I am preparing a registration page using JSF/Spring webflow&mvc application. I have added two side validation one in client side every input fields has its own rich:message and other one at server side, registration bean response as facescontext.addMessage(). My problem when I try to test validation, rich:message components show errors correct but rich:messages show same errors as well. I want to use messages just for specific errors, something like mail already exist in database.
my rich:messages tag:
<rich:messages id="msg" layout="table" limitRender="true"
style="font-weight:bold;color:#BDBDBD">
<f:facet name="errorMarker">
<h:graphicImage url="/images/messages_error.png" />
</f:facet>
</rich:messages>
<h:form ...>
.....SOME LOGIC.....
<h:inputText id="i_ln" required="true" value="#{regBean.lastName}">
<f:validateLength minimum="2" maximum="35" />
<rich:ajaxValidator event="onblur" />
</h:inputText>
<rich:message for="i_ln">
<f:facet name="errorMarker">
<h:graphicImage url="/images/messages_error.png" />
</f:facet>
</rich:message>
.....
</h:form>
I have checked similar issues that people advice to use globalOnly=”true” and when I use this attribute then duplicate validation stops but I am not able to add severity error. My oytput as below:
Feb 07, 2012 10:08:04 PM com.sun.faces.lifecycle.RenderResponsePhase execute
INFO: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=i_comment[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
sourceId=i_title[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
sourceId=i_salut[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
sourceId=i_mobile[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
sourceId=i_fax[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
Another question is should I keep server side validation?
Ok here is a workaround:
First of all its a known issue refer to jboss community:
So I have played around with code and notice that rich:messages just picking messages when:
assigned and message has client&sourceID=”xxx”
no globalOnly=”true” attribute assigned then any message also messages with
the null client id.
I was able to apply two solution for this:
First solution for pages with just one rich:messages;
My rich:messages tag just have globalOnly=”true” and there is no for attribute;
And my bean send message with id=null;
Second solution for pages with more than one rich:messages;
I have added one hidden rich:message to use as a bridge, then my message can have hidden component id and will not be null, after I just pick it up by my rich:messages using this id.
And I have added message as below via FacesContext: