The message errorClass sets the errorClass of the message, I'm trying to
set the styleClass of inputText to something different when there is an
error.
 
I think the isFlagged() method will work if I can figure out how to get
the clientId of the inputText component. Can anyone help?


-----Original Message-----
From: Jimmy Emmanual [mailto:[EMAIL PROTECTED] 
Sent: Friday, March 10, 2006 1:06 PM
To: MyFaces Discussion
Subject: RE: Looking for equivalent to Struts errorStyleClass with an
input field

Use the errorClass of message...

<h:form>
<h:panelGrid columns="2" rowClasses="cRows">
   <h:outputText value="#{msgs.namePrompt}"/>
   <h:panelGroup>
          <h:inputText id="name" required="true"/>
          <h:message for="name" errorClass="errors"/>
   </h:panelGroup>
   <h:outputText value="#{msgs.agePrompt}"/>
   <h:inputText size="3"/>
</h:panelGrid>
<br/>
<h:commandButton value="#{msgs.submitPrompt}"/>
</h:form>

-----Original Message-----
From: Lindholm, Greg [mailto:[EMAIL PROTECTED] 
Sent: Friday, March 10, 2006 11:37 AM
To: MyFaces Discussion
Subject: RE: Looking for equivalent to Struts errorStyleClass with an
input field

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