开发者

Implementing AJAX and database operations with Wicket

开发者 https://www.devze.com 2023-01-30 15:17 出处:网络
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

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
     }
};
0

精彩评论

暂无评论...
验证码 换一张
取 消