Hello All,
I just wanted to thank you all for your help. I thought posting the solution
back to the list will help other people in the future.
Oki - I did the following:
I created a map for the clientId's which will hold required validation messages.
Map styleMap = new HashMap();
An additional 'getRequired" method is executed by all the components which
should get the style:
<h:inputText id="emailAddress"
value="#{ActivationForm.emailAddress}"
size="25"
required="true"
style="#{ActivationForm.required ?
ActivationForm.styleMap['emailAddress'] : ''}"
></h:inputText>
The following method finds out if there are any components with messages, adds
it to the styleMap and returns true if so.
public boolean getRequired(){
styleMap.clear();
FacesContext context = FacesContext.getCurrentInstance();
Iterator itr = context.getClientIdsWithMessages();
boolean ret_val = false;
try{
while (itr.hasNext()) {
String clientId = (String) itr.next();
UIComponent uic =
context.getCurrentInstance().getViewRoot().findComponent(clientId);
styleMap.put(uic.getId(),"background: red");
ret_val = true;
}
}catch(Exception ex){}
return ret_val;
}
That also works pretty good for components in a dataTable.
Thanks again - have a good one,
Nico
Nico Krause| Software Development| TomTom WORK | [EMAIL PROTECTED] | +49
(0)1749891949 mobile | +49(0)34124495-0 office | +49(0)34124495-25 fax |
www.tomtomwork.com
-----Ursprüngliche Nachricht-----
Von: news [mailto:[EMAIL PROTECTED] Im Auftrag von Laurie Harper
Gesendet: Donnerstag, 16. März 2006 06:11
An: [email protected]
Betreff: Re: (Validation) required="true" should change my css style of
inputbox e.g. background:red
Yep, that's the simplest solution. If you don't want to emit the
style/styleClass value from a backing bean you can also use a variant such as
<h:inputText ... styleClass="#{mybean.required ? 'required' : ''}"/>
Regarding your concern about doing this in a data table, you shouldn't have any
problem provided you have the isRequired() method on each row item in your
table model.
L.
CONNER, BRENDAN (SBCSI) wrote:
> if you can compute the style you want from the information you have in
> one of your managed beans, I believe you can also do one of the
> following:
>
> <h:inputText ... style="#{myBean.myStyle}"/>
>
> or
>
> <h:inputText ... style="#{myBean.myStyle}"/>
>
> - Brendan
>
> -----Original Message-----
> From: Christian Bohn [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 15, 2006 8:46 AM
> To: MyFaces Discussion
> Subject: Re: (Validation) required="true" should change my css style
> of inputbox e.g. background:red
>
>
> Hi,
>
> why don't you simply define two inputfields and render only one like
> this:
>
> ....
> <t:inputText rendered="#{<<the EL-expression you used in your
> required-attribute or simply true or false}" required="true"
> styleClass="red" .... />
> <t:inputText rendered="#{! <<the EL-expression you used in your
> required-attribute or simply true or false}" required="false"
> styleClass="normal" .... />
> ....
>
> greetings
>
> Chrstian
>
>
>
>
>