I have a form with subtmit button but this is implemented by Wicket's AjaxButton class. When HTML page rendered Wicket keeps a javascrpt onClick method dynamically for that submit button.
I want to do some operations using JQuery after Wicket's onClick method completed. How do I do this?
views:
84answers:
2
+3
A:
protected void onClick(AjaxRequestTarget target){
target.appendJavascript("alert('hello');");
)
black666
2010-10-04 21:02:57
In appendJavascript if you pass any JQuery function name, it is not working. For simple javascripts like alert is OK.
goutham
2010-10-04 21:47:54
if it doesn't work, you are probably doing something wrong. It *should* work that way. (+1)
seanizer
2010-10-05 14:11:56
+1
A:
Using JQuery or any other JavaScript library works like a charm in wicket if you do it right.
First of all you need to make sure the library is present. You usually do that using a JavascriptPackageResource.
add(JavascriptPackageResource.getHeaderContribution("/path/to/jquery.js"));
(Put this in a constructor or dynamic initializer or in onBeforeRender())
Then, you need to make sure that
- your component has an id (use
Component.setOutputMarkupId(true)
) and - you are using the correct id in the
JQuery function (always retrieve the id via
Component.getMarkupId()
)
Here's an example with a button that turns blue when clicked:
add(new AjaxButton("id"){
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form){
target.appendJavascript(
"$('#" +getMarkupId() +"').css({'background':'blue'})");
}
}.setOutputMarkupId(true));
seanizer
2010-10-05 14:10:50