Wicket Checkbox Attributeappender
In a code that I am working on there is a normal(no ajax) checkbox to which I want to append the JavaScript onchange event to it like: checkbox.add(new AttributeAppender('onchange'
Solution 1:
May be you can call your func(this);
function as a AjaxEventBehavior. getPreconditionScript()
or getSuccessScript()
, instead of adding and AttributeAppender
on the onchange
event.
Take a look at http://wicket.apache.org/apidocs/1.5/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.html#getPreconditionScript()
Your AjaxEventBehavior
will look similar to this:
new AjaxEventBehavior("onclick") {
protectedvoidonEvent(AjaxRequestTarget target) {
System.out.println("ajax here!");
}
protected CharSequence getSuccessScript() {
return"func(this);";
}
}
Solution 2:
Regarding my comments on the other answer, here is what I suggest using an AjaxCallDecorator
newAjaxEventBehavior('onclick'){
protectedvoidonEvent(AjaxRequestTarget target) {
//call your onclick handling logic here
}
protected IAjaxCallDecorator getAjaxCallDecorator(){
returnnewIAjaxCallDecorator(){
publicCharSequencedecorateScript(Component component,
CharSequence script){
//prepend your javascript call to ajax server callreturn"func(this);"+script;
}
publicCharSequencedecorateOnSuccessScript(Component component,
CharSequence script){
return script;
}
publicCharSequencedecorateOnFailureScript(Component component,
CharSequence script){
return script;
}
};
}
}
Post a Comment for "Wicket Checkbox Attributeappender"