On Fri, 09 Nov 2007, BatiB80 wrote:
> example: myfield.add(new AttributeModifier("class", getClassValue());

myfield.add(new RedIfInvalid(myfield));

public class RedIfInvalid extends AttributeModifier() {
    private final FormComponent component;

    public RedIfInvalid(FormComponent component) {
        super("class", true, new AbstractReadOnlyModel() {
            @Override
            public Object getObject() {
                if (component.isValid() {
                    return "green";
                }
                return "red";
            }
        }
        this.component = component;
    }
}

Or something like that. 

It's a bit tricky if you want to make it work on ajax (e.g.
with OnChangeAjaxBehavior, I think you have to explicitly
call validate() or something), but very cool :)

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to