You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "j.palleschitz" <j....@ad2book.com> on 2008/10/16 11:41:27 UTC

h:messages validation-messages without formid ?

hi,

in case of a required-field validation i get a message that starts with

formid:nameoffield: text of the validation


is it possible to customize the validation-messages only to

nameoffield: text of the validation  ???


i have already defined a custom message in my message.properties, but the
{0}

return "formid:nameoffield".

(javax.faces.component.UIInput.REQUIRED={0}: you have to enter something!)


thats not really nice to read for the users.


any ideas? 


thanks a lot.

johannes

-- 
View this message in context: http://www.nabble.com/h%3Amessages-validation-messages-without-formid---tp20010322p20010322.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.

Re: h:messages valition-messages without formid ?

Posted by Simon Kitching <sk...@apache.org>.
FYI, Mario Ivankovits has reminded me that the tomahawk t:messages
component has some related functionality.

When a component has an associated label component, then it can modify
the message by replacing the component's id with the text of the label.
Or something like that; hopefully the t:messages component describes
this feature in more detail. So if you are willing to use t:messages
instead of h:messages this might be useful...

Regards, Simon


Simon Kitching schrieb:
> Hmm. I know myfaces had a bug where resource-bundles are not available
> during the postback phase.
>
> I wonder if that ever got fixed. If not, that might be the cause.
> Usually resource-bundles are not needed during postback; generation of
> text output is done during rendering. Except that *validation messages*
> are of course resolved during the postback phase.
>
> I suggest you search the myfaces JIRA system to see if you can find an
> existing issue related to resource-bundles and postback. If so, then
> that's the problem. As a workaround, you might try writing a
> PhaseListener that always stores your resource-bundle into the current
> request scope; that should be about 10 lines of code.
>
> Anyway even using a simple literal for the label is at least better than
> what you had before, right?
>
> Regards,
> Simon
>
> j.palleschitz schrieb:
>   
>> thanks simon,
>>
>> the label-parameter looked like a solution.
>> but it cannot resolve my resource-bundles.
>>
>> if i set label="#{label.username}" the message start with ": ..."
>> when label="Username" it looks fine.
>>
>> so it´s not the solution i´ve looked for.
>>
>> i can´t believe that such a behavior is wanted from myfaces.
>>
>>
>>
>> Simon Kitching wrote:
>>   
>>     
>>> While testing something else, I took a moment to check how Sun's Mojarra
>>> handles required-messages. It also inserts the clientId (ie *with* the
>>> form/subview prefix). Therefore myfaces 1.2.x and mojarra currently work
>>> the same. I think it unlikely that MyFaces would accept a patch to
>>> change its default behaviour to something different from Mojarra, although
>>> (a) you could try; the decision is not mine to make, and
>>> (b) you could create and offer a patch to make the behaviour configurable
>>>
>>> Re the "label" attribute I mentioned below: it looks like JSF also added
>>> this optional attribute to customise the {0} parameter, eg
>>>   <h:input id="someProgrammerId" label="someUserLabel" required="true"../>
>>> will generate whatever generic "required" message is configured, but
>>> with {0} set to "someUserLabel". This feature still requires setting
>>> this on each component though.
>>>
>>> Regards,
>>> Simon
>>>
>>>     
>>>       
>>   
>>     
>
>
>   


Re: h:messages valition-messages without formid ?

Posted by Simon Kitching <sk...@apache.org>.
Hmm. I know myfaces had a bug where resource-bundles are not available
during the postback phase.

I wonder if that ever got fixed. If not, that might be the cause.
Usually resource-bundles are not needed during postback; generation of
text output is done during rendering. Except that *validation messages*
are of course resolved during the postback phase.

I suggest you search the myfaces JIRA system to see if you can find an
existing issue related to resource-bundles and postback. If so, then
that's the problem. As a workaround, you might try writing a
PhaseListener that always stores your resource-bundle into the current
request scope; that should be about 10 lines of code.

Anyway even using a simple literal for the label is at least better than
what you had before, right?

Regards,
Simon

j.palleschitz schrieb:
> thanks simon,
>
> the label-parameter looked like a solution.
> but it cannot resolve my resource-bundles.
>
> if i set label="#{label.username}" the message start with ": ..."
> when label="Username" it looks fine.
>
> so it´s not the solution i´ve looked for.
>
> i can´t believe that such a behavior is wanted from myfaces.
>
>
>
> Simon Kitching wrote:
>   
>> While testing something else, I took a moment to check how Sun's Mojarra
>> handles required-messages. It also inserts the clientId (ie *with* the
>> form/subview prefix). Therefore myfaces 1.2.x and mojarra currently work
>> the same. I think it unlikely that MyFaces would accept a patch to
>> change its default behaviour to something different from Mojarra, although
>> (a) you could try; the decision is not mine to make, and
>> (b) you could create and offer a patch to make the behaviour configurable
>>
>> Re the "label" attribute I mentioned below: it looks like JSF also added
>> this optional attribute to customise the {0} parameter, eg
>>   <h:input id="someProgrammerId" label="someUserLabel" required="true"../>
>> will generate whatever generic "required" message is configured, but
>> with {0} set to "someUserLabel". This feature still requires setting
>> this on each component though.
>>
>> Regards,
>> Simon
>>
>>     
>
>   


-- 
-- Emails in "mixed" posting style will be ignored
-- (http://en.wikipedia.org/wiki/Posting_style)


Re: h:messages valition-messages without formid ?

Posted by "j.palleschitz" <j....@ad2book.com>.
thanks simon,

the label-parameter looked like a solution.
but it cannot resolve my resource-bundles.

if i set label="#{label.username}" the message start with ": ..."
when label="Username" it looks fine.

so it´s not the solution i´ve looked for.

i can´t believe that such a behavior is wanted from myfaces.



Simon Kitching wrote:
> 
> While testing something else, I took a moment to check how Sun's Mojarra
> handles required-messages. It also inserts the clientId (ie *with* the
> form/subview prefix). Therefore myfaces 1.2.x and mojarra currently work
> the same. I think it unlikely that MyFaces would accept a patch to
> change its default behaviour to something different from Mojarra, although
> (a) you could try; the decision is not mine to make, and
> (b) you could create and offer a patch to make the behaviour configurable
> 
> Re the "label" attribute I mentioned below: it looks like JSF also added
> this optional attribute to customise the {0} parameter, eg
>   <h:input id="someProgrammerId" label="someUserLabel" required="true"../>
> will generate whatever generic "required" message is configured, but
> with {0} set to "someUserLabel". This feature still requires setting
> this on each component though.
> 
> Regards,
> Simon
> 

-- 
View this message in context: http://www.nabble.com/h%3Amessages-validation-messages-without-formid---tp20010322p20147227.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: h:messages valition-messages without formid ?

Posted by Simon Kitching <sk...@apache.org>.
While testing something else, I took a moment to check how Sun's Mojarra
handles required-messages. It also inserts the clientId (ie *with* the
form/subview prefix). Therefore myfaces 1.2.x and mojarra currently work
the same. I think it unlikely that MyFaces would accept a patch to
change its default behaviour to something different from Mojarra, although
(a) you could try; the decision is not mine to make, and
(b) you could create and offer a patch to make the behaviour configurable

Re the "label" attribute I mentioned below: it looks like JSF also added
this optional attribute to customise the {0} parameter, eg
  <h:input id="someProgrammerId" label="someUserLabel" required="true"../>
will generate whatever generic "required" message is configured, but
with {0} set to "someUserLabel". This feature still requires setting
this on each component though.

Regards,
Simon

Simon Kitching schrieb:
> As I said earlier in this thread: set an explicit requiredMessage string.
>
> IMO, expecting component ids to be meaningful as part of error messages
> is wrong. They (a) are names chosen by a programmer for coding purposes
> not ui purposes, and (b) are not localisable. The default behaviour of
> inserting the id/clientId into the message should be just a last fallback.
>
> The code that actually handles this is
>     UIInput.validateValue
> which invokes
>    _MessageUtils.getLabel
> which returns component.getClientId by default.
>
> It is interesting that myfaces 1.1.x inserts just the component id by
> default, while myfaces 1.2 inserts the component clientId. Catagay
> Civici made these changes in r518079 and r518084 but there is no hint
> there why he made it use the full clientId instead of just id.
>
> Interestingly, _MessageUtils.getLabel (myfaces 1.2.x) does also look for
> an attribute or valueExpression called "label", and returns that if
> present. I wonder what that is for...
>
> Have you tried Sun Mojarra? If that outputs ids rather than client-ids
> then there is a reasonable chance that myfaces would be changed to
> match. But IMO it would *still* be wrong to rely on ids to create
> meaningful error messages for users.
>
> Regards,
> Simon
>
> j.palleschitz schrieb:
>   
>> could someone tell me what the problem could be? please  ;o)
>>
>> i get following message:  contentView:Username: required field!
>>
>> and this looks not really nice.
>>
>>
>>
>>
>> j.palleschitz wrote:
>>   
>>     
>>> hi, 
>>>
>>> now i have another problem like this.
>>> the id of the subview is rendered before den Message.
>>>
>>> any idea?
>>>
>>> thanks
>>>
>>>     
>>>       
>>   
>>     
>
>
>   


-- 
-- Emails in "mixed" posting style will be ignored
-- (http://en.wikipedia.org/wiki/Posting_style)


Re: h:messages valition-messages without formid ?

Posted by Simon Kitching <sk...@apache.org>.
As I said earlier in this thread: set an explicit requiredMessage string.

IMO, expecting component ids to be meaningful as part of error messages
is wrong. They (a) are names chosen by a programmer for coding purposes
not ui purposes, and (b) are not localisable. The default behaviour of
inserting the id/clientId into the message should be just a last fallback.

The code that actually handles this is
    UIInput.validateValue
which invokes
   _MessageUtils.getLabel
which returns component.getClientId by default.

It is interesting that myfaces 1.1.x inserts just the component id by
default, while myfaces 1.2 inserts the component clientId. Catagay
Civici made these changes in r518079 and r518084 but there is no hint
there why he made it use the full clientId instead of just id.

Interestingly, _MessageUtils.getLabel (myfaces 1.2.x) does also look for
an attribute or valueExpression called "label", and returns that if
present. I wonder what that is for...

Have you tried Sun Mojarra? If that outputs ids rather than client-ids
then there is a reasonable chance that myfaces would be changed to
match. But IMO it would *still* be wrong to rely on ids to create
meaningful error messages for users.

Regards,
Simon

j.palleschitz schrieb:
> could someone tell me what the problem could be? please  ;o)
>
> i get following message:  contentView:Username: required field!
>
> and this looks not really nice.
>
>
>
>
> j.palleschitz wrote:
>   
>> hi, 
>>
>> now i have another problem like this.
>> the id of the subview is rendered before den Message.
>>
>> any idea?
>>
>> thanks
>>
>>     
>
>   


-- 
-- Emails in "mixed" posting style will be ignored
-- (http://en.wikipedia.org/wiki/Posting_style)


Re: h:messages valition-messages without formid ?

Posted by "j.palleschitz" <j....@ad2book.com>.
could someone tell me what the problem could be? please  ;o)

i get following message:  contentView:Username: required field!

and this looks not really nice.




j.palleschitz wrote:
> 
> hi, 
> 
> now i have another problem like this.
> the id of the subview is rendered before den Message.
> 
> any idea?
> 
> thanks
> 

-- 
View this message in context: http://www.nabble.com/h%3Amessages-validation-messages-without-formid---tp20010322p20105296.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: h:messages valition-messages without formid ?

Posted by "j.palleschitz" <j....@ad2book.com>.
hi, 

now i have another problem like this.
the id of the subview is rendered before den Message.

any idea?

thanks


jamiebarrow wrote:
> 
> Hi,
> 
> I know that you can stop JSF from prepending the formid, as below, if
> that helps... not sure if it does haven't tried it :)
> 
> <h:form id="myFormId" prependId="false">
> 
> Cheers,
> 
> James
> 
> On Thu, Oct 16, 2008 at 11:58 AM, j.palleschitz
> <j....@ad2book.com> wrote:
>>
>> thanks, i know this property, but its not really my target to
>> edit all my pages and add to each inputfield the "requiredMessage".
>>
>> i only want to remove the "formid:" !
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/h%3Amessages-validation-messages-without-formid---tp20010322p20076544.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: h:messages valition-messages without formid ?

Posted by "j.palleschitz" <j....@ad2book.com>.
That solves the problem.
thanks a lot, james.



jamiebarrow wrote:
> 
> Hi,
> 
> I know that you can stop JSF from prepending the formid, as below, if
> that helps... not sure if it does haven't tried it :)
> 
> <h:form id="myFormId" prependId="false">
> 
> Cheers,
> 
> James
> 

-- 
View this message in context: http://www.nabble.com/h%3Amessages-validation-messages-without-formid---tp20010322p20011196.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: h:messages valition-messages without formid ?

Posted by James Barrow <ja...@gmail.com>.
Hi,

I know that you can stop JSF from prepending the formid, as below, if
that helps... not sure if it does haven't tried it :)

<h:form id="myFormId" prependId="false">

Cheers,

James

On Thu, Oct 16, 2008 at 11:58 AM, j.palleschitz
<j....@ad2book.com> wrote:
>
> thanks, i know this property, but its not really my target to
> edit all my pages and add to each inputfield the "requiredMessage".
>
> i only want to remove the "formid:" !
>

Re: h:messages valition-messages without formid ?

Posted by "j.palleschitz" <j....@ad2book.com>.
thanks, i know this property, but its not really my target to
edit all my pages and add to each inputfield the "requiredMessage".

i only want to remove the "formid:" !

no solution for this problem.
JSF1.2 has some really strange new features.



Simon Kitching wrote:
> 
> j.palleschitz schrieb:
>> hi, in case of a required-field validation i get a message that starts 
>> with
>> /formid:nameoffield: text of the validation/
>>
>> is it possible to customize the validation-messages only to
>> /nameoffield: text of the validation/ ???
>>
>> i have already defined a custom message in my message.properties, but 
>> the {0}
>> return "formid:nameoffield".
>> (javax.faces.component.UIInput.REQUIRED={0}: you have to enter
>> something!)
>>
>> thats not really nice to read for the users.
>>
>> any ideas?
> In JSF1.2, every input component has an optional "requiredMessage" 
> property. So you can do:
>   <h:inputText id="userName" required="true" requiredMessage="You must 
> enter a user name" ... />
> 
> Regards,
> Simon
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/h%3Amessages-validation-messages-without-formid---tp20010322p20010501.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: h:messages valition-messages without formid ?

Posted by Simon Kitching <sk...@apache.org>.
j.palleschitz schrieb:
> hi, in case of a required-field validation i get a message that starts 
> with
> /formid:nameoffield: text of the validation/
>
> is it possible to customize the validation-messages only to
> /nameoffield: text of the validation/ ???
>
> i have already defined a custom message in my message.properties, but 
> the {0}
> return "formid:nameoffield".
> (javax.faces.component.UIInput.REQUIRED={0}: you have to enter something!)
>
> thats not really nice to read for the users.
>
> any ideas?
In JSF1.2, every input component has an optional "requiredMessage" 
property. So you can do:
  <h:inputText id="userName" required="true" requiredMessage="You must 
enter a user name" ... />

Regards,
Simon