I have tried out the suggestion in the post
(*)
http://article.gmane.org/gmane.comp.java.tapestry.user/38761/match=required+validator

to implement client side 'required' validation on a 
Checkbox compponent (in Tapestry 4.0.2).
In (*), a validator with a custom javascript to
validate a required checkbox was given.

When I test it, the javascript  does the validation
never get rendered. 
After some debugging, I noticed that in the method
renderComponent of Checkbox.java,
it does not call
 
getValidatableFieldSupport().renderContributions(this,
writer, cycle);


It is in  the method
getValidatableFieldSupport().renderContributions()
that
the javascript that does the validation is rendered. 
After adding 
getValidatableFieldSupport().renderContributions(this,
writer, cycle);
into  the  method renderComponent of Checkbox.java,
the client side validation works. 
Also if I add

renderDelegatePrefix(writer, cycle);
and 
 renderDelegateSuffix(writer, cycle);

to   the  method renderComponent of Checkbox.java.
the custom required validator also works when the
validation is done on the server.

Here is the modified  renderComponent method  of
Checkbox.java :

 protected void renderFormComponent(IMarkupWriter
writer, IRequestCycle cycle)
    {
        // New
        renderDelegatePrefix(writer, cycle);
         
        writer.beginEmpty("input");
        writer.attribute("type", "checkbox");

        writer.attribute("name", getName());

        if (isDisabled())
            writer.attribute("disabled", "disabled");

        if (getValue())
            writer.attribute("checked", "checked");

        renderIdAttribute(writer, cycle);
        
        // New
       
getValidatableFieldSupport().renderContributions(this,
writer, cycle);
        
        renderInformalParameters(writer, cycle);

        writer.closeTag();
        // New
        renderDelegateSuffix(writer, cycle);
    }


Components like TextField and TextArea have  
        renderDelegatePrefix(writer, cycle);
        
       
getValidatableFieldSupport().renderContributions(this,
writer, cycle);
        renderDelegateSuffix(writer, cycle)

in their renderComponent methods.
Shouldn't  Checkbox be the same ?

Shing 


Home page :
  http://uk.geocities.com/matmsh/index.html


                
___________________________________________________________ 
The all-new Yahoo! Mail goes wherever you go - free your email address from 
your Internet provider. http://uk.docs.yahoo.com/nowyoucan.html

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

Reply via email to