Hi,
I've written a TextField component that starts (by subclassing) from TextField and when the component is not valid it adds a custom css and it appends the error description near the field. The goal was to create a replacement for TextField leaving the html as it was before the subclassed TextField usage (i.e. the only required change is the the class name in the java code) I've implementend the component with two behaviours and the core lies in the onBeforeRender method. I'm wondering if there are better approaches to achive the result; here is the method implementation:
    @Override
    public void onBeforeRender() {
        if (!isValid()) {
            add(cssErrorAppender);
            add(errorMessageBehaviour);
            final String error;
String preMessage=prefix +"<" + errorDescriptionTag +" class=\""+ errorDescriptionClass + "\">";
            String postMessage="</"+ errorDescriptionTag + ">";
            if (hasFeedbackMessage()) {
error = preMessage +getFeedbackMessage().getMessage().toString()+ postMessage;
            } else {
error = preMessage +getString("input.invalid") + postMessage;
            }
            errorMessageBehaviour.setErrorDescription(error);
            addedBehaviour=true;
        } else {
            if (addedBehaviour) {
                remove(cssErrorAppender);
                remove(errorMessageBehaviour);
                addedBehaviour=false;
            }
        }
        super.onBeforeRender();
    }

here is the declaration of behaviour

private AttributeAppender cssErrorAppender=new AttributeAppender("class", new Model<String>(errorClass), " "); private ErrorMessageBehaviour errorMessageBehaviour=new ErrorMessageBehaviour();

Thanks,
       Giovanni

--
Giovanni Cuccu
Responsabile area sviluppo - CUP 2000 Spa
Via del Borgo di S. Pietro, 90/c - 40126 Bologna
e-mail: giovanni.cuccu _at_ cup2000.it


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to