Thanks for replying but I don't think either suggestion would help.

I don't see how the ifMessage tag would allow me to change the
styleClass
of the h:inputText.

The  styleClass="#{backingBean.errorStyleClass}" might work. I assume 
there is away to get the h:inputText component from the backing bean 
(can someone tell me how?). However, I need to keep the actual 
style class in the JSP so the designers can specify it.

Would it be possible to create a boolean isFlagged() method in the
backing bean so I can do something like this.

<h:inputText id="myId"  
        value="#{myBean.myProperty}" 
        styleClass="#{myBean.flagged? 'errorStyle':'normalStyle' }"/>

public boolean isFlagged()
{
String clientId =?????
return
FacesContext.getCurrentInstance().getMessages(clientId).hasNext();
}

This seems like it would work but I don't know how to get he clientId 
of the inputText component. (I'm new to JSF and will keep looking.)

Can anyone help?

Greg

-----Original Message-----
From: Mike Kienenberger [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 09, 2006 3:48 PM
To: MyFaces Discussion
Subject: Re: Looking for equivalent to Struts errorStyleClass with an
input field

I haven't done this, but here's a couple of approaches I'd use if I
were going to.

1 ) http://issues.apache.org/jira/browse/TOMAHAWK-165
ifMessage tag that renders children only if there is a message for the
specified component(s)

2) Alternately, create a styleClass="#{backingBean.errorStyleClass}"
attribute with a method that returns either the error style or the
normal style depending on if it finds an applicable message tag.

You can also set up an h:message or t:message tag that is active only
for specific component, but I don't know if that would really help you
in your case.

On 3/9/06, Lindholm, Greg <[EMAIL PROTECTED]> wrote:
> I'm writing my first JSF application and looking for the equivalent to
> "errorStyleClass" feature I used in Struts.
>
> In Struts you can specify an "errorStyleClass" attribute on an
> <html:text>  input field tag. If a validation error occurs on that
field
> it will
> redisplay the field with the supplied errorStyleClass.
>
>         <html:text errorStyleClass="errorStyle" ....>
>
> The JSF <h:inputText > tag doesn't support this so how do you do this
> in JSF?
>
> I see something similar in the <h:message errorClass="errorStyle"...>
> tag
> but it seems to apply to the message not the input field.
>
> Is there another component I can use? Or can I embed the field in in
> another tag?

Reply via email to