tag:blogger.com,1999:blog-6189528330814114396.post9031707044886379831..comments2023-10-08T05:17:32.788-04:00Comments on The Wicket Evangelist: Marrying Wicket And jQuery AjaxJeff Schwartzhttp://www.blogger.com/profile/02747605277666816054noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-6189528330814114396.post-17108172378079965132012-01-17T10:25:00.036-05:002012-01-17T10:25:00.036-05:00I'm in the process of catching up with all you...I'm in the process of catching up with all your other Wicket articles. (pretty interesting to read , especially since I'm not very fond of Wiquery myself).<br /><br />I did it in a slightly different way: <br />Server side:<br />protected void onComponentTag(ComponentTag tag) {<br /> super.onComponentTag(tag);<br /> tag.put("callback", aab.getCallbackUrl());<br /> }<br /><br />Client side:<br />(in the "clickme" anonymous function)<br />var callback = $('form.jqueryid_form1').attr("callback")<br /><br />Then used the Jquery ajax submission (of course, I had to collect the field values "manually")Frefhttps://www.blogger.com/profile/17309797134213114726noreply@blogger.comtag:blogger.com,1999:blog-6189528330814114396.post-18354677261306853392012-01-17T09:04:02.373-05:002012-01-17T09:04:02.373-05:00Ok, now I understand and thank you for taking the ...Ok, now I understand and thank you for taking the time clarifying the issue. <br /><br />Yes, this is easily done - having one url for the ajax call back and one url for the form's action but note that I purposely used ajax form submission for this article due to its inherent advantages from the user's perspective as far as the UI is concerned. <br /><br />So how can you achieve what you are seeking? There are a few ways, actually. One way is to provide an override in the AbstractAjaxBehavior for its renderHead method. In that method render javascript to the browser that would amount to: String ajaxCallbackUrl = "var ajaxCallbackUrl = " + abstactAjaxBehavior.getCallbackUrl() + ";";<br /><br />On the client, you wouldn't use jQuery's form submit but rather would just use jQuery's normal ajax method to call the server using the ajaxCallback variable's value as the url. For an example of this technique, please see my related article 'A Reusable jQuery UI Autocomplete Wicket Component' at http://thewicketevangelist.blogspot.com/2011/12/reusable-jquery-ui-autocomplete-wicket.html. It is a little more involved than the examples I presented here but it should serve to provide you with a concrete example.<br /><br />Thank you for taking the time to respond to my article and I hope you will continue to enjoy the other articles I have written and will write.<br /><br />JeffJeff Schwartzhttps://www.blogger.com/profile/02747605277666816054noreply@blogger.comtag:blogger.com,1999:blog-6189528330814114396.post-8655541742446544762012-01-17T03:01:45.098-05:002012-01-17T03:01:45.098-05:00Jeff, I understood that, but my concern is: how do...Jeff, I understood that, but my concern is: how do you get the standard "form behaviour" if you want to actually submit the content of the form?<br /><br />I implemented the first example, which works fine, then added a submit button (standard or wicketized, it doesn't really matter). When I click on it, I see the TextHandler response, but the onSubmit() method of my button is never called.<br /><br />I'm therefore wondering : how can you get both aspects (the ajax submission through jquery and the normal form handling)?Frefhttps://www.blogger.com/profile/17309797134213114726noreply@blogger.comtag:blogger.com,1999:blog-6189528330814114396.post-31388972893323577082012-01-16T11:14:36.261-05:002012-01-16T11:14:36.261-05:00@Unknown,
All Ajax calls, regardless of the Web f...@Unknown,<br /><br />All Ajax calls, regardless of the Web framework, require a url that points to a request handler on the server. <br /><br />In both of the above examples both forms are submitted but both of their action urls are not the default form action urls that Wicket generated for the forms; they are replaced by the call back urls from the AbstractAjaxBehaviors which handles the form submission. <br /><br />So in both example both forms are submitted but submitted using ajax and are handled by the AbstractAjaxBehaviors onRequest methods.<br /><br />JeffJeff Schwartzhttps://www.blogger.com/profile/02747605277666816054noreply@blogger.comtag:blogger.com,1999:blog-6189528330814114396.post-30785114228564984782012-01-16T10:52:03.991-05:002012-01-16T10:52:03.991-05:00Interesting.
That implies that you submit your f...Interesting. <br /><br />That implies that you submit your form for a single Ajax purpose though, and the "action" value of your form is stuck to the Wicket Ajax callback. <br /><br />This seems to prevent the user from actually submitting the form itself (or (s)he would receive the Ajax response).<br /><br />Did I miss something?Frefhttps://www.blogger.com/profile/17309797134213114726noreply@blogger.com