You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Matt Raible <li...@raibledesigns.com> on 2004/12/03 19:56:02 UTC

Is it possible to change the required validation message to something friendlier?

I would like to change the validation messages to be a bit more 
friendly, like they are with Commons Validation and Struts/Spring. 
Basically, instead of:

"firstName": Value is required.

I'd like it to say "First Name is a required field."

I have the following in my resource bundle, but it doesn't give me 
access to the field's label (i18n-ized).

javax.faces.component.UIInput.REQUIRED={0} is a required field.

Instead it prints:

firstName is a required field.

Any idea how to look up a input field's label and use the text from that 
in the {0}?

Thanks,

Matt


Re: Is it possible to change the required validation message to something friendlier?

Posted by Heath Borders <he...@gmail.com>.
Oh that is awesome.


On Sat, 4 Dec 2004 09:28:24 +0100, Martin Marinschek
<ma...@gmail.com> wrote:
> there is functionality in MyFaces already to show the label of the
> components, just use the x:message tags and make sure to include
> component and message tag in a panel group...
> 
> regards,
> 
> Martin
> 
> On Fri, 3 Dec 2004 16:31:06 -0600, Heath Borders
> 
> 
> <he...@gmail.com> wrote:
> > You can't change this in the UIInput directly because it is not to spec.
> >
> > The only way to do it and keep the code to spec is to extend all of
> > the components individually.  This is why the spec needs to be
> > changed.  Let's just hope that they get it done in 1.2
> >
> >
> >
> >
> > On Fri, 03 Dec 2004 15:22:40 -0700, Matt Raible <li...@raibledesigns.com> wrote:
> > > Craig McClanahan wrote:
> > >
> > >
> > >
> > > >On Fri, 3 Dec 2004 13:21:16 -0600, Heath Borders
> > > ><he...@gmail.com> wrote:
> > > >
> > > >
> > > >>Unfortunately, the spec isn't very good on this matter.
> > > >>
> > > >>Basically, you'll have to override the spec and provide custom
> > > >>functionality to be able to achieve this.
> > > >>
> > > >>Isn't this something we could do in the MyFaces custom components?
> > > >>
> > > >>The reason you can't do this within the spec is that the Validation
> > > >>exception that is created for empty UIInputs that are required is
> > > >>created inside UIInput.  Unfortunately, there is no way to change the
> > > >>String that the template message uses in its "{0}" place without
> > > >>overriding UIInput's validate() method.  This, of course, means that
> > > >>you would have to create extensions to all UIInputs
> > > >>(HtmlSelectOneRadio, HtmlSelectOneListbox, HtmlInputText, etc).
> > > >>
> > > >>Perhaps someone with a little clout (i.e. Craig, Manfred), could
> > > >>suggest this to the spec guys, since I've tried to do so on the
> > > >>forums, but it has fallen on deaf ears.
> > > >>
> > > >>
> > > >>
> > > >
> > > >There actually is a way to change the message text (declare a
> > > ><message-bundle> element in faces-config.xml, and in the corresponding
> > > >ResourceBundle define messages for the keys that are described in
> > > >Section 2.5.2.4 of the spec.
> > > >
> > > >What you cannot currently change is what parameters are passed in to
> > > >replace the {0} text -- right now it's the component id.  Looking into
> > > >this was on the initial radar for the JSF 1.2 expert group, but don't
> > > >know if they've discussed it yet.
> > > >
> > > >The particular idea of looking up the corresponding label component is
> > > >an interesting one, but presumes that the page author is diligent
> > > >about using <h:outputLabel> elements for their field labels, instead
> > > >of <h:outputText>.  So there would have to be a fallback mechanism as
> > > >well.
> > > >
> > > >On the other hand, you can also "cheat" a little, and convince JSF to
> > > >use *your* component class instead of the standard one.  Let's say
> > > >that you did a MyHtmlOutputText component that extended HtmlOutputText
> > > >and had the modified validate() method.  To register it, just do this
> > > >in your faces-config.xml file:
> > > >
> > > >
> > > Looking at MyFaces source code, this looks easy enough to change.  In
> > > the UIInput class, just change the following to look up the label based
> > > on the id, then I'd just have to be smart about naming my input fields
> > > to match their i18n keys:
> > >
> > > In the validate method:
> > >
> > >        if (isRequired() && empty)
> > >        {
> > >            _MessageUtils.addErrorMessage(context, this,
> > > REQUIRED_MESSAGE_ID,new Object[]{getId()});
> > >            setValid(false);
> > >            return;
> > >        }
> > >
> > > Change this to:
> > >
> > >        if (isRequired() && empty)
> > >        {
> > >            _MessageUtils.addErrorMessage(context, this,
> > > REQUIRED_MESSAGE_ID, getMessageBasedOnId(getId())});
> > >            setValid(false);
> > >            return;
> > >        }
> > >
> > > My question is - how would I get the message bundle?
> > >
> > > A better way would be to look up the label for the input and get the
> > > rendered message from that.  But I don't know if that's possible.
> > >
> > > Matt
> > >
> > >
> > >
> > > >    <component>
> > > >        <component-type>javax.faces.HtmlOutputText</component-type>
> > > >        <component-class>com.mycompany.MyHtmlOutputText</component-class>
> > > >    </component>
> > > >
> > > >and the JSF runtime, including <h:outputText>, will use your component
> > > >class instead of the standard one.  As long as you're subclassing the
> > > >one you replace, you should not have any class cast exception
> > > >problems.
> > > >
> > > >Craig
> > > >
> > > >
> > > >Craig
> > > >
> > > >
> > > >
> > > >>
> > > >>On Fri, 03 Dec 2004 11:56:02 -0700, Matt Raible <li...@raibledesigns.com> wrote:
> > > >>
> > > >>
> > > >>>I would like to change the validation messages to be a bit more
> > > >>>friendly, like they are with Commons Validation and Struts/Spring.
> > > >>>Basically, instead of:
> > > >>>
> > > >>>"firstName": Value is required.
> > > >>>
> > > >>>I'd like it to say "First Name is a required field."
> > > >>>
> > > >>>I have the following in my resource bundle, but it doesn't give me
> > > >>>access to the field's label (i18n-ized).
> > > >>>
> > > >>>javax.faces.component.UIInput.REQUIRED={0} is a required field.
> > > >>>
> > > >>>Instead it prints:
> > > >>>
> > > >>>firstName is a required field.
> > > >>>
> > > >>>Any idea how to look up a input field's label and use the text from that
> > > >>>in the {0}?
> > > >>>
> > > >>>Thanks,
> > > >>>
> > > >>>Matt
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>--
> > > >>If you don't have a GMail account, I probably have 5 invites.  Just ask!
> > > >>-Heath Borders-Wing
> > > >>hborders@mail.win.org
> > > >>
> > > >>
> > > >>
> > >
> > >
> >
> >
> > --
> >
> >
> > If you don't have a GMail account, I probably have 5 invites.  Just ask!
> > -Heath Borders-Wing
> > hborders@mail.win.org
> >
> 


-- 
If you don't have a GMail account, I probably have 5 invites.  Just ask!
-Heath Borders-Wing
hborders@mail.win.org

Re: Is it possible to change the required validation message to something friendlier?

Posted by Martin Marinschek <ma...@gmail.com>.
there is functionality in MyFaces already to show the label of the
components, just use the x:message tags and make sure to include
component and message tag in a panel group...

regards,

Martin


On Fri, 3 Dec 2004 16:31:06 -0600, Heath Borders
<he...@gmail.com> wrote:
> You can't change this in the UIInput directly because it is not to spec.
> 
> The only way to do it and keep the code to spec is to extend all of
> the components individually.  This is why the spec needs to be
> changed.  Let's just hope that they get it done in 1.2
> 
> 
> 
> 
> On Fri, 03 Dec 2004 15:22:40 -0700, Matt Raible <li...@raibledesigns.com> wrote:
> > Craig McClanahan wrote:
> >
> >
> >
> > >On Fri, 3 Dec 2004 13:21:16 -0600, Heath Borders
> > ><he...@gmail.com> wrote:
> > >
> > >
> > >>Unfortunately, the spec isn't very good on this matter.
> > >>
> > >>Basically, you'll have to override the spec and provide custom
> > >>functionality to be able to achieve this.
> > >>
> > >>Isn't this something we could do in the MyFaces custom components?
> > >>
> > >>The reason you can't do this within the spec is that the Validation
> > >>exception that is created for empty UIInputs that are required is
> > >>created inside UIInput.  Unfortunately, there is no way to change the
> > >>String that the template message uses in its "{0}" place without
> > >>overriding UIInput's validate() method.  This, of course, means that
> > >>you would have to create extensions to all UIInputs
> > >>(HtmlSelectOneRadio, HtmlSelectOneListbox, HtmlInputText, etc).
> > >>
> > >>Perhaps someone with a little clout (i.e. Craig, Manfred), could
> > >>suggest this to the spec guys, since I've tried to do so on the
> > >>forums, but it has fallen on deaf ears.
> > >>
> > >>
> > >>
> > >
> > >There actually is a way to change the message text (declare a
> > ><message-bundle> element in faces-config.xml, and in the corresponding
> > >ResourceBundle define messages for the keys that are described in
> > >Section 2.5.2.4 of the spec.
> > >
> > >What you cannot currently change is what parameters are passed in to
> > >replace the {0} text -- right now it's the component id.  Looking into
> > >this was on the initial radar for the JSF 1.2 expert group, but don't
> > >know if they've discussed it yet.
> > >
> > >The particular idea of looking up the corresponding label component is
> > >an interesting one, but presumes that the page author is diligent
> > >about using <h:outputLabel> elements for their field labels, instead
> > >of <h:outputText>.  So there would have to be a fallback mechanism as
> > >well.
> > >
> > >On the other hand, you can also "cheat" a little, and convince JSF to
> > >use *your* component class instead of the standard one.  Let's say
> > >that you did a MyHtmlOutputText component that extended HtmlOutputText
> > >and had the modified validate() method.  To register it, just do this
> > >in your faces-config.xml file:
> > >
> > >
> > Looking at MyFaces source code, this looks easy enough to change.  In
> > the UIInput class, just change the following to look up the label based
> > on the id, then I'd just have to be smart about naming my input fields
> > to match their i18n keys:
> >
> > In the validate method:
> >
> >        if (isRequired() && empty)
> >        {
> >            _MessageUtils.addErrorMessage(context, this,
> > REQUIRED_MESSAGE_ID,new Object[]{getId()});
> >            setValid(false);
> >            return;
> >        }
> >
> > Change this to:
> >
> >        if (isRequired() && empty)
> >        {
> >            _MessageUtils.addErrorMessage(context, this,
> > REQUIRED_MESSAGE_ID, getMessageBasedOnId(getId())});
> >            setValid(false);
> >            return;
> >        }
> >
> > My question is - how would I get the message bundle?
> >
> > A better way would be to look up the label for the input and get the
> > rendered message from that.  But I don't know if that's possible.
> >
> > Matt
> >
> >
> >
> > >    <component>
> > >        <component-type>javax.faces.HtmlOutputText</component-type>
> > >        <component-class>com.mycompany.MyHtmlOutputText</component-class>
> > >    </component>
> > >
> > >and the JSF runtime, including <h:outputText>, will use your component
> > >class instead of the standard one.  As long as you're subclassing the
> > >one you replace, you should not have any class cast exception
> > >problems.
> > >
> > >Craig
> > >
> > >
> > >Craig
> > >
> > >
> > >
> > >>
> > >>On Fri, 03 Dec 2004 11:56:02 -0700, Matt Raible <li...@raibledesigns.com> wrote:
> > >>
> > >>
> > >>>I would like to change the validation messages to be a bit more
> > >>>friendly, like they are with Commons Validation and Struts/Spring.
> > >>>Basically, instead of:
> > >>>
> > >>>"firstName": Value is required.
> > >>>
> > >>>I'd like it to say "First Name is a required field."
> > >>>
> > >>>I have the following in my resource bundle, but it doesn't give me
> > >>>access to the field's label (i18n-ized).
> > >>>
> > >>>javax.faces.component.UIInput.REQUIRED={0} is a required field.
> > >>>
> > >>>Instead it prints:
> > >>>
> > >>>firstName is a required field.
> > >>>
> > >>>Any idea how to look up a input field's label and use the text from that
> > >>>in the {0}?
> > >>>
> > >>>Thanks,
> > >>>
> > >>>Matt
> > >>>
> > >>>
> > >>>
> > >>>
> > >>--
> > >>If you don't have a GMail account, I probably have 5 invites.  Just ask!
> > >>-Heath Borders-Wing
> > >>hborders@mail.win.org
> > >>
> > >>
> > >>
> >
> >
> 
> 
> --
> 
> 
> If you don't have a GMail account, I probably have 5 invites.  Just ask!
> -Heath Borders-Wing
> hborders@mail.win.org
>

Re: Is it possible to change the required validation message to something friendlier?

Posted by Heath Borders <he...@gmail.com>.
You can't change this in the UIInput directly because it is not to spec.

The only way to do it and keep the code to spec is to extend all of
the components individually.  This is why the spec needs to be
changed.  Let's just hope that they get it done in 1.2


On Fri, 03 Dec 2004 15:22:40 -0700, Matt Raible <li...@raibledesigns.com> wrote:
> Craig McClanahan wrote:
> 
> 
> 
> >On Fri, 3 Dec 2004 13:21:16 -0600, Heath Borders
> ><he...@gmail.com> wrote:
> >
> >
> >>Unfortunately, the spec isn't very good on this matter.
> >>
> >>Basically, you'll have to override the spec and provide custom
> >>functionality to be able to achieve this.
> >>
> >>Isn't this something we could do in the MyFaces custom components?
> >>
> >>The reason you can't do this within the spec is that the Validation
> >>exception that is created for empty UIInputs that are required is
> >>created inside UIInput.  Unfortunately, there is no way to change the
> >>String that the template message uses in its "{0}" place without
> >>overriding UIInput's validate() method.  This, of course, means that
> >>you would have to create extensions to all UIInputs
> >>(HtmlSelectOneRadio, HtmlSelectOneListbox, HtmlInputText, etc).
> >>
> >>Perhaps someone with a little clout (i.e. Craig, Manfred), could
> >>suggest this to the spec guys, since I've tried to do so on the
> >>forums, but it has fallen on deaf ears.
> >>
> >>
> >>
> >
> >There actually is a way to change the message text (declare a
> ><message-bundle> element in faces-config.xml, and in the corresponding
> >ResourceBundle define messages for the keys that are described in
> >Section 2.5.2.4 of the spec.
> >
> >What you cannot currently change is what parameters are passed in to
> >replace the {0} text -- right now it's the component id.  Looking into
> >this was on the initial radar for the JSF 1.2 expert group, but don't
> >know if they've discussed it yet.
> >
> >The particular idea of looking up the corresponding label component is
> >an interesting one, but presumes that the page author is diligent
> >about using <h:outputLabel> elements for their field labels, instead
> >of <h:outputText>.  So there would have to be a fallback mechanism as
> >well.
> >
> >On the other hand, you can also "cheat" a little, and convince JSF to
> >use *your* component class instead of the standard one.  Let's say
> >that you did a MyHtmlOutputText component that extended HtmlOutputText
> >and had the modified validate() method.  To register it, just do this
> >in your faces-config.xml file:
> >
> >
> Looking at MyFaces source code, this looks easy enough to change.  In
> the UIInput class, just change the following to look up the label based
> on the id, then I'd just have to be smart about naming my input fields
> to match their i18n keys:
> 
> In the validate method:
> 
>        if (isRequired() && empty)
>        {
>            _MessageUtils.addErrorMessage(context, this,
> REQUIRED_MESSAGE_ID,new Object[]{getId()});
>            setValid(false);
>            return;
>        }
> 
> Change this to:
> 
>        if (isRequired() && empty)
>        {
>            _MessageUtils.addErrorMessage(context, this,
> REQUIRED_MESSAGE_ID, getMessageBasedOnId(getId())});
>            setValid(false);
>            return;
>        }
> 
> My question is - how would I get the message bundle?
> 
> A better way would be to look up the label for the input and get the
> rendered message from that.  But I don't know if that's possible.
> 
> Matt
> 
> 
> 
> >    <component>
> >        <component-type>javax.faces.HtmlOutputText</component-type>
> >        <component-class>com.mycompany.MyHtmlOutputText</component-class>
> >    </component>
> >
> >and the JSF runtime, including <h:outputText>, will use your component
> >class instead of the standard one.  As long as you're subclassing the
> >one you replace, you should not have any class cast exception
> >problems.
> >
> >Craig
> >
> >
> >Craig
> >
> >
> >
> >>
> >>On Fri, 03 Dec 2004 11:56:02 -0700, Matt Raible <li...@raibledesigns.com> wrote:
> >>
> >>
> >>>I would like to change the validation messages to be a bit more
> >>>friendly, like they are with Commons Validation and Struts/Spring.
> >>>Basically, instead of:
> >>>
> >>>"firstName": Value is required.
> >>>
> >>>I'd like it to say "First Name is a required field."
> >>>
> >>>I have the following in my resource bundle, but it doesn't give me
> >>>access to the field's label (i18n-ized).
> >>>
> >>>javax.faces.component.UIInput.REQUIRED={0} is a required field.
> >>>
> >>>Instead it prints:
> >>>
> >>>firstName is a required field.
> >>>
> >>>Any idea how to look up a input field's label and use the text from that
> >>>in the {0}?
> >>>
> >>>Thanks,
> >>>
> >>>Matt
> >>>
> >>>
> >>>
> >>>
> >>--
> >>If you don't have a GMail account, I probably have 5 invites.  Just ask!
> >>-Heath Borders-Wing
> >>hborders@mail.win.org
> >>
> >>
> >>
> 
> 


-- 
If you don't have a GMail account, I probably have 5 invites.  Just ask!
-Heath Borders-Wing
hborders@mail.win.org

Re: Is it possible to change the required validation message to something friendlier?

Posted by Matt Raible <li...@raibledesigns.com>.
Craig McClanahan wrote:

>On Fri, 3 Dec 2004 13:21:16 -0600, Heath Borders
><he...@gmail.com> wrote:
>  
>
>>Unfortunately, the spec isn't very good on this matter.
>>
>>Basically, you'll have to override the spec and provide custom
>>functionality to be able to achieve this.
>>
>>Isn't this something we could do in the MyFaces custom components?
>>
>>The reason you can't do this within the spec is that the Validation
>>exception that is created for empty UIInputs that are required is
>>created inside UIInput.  Unfortunately, there is no way to change the
>>String that the template message uses in its "{0}" place without
>>overriding UIInput's validate() method.  This, of course, means that
>>you would have to create extensions to all UIInputs
>>(HtmlSelectOneRadio, HtmlSelectOneListbox, HtmlInputText, etc).
>>
>>Perhaps someone with a little clout (i.e. Craig, Manfred), could
>>suggest this to the spec guys, since I've tried to do so on the
>>forums, but it has fallen on deaf ears.
>>
>>    
>>
>
>There actually is a way to change the message text (declare a
><message-bundle> element in faces-config.xml, and in the corresponding
>ResourceBundle define messages for the keys that are described in
>Section 2.5.2.4 of the spec.
>
>What you cannot currently change is what parameters are passed in to
>replace the {0} text -- right now it's the component id.  Looking into
>this was on the initial radar for the JSF 1.2 expert group, but don't
>know if they've discussed it yet.
>
>The particular idea of looking up the corresponding label component is
>an interesting one, but presumes that the page author is diligent
>about using <h:outputLabel> elements for their field labels, instead
>of <h:outputText>.  So there would have to be a fallback mechanism as
>well.
>
>On the other hand, you can also "cheat" a little, and convince JSF to
>use *your* component class instead of the standard one.  Let's say
>that you did a MyHtmlOutputText component that extended HtmlOutputText
>and had the modified validate() method.  To register it, just do this
>in your faces-config.xml file:
>  
>
Looking at MyFaces source code, this looks easy enough to change.  In 
the UIInput class, just change the following to look up the label based 
on the id, then I'd just have to be smart about naming my input fields 
to match their i18n keys:

In the validate method:

        if (isRequired() && empty)
        {
            _MessageUtils.addErrorMessage(context, this, 
REQUIRED_MESSAGE_ID,new Object[]{getId()});
            setValid(false);
            return;
        }

Change this to:

        if (isRequired() && empty)
        {
            _MessageUtils.addErrorMessage(context, this, 
REQUIRED_MESSAGE_ID, getMessageBasedOnId(getId())});
            setValid(false);
            return;
        }

My question is - how would I get the message bundle?

A better way would be to look up the label for the input and get the 
rendered message from that.  But I don't know if that's possible.

Matt

>    <component>
>        <component-type>javax.faces.HtmlOutputText</component-type>
>        <component-class>com.mycompany.MyHtmlOutputText</component-class>
>    </component>
>
>and the JSF runtime, including <h:outputText>, will use your component
>class instead of the standard one.  As long as you're subclassing the
>one you replace, you should not have any class cast exception
>problems.
>
>Craig
>
>
>Craig
>
>  
>
>>
>>On Fri, 03 Dec 2004 11:56:02 -0700, Matt Raible <li...@raibledesigns.com> wrote:
>>    
>>
>>>I would like to change the validation messages to be a bit more
>>>friendly, like they are with Commons Validation and Struts/Spring.
>>>Basically, instead of:
>>>
>>>"firstName": Value is required.
>>>
>>>I'd like it to say "First Name is a required field."
>>>
>>>I have the following in my resource bundle, but it doesn't give me
>>>access to the field's label (i18n-ized).
>>>
>>>javax.faces.component.UIInput.REQUIRED={0} is a required field.
>>>
>>>Instead it prints:
>>>
>>>firstName is a required field.
>>>
>>>Any idea how to look up a input field's label and use the text from that
>>>in the {0}?
>>>
>>>Thanks,
>>>
>>>Matt
>>>
>>>
>>>      
>>>
>>--
>>If you don't have a GMail account, I probably have 5 invites.  Just ask!
>>-Heath Borders-Wing
>>hborders@mail.win.org
>>
>>    
>>



Re: Is it possible to change the required validation message to something friendlier?

Posted by Craig McClanahan <cr...@gmail.com>.
On Fri, 3 Dec 2004 13:21:16 -0600, Heath Borders
<he...@gmail.com> wrote:
> Unfortunately, the spec isn't very good on this matter.
> 
> Basically, you'll have to override the spec and provide custom
> functionality to be able to achieve this.
> 
> Isn't this something we could do in the MyFaces custom components?
> 
> The reason you can't do this within the spec is that the Validation
> exception that is created for empty UIInputs that are required is
> created inside UIInput.  Unfortunately, there is no way to change the
> String that the template message uses in its "{0}" place without
> overriding UIInput's validate() method.  This, of course, means that
> you would have to create extensions to all UIInputs
> (HtmlSelectOneRadio, HtmlSelectOneListbox, HtmlInputText, etc).
> 
> Perhaps someone with a little clout (i.e. Craig, Manfred), could
> suggest this to the spec guys, since I've tried to do so on the
> forums, but it has fallen on deaf ears.
> 

There actually is a way to change the message text (declare a
<message-bundle> element in faces-config.xml, and in the corresponding
ResourceBundle define messages for the keys that are described in
Section 2.5.2.4 of the spec.

What you cannot currently change is what parameters are passed in to
replace the {0} text -- right now it's the component id.  Looking into
this was on the initial radar for the JSF 1.2 expert group, but don't
know if they've discussed it yet.

The particular idea of looking up the corresponding label component is
an interesting one, but presumes that the page author is diligent
about using <h:outputLabel> elements for their field labels, instead
of <h:outputText>.  So there would have to be a fallback mechanism as
well.

On the other hand, you can also "cheat" a little, and convince JSF to
use *your* component class instead of the standard one.  Let's say
that you did a MyHtmlOutputText component that extended HtmlOutputText
and had the modified validate() method.  To register it, just do this
in your faces-config.xml file:

    <component>
        <component-type>javax.faces.HtmlOutputText</component-type>
        <component-class>com.mycompany.MyHtmlOutputText</component-class>
    </component>

and the JSF runtime, including <h:outputText>, will use your component
class instead of the standard one.  As long as you're subclassing the
one you replace, you should not have any class cast exception
problems.

Craig


Craig

> 
> 
> 
> On Fri, 03 Dec 2004 11:56:02 -0700, Matt Raible <li...@raibledesigns.com> wrote:
> > I would like to change the validation messages to be a bit more
> > friendly, like they are with Commons Validation and Struts/Spring.
> > Basically, instead of:
> >
> > "firstName": Value is required.
> >
> > I'd like it to say "First Name is a required field."
> >
> > I have the following in my resource bundle, but it doesn't give me
> > access to the field's label (i18n-ized).
> >
> > javax.faces.component.UIInput.REQUIRED={0} is a required field.
> >
> > Instead it prints:
> >
> > firstName is a required field.
> >
> > Any idea how to look up a input field's label and use the text from that
> > in the {0}?
> >
> > Thanks,
> >
> > Matt
> >
> >
> 
> 
> --
> If you don't have a GMail account, I probably have 5 invites.  Just ask!
> -Heath Borders-Wing
> hborders@mail.win.org
>

Re: Is it possible to change the required validation message to something friendlier?

Posted by Heath Borders <he...@gmail.com>.
Unfortunately, the spec isn't very good on this matter.

Basically, you'll have to override the spec and provide custom
functionality to be able to achieve this.

Isn't this something we could do in the MyFaces custom components?

The reason you can't do this within the spec is that the Validation
exception that is created for empty UIInputs that are required is
created inside UIInput.  Unfortunately, there is no way to change the
String that the template message uses in its "{0}" place without
overriding UIInput's validate() method.  This, of course, means that
you would have to create extensions to all UIInputs
(HtmlSelectOneRadio, HtmlSelectOneListbox, HtmlInputText, etc).

Perhaps someone with a little clout (i.e. Craig, Manfred), could
suggest this to the spec guys, since I've tried to do so on the
forums, but it has fallen on deaf ears.


On Fri, 03 Dec 2004 11:56:02 -0700, Matt Raible <li...@raibledesigns.com> wrote:
> I would like to change the validation messages to be a bit more
> friendly, like they are with Commons Validation and Struts/Spring.
> Basically, instead of:
> 
> "firstName": Value is required.
> 
> I'd like it to say "First Name is a required field."
> 
> I have the following in my resource bundle, but it doesn't give me
> access to the field's label (i18n-ized).
> 
> javax.faces.component.UIInput.REQUIRED={0} is a required field.
> 
> Instead it prints:
> 
> firstName is a required field.
> 
> Any idea how to look up a input field's label and use the text from that
> in the {0}?
> 
> Thanks,
> 
> Matt
> 
> 


-- 
If you don't have a GMail account, I probably have 5 invites.  Just ask!
-Heath Borders-Wing
hborders@mail.win.org