You can't do that in the jsp, you need a backingBean method for this.
-------- JSP ----------
<h:inputSecret id="password" value="#{LoginBean.password}" required="true"/>
<h:outputText rendered="#{bean.messageForPassword}" value="*"/>
-------- /JSP ----------
---------- JAVA -------
public boolean isMessageForPassword() {
return hasMessageFor("loginForm:password");
}
private boolean hasMessageFor(id) {
FacesContext facesContext = FacesContext.getCurrentInstance();
Iterator iter = facesContext.getMessages(id);
return iter.hasNext();
}
---------- /JAVA -------
Regards,
Volker
Michael Heinen wrote:
> Volker,
>
> I need your help again.
>
> How can I check in a JSP whether there is a message for a field?
> I get a PropertyNotFoundException with following lines:
>
> <h:form id="loginForm">
> <h:inputSecret id="password" value="#{LoginBean.password}"
> required="true"/>
> <h:outputText rendered="#{facesContext.messages['loginForm:password'] !=
> null}" value="*"/>
>
> FacesContext.getMessages(String clientId) returns an Iterator.
> But how to pass clientId?
> Isn't clienId an identifier of the component?
>
> -----Original Message-----
> From: Volker Weber [mailto:[EMAIL PROTECTED]
> Sent: Mittwoch, 22. Februar 2006 10:18
> To: MyFaces Discussion
> Subject: Re: simple identification of incorrect fields
>
> Michael,
>
> i would prefer Andrews solution, but if you don't want to create a
> custom renderer there is another way to archive what you want.
>
> Take a outputText component and check in the rendered attribute method
> if there is a relevant message in the context.
>
> But going the custom renderer approach allows to have the message in the
> tooltip over the asterisk.
>
> Regards,
> Volker
>
>
> Andrew Robinson wrote:
>
>>I have done this using a custom renderer for the t:message tag. In
>>there I set the summary (or detail, I always get those confused on
>>which one is the tooltip), to an asterisk before passing it to the
>>base (myfaces) renderer. I clone the object before changing it though
>>so that the "messages" tag still shows the correct information and not
>>an asterisk.
>>
>>On 2/22/06, Michael Heinen <[EMAIL PROTECTED]> wrote:
>>
>>
>>>I want to show the asterisk only in error cases.
>>>
>>>It is not limited on required fields.
>>>I want to ease the finding of incorrect fields because I don't have
>>>enough room to display detailed error messages beside my fields in the
>>>form.
>>>So I have to show a detailed summary on top of my page and an asterisk
>>>or somewhat beside the fields.
>>>
>>>But I don't know how to achieve this :-(
>>>
>>>-----Original Message-----
>>>From: Sean Schofield [mailto:[EMAIL PROTECTED]
>>>Sent: Mittwoch, 22. Februar 2006 08:50
>>>To: MyFaces Discussion
>>>Subject: Re: simple identification of incorrect fields
>>>
>>>Do you only want to show them when they fail to submit a required
>>>value or do you want to show them all of the time?
>>>
>>>Sean
>>>
>>>On 2/22/06, Michael Heinen <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>>I was afraid of having to do this.
>>>>Actually I don't want to override the messages because I want to show
>>>>them in a summary list at the top of my page.
>>>>
>>>>I just want to mark the incorrect fields in addition.
>>>>Is there no other possibility or workaround?
>>>>
>>>>-----Original Message-----
>>>>From: Sean Schofield [mailto:[EMAIL PROTECTED]
>>>>Sent: Dienstag, 21. Februar 2006 19:19
>>>>To: MyFaces Discussion
>>>>Subject: Re: simple identification of incorrect fields
>>>>
>>>>The required message doesn't work this way. You need to override the
>>>>value in Message.properties if you want to use just an asterisk
>>>>character.
>>>>
>>>>The defaults are ...
>>>>
>>>>javax.faces.component.UIInput.REQUIRED = Validation Error
>>>>javax.faces.component.UIInput.REQUIRED_detail = "{0}": Value is
>>>>required.
>>>>
>>>>If you check the spec docs you can see the various ways to overload
>>>>these and replace them with your own.
>>>>
>>>>Sean
>>>>
>>>>
>>>>
>>>>On 2/21/06, Michael Heinen <[EMAIL PROTECTED]> wrote:
>>>>
>>>>
>>>>>
>>>>>Hi all,
>>>>>
>>>>>
>>>>>
>>>>>I display at the top of my page a summary of all error messages.
>>>>>
>>>>>
>>>>>
>>>>>In addition I try to mark all incorrect fields with a '*' or another
>>>>
>>>>symbol.
>>>>
>>>>
>>>>>Currently I have no idea how to implement this in an easy way.
>>>>>
>>>>>
>>>>>
>>>>>The following simple approach is not working:
>>>>>
>>>>><h:inputText id="searchName" value="#{ControllerBean.searchName}"
>>>>>required="true"/>
>>>>>
>>>>><t:message for="searchName" showDetail="false"
>>>>>showSummary="false">*</t:message>
>>>>>
>>>>>
>>>>>
>>>>>If I enclose the '*' with a verbatim tag it will be always displayed
>>>>
>>>>(even
>>>>
>>>>
>>>>>without errors).
>>>>>
>>>>>
>>>>>
>>>>>I'am sure this is a common requirement therefore this question.
>>>>>
>>>>>
>>>>>
>>>>>Michael
>>>>>
>>>>>
>>>>
>
--
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.