Implementing AJAX and database operations with Wicket
I'm trying to add AJAX to my project.
I have a link and a boolean variable named hasEngagement
in my Wicket page. I want my link to produce a JavaScript informational warning if the boolean value is true, or perform a database operation otherwise. Here's my code:
Link myLink = new Link("mylink"){
@Override
onSubmit(){
if(hasEngagement)
//ajax operation
开发者_开发技巧 else
// database operation
}
};
You need to use an AjaxLink: http://wicket.apache.org/apidocs/1.4/org/apache/wicket/ajax/markup/html/AjaxLink.html
And override onClick
cheers
Lee
Also you can assign your message to a Feedback message. And of course use AjaxLink
AjaxLink myLink = new AjaxLink("mylink") {
@Override
public void onClick(AjaxRequestTarget target) {
if (hasEngagement) {
target.appendJavascript("alert('information warning');");
} else {
// database operation
}
};
精彩评论