Board index JavaServer Faces General Change Severity to requiredMessage validation

Change Severity to requiredMessage validation

Components, Ajax Framework, Utilities and More.


Posts: 3
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:
<p:growl id="messages" sticky="true" autoUpdate="true" />


The code of the input field with the required attribute set on true
<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!
Running PrimeFaces-3.1 on Mojarra-2.1.4 (Oracle Weblogic 12c Server)

sudheer User avatar
PrimeFaces Core Developer

Posts: 3120
Location: India,chennai
You can use growl severity attribute or setting the severity from backing bean using faces message
PrimeFaces 5.0 | PFExt 2.0.0 | Mojarra 2.2
PFExtensions Book: http://www.packtpub.com/learning-primef ... pment/book
PFBlueprints: https://www.packtpub.com/primefaces-blueprints/book/
___________________
Sudheer Jonna


Posts: 3
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:
<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.
Running PrimeFaces-3.1 on Mojarra-2.1.4 (Oracle Weblogic 12c Server)

sudheer User avatar
PrimeFaces Core Developer

Posts: 3120
Location: India,chennai
Then apply field validations on server side using faces message.Remove the required and requiredMessage from client side and do it on serverside.
PrimeFaces 5.0 | PFExt 2.0.0 | Mojarra 2.2
PFExtensions Book: http://www.packtpub.com/learning-primef ... pment/book
PFBlueprints: https://www.packtpub.com/primefaces-blueprints/book/
___________________
Sudheer Jonna


Posts: 3
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.
Running PrimeFaces-3.1 on Mojarra-2.1.4 (Oracle Weblogic 12c Server)

sudheer User avatar
PrimeFaces Core Developer

Posts: 3120
Location: India,chennai
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. :)
PrimeFaces 5.0 | PFExt 2.0.0 | Mojarra 2.2
PFExtensions Book: http://www.packtpub.com/learning-primef ... pment/book
PFBlueprints: https://www.packtpub.com/primefaces-blueprints/book/
___________________
Sudheer Jonna


Return to General