Re: Javascript call to wicket
Hi Erik, I used your solution and it works great for ff, while ie seem to have problems with it. Have you run it also in ie? Thanks, Itay Erik van Oosten wrote: I just finished an experiment with something like that. Its still ugly and very static, but here is my code. In the HTML header the function you can call from Flash: function(someValue) { var inputEl = document.getElementById('anchor8'); inputEl.value = someValue; eval(inputEl.getAttribute('onclick')); } Somewhere in the page: form wicket:id=ajaxForm style=display: none;input wicket:id=myField type=hidden value=//form Note that 'anchor8', the Wicket generated id of the input element, still needs te be made dynamic. Not sure how yet. The code: Form form = new Form(ajaxForm); add(form); final HiddenField myField = new HiddenField(myField, new Model(), String.class); form.add(myField); myField.add(new AjaxFormSubmitBehavior(onclick) { @Override protected void onError(AjaxRequestTarget target) { throw new RuntimeException(foutje); // not sure what to do here } @Override protected void onSubmit(AjaxRequestTarget target) { String myValue = (String) myField.getConvertedInput(); processAjaxRequest(target, myValue); } }); Improvements are very welcome. Regards, Erik. Sébastien Piller wrote: Hello guys, I've a little question about the javascript and wicket. I need to update some models on server side using javascript (in fact, I need to update it from a flash object, and that's why I use js). But I have no idea about how to do this... I know how to call a JS function from flash, but I don't know how to update a wicket model using a javascript/ajax call. Has anybody some hint about that? Thanks you - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p21035640.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Javascript call to wicket
Hello Itay, It was just an experiment. I have never actually used it. Its been a long time ago too.. If may suggest, please try Firebug Lite to debug it. Sorry I can't be of more help. Regards, Erik. itayh wrote: Hi Erik, I used your solution and it works great for ff, while ie seem to have problems with it. Have you run it also in ie? Thanks, Itay Erik van Oosten wrote: I just finished an experiment with something like that. Its still ugly and very static, but here is my code. In the HTML header the function you can call from Flash: function(someValue) { var inputEl = document.getElementById('anchor8'); inputEl.value = someValue; eval(inputEl.getAttribute('onclick')); } Somewhere in the page: form wicket:id=ajaxForm style=display: none;input wicket:id=myField type=hidden value=//form Note that 'anchor8', the Wicket generated id of the input element, still needs te be made dynamic. Not sure how yet. The code: Form form = new Form(ajaxForm); add(form); final HiddenField myField = new HiddenField(myField, new Model(), String.class); form.add(myField); myField.add(new AjaxFormSubmitBehavior(onclick) { @Override protected void onError(AjaxRequestTarget target) { throw new RuntimeException(foutje); // not sure what to do here } @Override protected void onSubmit(AjaxRequestTarget target) { String myValue = (String) myField.getConvertedInput(); processAjaxRequest(target, myValue); } }); Improvements are very welcome. Regards, Erik. -- Erik van Oosten http://www.day-to-day-stuff.blogspot.com/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Javascript call to wicket
Thanks, it's short and precise. I have nothing more to say about this ;) Erik van Oosten-3 wrote: I did not find the results of this thread on the Wiki yet, so I created the following page: http://cwiki.apache.org/confluence/display/WICKET/Calling+Wicket+from+Javascript Comments and edits are appreciated. There is a TODO on the page for providing an example that adds Javascript to the header. Or perhaps this should be on another page under AJAX? Thanks for sharing the information! Regards, Erik. -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14800946.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
I did not find the results of this thread on the Wiki yet, so I created the following page: http://cwiki.apache.org/confluence/display/WICKET/Calling+Wicket+from+Javascript Comments and edits are appreciated. There is a TODO on the page for providing an example that adds Javascript to the header. Or perhaps this should be on another page under AJAX? Thanks for sharing the information! Regards, Erik. Gwyn Evans wrote: As Cemel suggested, if you have time to put a summary up on the Wiki, it would be appreciated! /Gwyn - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
Yes, I'd like to do it, but as english is not my mother language, I need somebody to correct it after I write it. Who wants to do that? ;) Gwyn Evans a crit: As Cemel suggested, if you have time to put a summary up on the Wiki, it would be appreciated! - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
As Cemel suggested, if you have time to put a summary up on the Wiki, it would be appreciated! /Gwyn On 09/01/2008, Pills [EMAIL PROTECTED] wrote: Thank you, now everything works fine, and it's clean ;) Michael Sparer wrote: You can do that like so: Map map = ((WebRequestCycle)RequestCycle.get()).getRequest().getParameterMap(); Maybe there's also an easier way but I'm not really into wicket's requestcycle ... -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14707957.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Download Wicket 1.3.0-rc1 now! - http://wicketframework.org - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
We can probably take a look and I am sure others will help once its up on the wiki. These may be useful references too: http://www.nabble.com/integrating-extjs-with-wicket-to14715123.html here and http://www.nabble.com/calling-javascript-function-on-wicket-component%27s-onclick-to14730927.html here Regards - Cemal http://jWeekend.co.uk http://jWeekend.co.uk Pills wrote: Yes, I'd like to do it, but as english is not my mother language, I need somebody to correct it after I write it. Who wants to do that? ;) Gwyn Evans a eacute;critnbsp;: As Cemel suggested, if you have time to put a summary up on the Wiki, it would be appreciated! - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14735841.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
Ok, I'll write it maybe tomorrow or this week end (I'm quite busy but I can take an hour or two to write it). Michael Sparer wrote: I'm also no native speaker but I'll certainly read through it and write some enhancements (if necessary) once it's in the wiki regards, Michael -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14736458.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
I'm also no native speaker but I'll certainly read through it and write some enhancements (if necessary) once it's in the wiki regards, Michael jweekend wrote: We can probably take a look and I am sure others will help once its up on the wiki. These may be useful references too: http://www.nabble.com/integrating-extjs-with-wicket-to14715123.html here and http://www.nabble.com/calling-javascript-function-on-wicket-component%27s-onclick-to14730927.html here Regards - Cemal http://jWeekend.co.uk http://jWeekend.co.uk Pills wrote: Yes, I'd like to do it, but as english is not my mother language, I need somebody to correct it after I write it. Who wants to do that? ;) Gwyn Evans a eacute;critnbsp;: As Cemel suggested, if you have time to put a summary up on the Wiki, it would be appreciated! - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Michael Sparer http://talk-on-tech.blogspot.com -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14735846.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
Hi Michael Why not just have a page with a hidden form, then fill the values via javascript and submit the form again via javascript? -Nino Michael Sparer wrote: The parameters you defined in JS are regular HTTP GET parameters, so, as I wrote earlier, you can get them out of the request. You can do that like so: Map map = ((WebRequestCycle)RequestCycle.get()).getRequest().getParameterMap(); Maybe there's also an easier way but I'm not really into wicket's requestcycle ... Pills wrote: Thank you, I choosed your first and pretty solution, and it works fine. But how to get the parameters in the java code? I see nothing in the class AjaxRequestTarget that may return the parameters of the request? Michael Sparer wrote: hi, - your component has to implement IHeaderContributor, that's where the response-object gets passed - you add the abstractdefaultajaxbehavior to the component you'd like to call from javascript. you then have to override the respond method of AbstractDefaultAjaxBehavior to perform your actions and to append your changes to the response - Michael Sparer http://talk-on-tech.blogspot.com -- Nino Martinez Wael Java Specialist @ Jayway DK http://www.jayway.dk +45 2936 7684 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
Thank you, now everything works fine, and it's clean ;) Michael Sparer wrote: You can do that like so: Map map = ((WebRequestCycle)RequestCycle.get()).getRequest().getParameterMap(); Maybe there's also an easier way but I'm not really into wicket's requestcycle ... -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14707957.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
Generally you can get the callback-url of a wicket ajax-component with calling getCallbackUrl(), you should have a look at wicketAjaxGet which is part of wicket's JS library to make the whole stuff a bit more dynamic you could make a javascript template using wicketstuff-dojo, e.g. function callWicket() { var wcall = wicketAjaxGet('${url}' + addToUrl, function() { }, function() { }); // addToUrl are optional parameters } and then in the java-code HashMapString, String map = new HashMapString, String(); map.put(url, getCallbackUrl().toString()); // getcallbackurl is from AbstractAjaxBehavior return new DojoPackagedTextTemplate(YourClass.class, CometdDefaultBehaviorTemplate.js) .asString(map); and then add it in your responseheader (renderHead method) with response.renderJavaScript(...) this may be not the easiest method but allows the most flexibility. hope that helps Michael Pills wrote: Hello guys, I've a little question about the javascript and wicket. I need to update some models on server side using javascript (in fact, I need to update it from a flash object, and that's why I use js). But I have no idea about how to do this... I know how to call a JS function from flash, but I don't know how to update a wicket model using a javascript/ajax call. Has anybody some hint about that? Thanks you - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Michael Sparer http://talk-on-tech.blogspot.com -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14688033.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
Michael Sparer wrote: Generally you can get the callback-url of a wicket ajax-component with calling getCallbackUrl(), you should have a look at wicketAjaxGet which is part of wicket's JS library to make the whole stuff a bit more dynamic you could make a javascript template using wicketstuff-dojo, e.g. function callWicket() { var wcall = wicketAjaxGet('${url}' + addToUrl, function() { }, function() { }); // addToUrl are optional parameters } and then in the java-code HashMapString, String map = new HashMapString, String(); map.put(url, getCallbackUrl().toString()); // getcallbackurl is from AbstractAjaxBehavior return new DojoPackagedTextTemplate(YourClass.class, CometdDefaultBehaviorTemplate.js) .asString(map); and then add it in your responseheader (renderHead method) with response.renderJavaScript(...) this may be not the easiest method but allows the most flexibility. hope that helps Michael Hello Michael, thank you for your answer. I have two little problems with this way: - how can I get an instance of ResponseHeader from a WebPage? - I need to use an AbstractAjaxBehavior, but where do I need to add it? Simply on the page? Or on my ShockwaveComponent? Thank you ;) -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14689818.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
I just finished an experiment with something like that. Its still ugly and very static, but here is my code. In the HTML header the function you can call from Flash: function(someValue) { var inputEl = document.getElementById('anchor8'); inputEl.value = someValue; eval(inputEl.getAttribute('onclick')); } Somewhere in the page: form wicket:id=ajaxForm style=display: none;input wicket:id=myField type=hidden value=//form Note that 'anchor8', the Wicket generated id of the input element, still needs te be made dynamic. Not sure how yet. The code: Form form = new Form(ajaxForm); add(form); final HiddenField myField = new HiddenField(myField, new Model(), String.class); form.add(myField); myField.add(new AjaxFormSubmitBehavior(onclick) { @Override protected void onError(AjaxRequestTarget target) { throw new RuntimeException(foutje); // not sure what to do here } @Override protected void onSubmit(AjaxRequestTarget target) { String myValue = (String) myField.getConvertedInput(); processAjaxRequest(target, myValue); } }); Improvements are very welcome. Regards, Erik. Sébastien Piller wrote: Hello guys, I've a little question about the javascript and wicket. I need to update some models on server side using javascript (in fact, I need to update it from a flash object, and that's why I use js). But I have no idea about how to do this... I know how to call a JS function from flash, but I don't know how to update a wicket model using a javascript/ajax call. Has anybody some hint about that? Thanks you - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
hi, - your component has to implement IHeaderContributor, that's where the response-object gets passed - you add the abstractdefaultajaxbehavior to the component you'd like to call from javascript. you then have to override the respond method of AbstractDefaultAjaxBehavior to perform your actions and to append your changes to the response e.g. in your panel final AbstractDefaultAjaxBehavior behave = new AbstractDefaultAjaxBehavior() { protected void respond(final AjaxRequestTarget target) { target.add(new Label(foo, yeah I just called this from flash!)); } }; add(behave); the method behave.getCallbackUrl(); gives you the url to call that respond method. I.e. if you paste the String returned from that method into your browser, you'll invoke the respond method, the same applies for the javascript method - Dojopackagedtexttemplate is part of the wicketstuff dojo project, don't know if you need more than that class or if it's possible without the project. we used that as part of the wicketstuff-push project ... add this to your pom: dependency groupIdorg.wicketstuff/groupId artifactIdwicketstuff-dojo/artifactId version1.3.0-SNAPSHOT/version /dependency Michael Pills wrote: Michael Sparer wrote: Generally you can get the callback-url of a wicket ajax-component with calling getCallbackUrl(), you should have a look at wicketAjaxGet which is part of wicket's JS library to make the whole stuff a bit more dynamic you could make a javascript template using wicketstuff-dojo, e.g. function callWicket() { var wcall = wicketAjaxGet('${url}' + addToUrl, function() { }, function() { }); // addToUrl are optional parameters } and then in the java-code HashMapString, String map = new HashMapString, String(); map.put(url, getCallbackUrl().toString()); // getcallbackurl is from AbstractAjaxBehavior return new DojoPackagedTextTemplate(YourClass.class, CometdDefaultBehaviorTemplate.js) .asString(map); and then add it in your responseheader (renderHead method) with response.renderJavaScript(...) this may be not the easiest method but allows the most flexibility. hope that helps Michael Hello Michael, thank you for your answer. I have two little problems with this way: - how can I get an instance of ResponseHeader from a WebPage? - I need to use an AbstractAjaxBehavior, but where do I need to add it? Simply on the page? Or on my ShockwaveComponent? Thank you ;) EDIT: And I find no class named DojoPackagedTextTemplate... is it included in a wicket's subproject? - Michael Sparer http://talk-on-tech.blogspot.com -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14693821.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
hi erik, actually the example in my first post already calls the behaviour: function callWicket() { var wcall = wicketAjaxGet('${url}' + addToUrl, function() { }, function() { }); // addToUrl are optional parameters } the addToUrl variable above may look like that 'foo=bar' - so you can get the get parameters out of the request. It actually _is_ quite ugly, but you get them like so: Map map = ((WebRequestCycle)RequestCycle.get()).getRequest().getParameterMap(); Maybe there's also an easier way but I'm not really into wicket's requestcycle ... I saw this approach (JS-template + AbstractDefaultAjaxBehavior) in the wicketstuff-push project that was done by Xavier Hanin and Vincent Demant. If you want to see it in production check it out from SVN and take a look at the org.wicketstuff.push.cometd package. There's a JS-template and the class that uses it (CometdBehavior). regards, Michael Erik van Oosten-3 wrote: Nice to see a more structured approach. Do you have a small JavaScript example that shows how to call the behavior URL? Can you also explain (or reference docs/examples) how to pass parameters from javascript to the behavior? Regards, Erik. Michael Sparer wrote: hi, - your component has to implement IHeaderContributor, that's where the response-object gets passed. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Michael Sparer http://talk-on-tech.blogspot.com -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14696846.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
Nice to see a more structured approach. Do you have a small JavaScript example that shows how to call the behavior URL? Can you also explain (or reference docs/examples) how to pass parameters from javascript to the behavior? Regards, Erik. Michael Sparer wrote: hi, - your component has to implement IHeaderContributor, that's where the response-object gets passed. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
This is an interesting and useful thread and goes over ground not too well covered elsewhere, afaics. Would it be worthwhile to get an authoritatively edited version up on the Wiki, maybe in the reference section? Regards - Cemal http://jWeekend.co.uk http://jWeekend.co.uk Pills wrote: Hello guys, I've a little question about the javascript and wicket. I need to update some models on server side using javascript (in fact, I need to update it from a flash object, and that's why I use js). But I have no idea about how to do this... I know how to call a JS function from flash, but I don't know how to update a wicket model using a javascript/ajax call. Has anybody some hint about that? Thanks you - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14700516.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
Thank you, I choosed your first and pretty solution, and it works fine. But how to get the parameters in the java code? I see nothing in the class AjaxRequestTarget that may return the parameters of the request? Michael Sparer wrote: hi, - your component has to implement IHeaderContributor, that's where the response-object gets passed - you add the abstractdefaultajaxbehavior to the component you'd like to call from javascript. you then have to override the respond method of AbstractDefaultAjaxBehavior to perform your actions and to append your changes to the response -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14700577.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript call to wicket
The parameters you defined in JS are regular HTTP GET parameters, so, as I wrote earlier, you can get them out of the request. You can do that like so: Map map = ((WebRequestCycle)RequestCycle.get()).getRequest().getParameterMap(); Maybe there's also an easier way but I'm not really into wicket's requestcycle ... Pills wrote: Thank you, I choosed your first and pretty solution, and it works fine. But how to get the parameters in the java code? I see nothing in the class AjaxRequestTarget that may return the parameters of the request? Michael Sparer wrote: hi, - your component has to implement IHeaderContributor, that's where the response-object gets passed - you add the abstractdefaultajaxbehavior to the component you'd like to call from javascript. you then have to override the respond method of AbstractDefaultAjaxBehavior to perform your actions and to append your changes to the response - Michael Sparer http://talk-on-tech.blogspot.com -- View this message in context: http://www.nabble.com/Javascript-call-to-wicket-tp14685384p14706775.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]