Page 1 of 1

Change Severity to requiredMessage validation

Posted: 04 Dec 2012, 18:07
by Cmegrow
By default primefaces shows an error message (SEVERITY_ERROR) when required field validation fails, and if properly configured a customized requiredMessage is shown. To show these kind of messages I use a Growl component and I want to know if i can change the severity of the these kind of validation messages to be a Warning (SEVERITY_WARN) instead of an Error (SEVERITY_ERROR).

Here is the Growl code:

Code: Select all

<p:growl id="messages" sticky="true" autoUpdate="true" />
The code of the input field with the required attribute set on true

Code: Select all

<p:inputText value="#{modDespSesion.nitFac}" id="nitIT" 
                    required="true" requiredMessage="Por favor ingrese el numero de NIT"
                    rendered="#{modDespSesion.cambiaDatosFactura eq 'S' or modDespSesion.cambiaDatosFactura eq 'X'}"
                    converterMessage="El campo NIT solo acepta nĂºmeros"
                    onkeypress="return keyPressNro(this, event);">
                    <f:convertNumber integerOnly="true" type="number" />
</p:inputText>
Thanks in advance!

Re: Change Severity to requiredMessage validation

Posted: 04 Dec 2012, 19:39
by sudheer
You can use growl severity attribute or setting the severity from backing bean using faces message

Re: Change Severity to requiredMessage validation

Posted: 04 Dec 2012, 21:14
by Cmegrow
sudheer wrote:You can use growl severity attribute or setting the severity from backing bean using faces message
Hello! thanks for your reply.

Checking growl's attributes in the primefaces user guide i can't find any attribute that can change the severity setting, the only attributes similar is to change the icon of the severity (e.g. warnIcon, errorIcon), however those attributes only change the icon and not the severity.

Setting the severity from backing beans using the faces message does the job for errors controlled by my code, but not for errors generated when field validation fails, for example when i set the required attribute of an p:inputText in true. For example:

Code: Select all

<p:inputText value="#{modDespSesion.nitFac}" id="nitIT" 
         required="true" requiredMessage="Por favor ingrese el numero de NIT">
</p:inputText>
In the example above if the user does not input anything in the inputText then a validation error is shown, showing the contents of the requiredMessage attribute but with the SEVERITY_ERROR severity configured by default in the Growl component.

Re: Change Severity to requiredMessage validation

Posted: 04 Dec 2012, 21:21
by sudheer
Then apply field validations on server side using faces message.Remove the required and requiredMessage from client side and do it on serverside.

Re: Change Severity to requiredMessage validation

Posted: 04 Dec 2012, 21:41
by Cmegrow
sudheer wrote:Then apply field validations on server side using faces message.Remove the required and requiredMessage from client side and do it on serverside.
I thought in the same solution but when i saw that i have to change a lot of inputText on several pages, i was thinking....maybe there is a better solution :)

Thanks for the tip though, i think there is a way to do it and hope someone has the answer.

Re: Change Severity to requiredMessage validation

Posted: 04 Dec 2012, 21:56
by sudheer
I can understand more number of components need to be modified in your app.But I don't think there will be any better way even considering growl CSS styleclasses. We can provide any number of custom validations with facesmessages not just the empty field validation.However, let us wait for other approaches also. :)