Change Severity to requiredMessage validation

UI Components for JSF
Post Reply
Cmegrow
Posts: 3
Joined: 04 Dec 2012, 17:26

04 Dec 2012, 18:07

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

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

04 Dec 2012, 19:39

You can use growl severity attribute or setting the severity from backing bean using faces message
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

Cmegrow
Posts: 3
Joined: 04 Dec 2012, 17:26

04 Dec 2012, 21:14

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

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

04 Dec 2012, 21:21

Then apply field validations on server side using faces message.Remove the required and requiredMessage from client side and do it on serverside.
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

Cmegrow
Posts: 3
Joined: 04 Dec 2012, 17:26

04 Dec 2012, 21:41

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)

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

04 Dec 2012, 21:56

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. :)
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 25 guests