So although clearly AJAX is supposed to be mostly asynchronous. it looks 
like the underlying XMLHttpRequest object _can_ be synchronous.

If I modify wicket-ajax.js and set 'Wicket.Ajax.Request.async' to 
*false* -- suddenly my code works... i.e. I can code an 
AjaxFormSubmitBehavor.onSubmit so it takes a value from one 
FormComponent (the argument to the function), modifies it (in this case 
toUppercase), and sends it back to another FormComponent, whose node I 
can grab from the DOM tree and return inside my function.

So I guess my question is -- am I going to break something fundamental 
by doing this? It seem to work fine in my test case.

<Javascript_function>

<script type="text/javascript" id="onTestMethod1"><!--/*--><![CDATA[/*><!--*/
TestMethod1 = function () { 
var wcall=wicketSubmitFormById('form', 
'/portal/tool/52480496-d4f6-4278-0002-e65fdefcc0ef/?wicket:interface=wicket-247:0:form:-1:IUnversionedBehaviorListener&wicket:behaviorId=0&wicket:ignoreIfNotActive=true',
 null, function() { }, function() { }); 
return document.getElementById('form_result').value;;};
/*-->]]>*/</script>

</Javascript_function>

<AjaxFormSubmitBehavior.onSubmit>
            @Override
            protected void onSubmit(AjaxRequestTarget target) {
                FormComponent c = (FormComponent)form.get("argument");
                String testValue = (String)c.getConvertedInput();
            
                FormComponent r = (FormComponent)form.get("result");
                bean.setResult(testValue.toUpperCase());
                target.addComponent(r);
            }
</AjaxFormSubmitBehavior.onSubmit>

<wicket-ajax.js>
Wicket.Ajax.Request.prototype = {
    initialize: function(url, loadedCallback, parseResponse, randomURL, 
failureHandler, channel) {
        this.url = url;
        this.loadedCallback = loadedCallback;
        this.parseResponse = parseResponse != null ? parseResponse : true;
        this.randomURL = randomURL != null ? randomURL : true;
        this.failureHandler = failureHandler != null ? failureHandler : 
function() { };
        this.async = *true;*
        this.channel = channel;
        this.suppressDone = false;
        this.instance = Math.random();
        this.debugContent = true;
    },
</wicket-ajax.js>

Thanks,
James


Igor Vaynberg wrote:
> the short answer is: you cant do that. javascript is asynchronous, so 
> the request will start _and_ your function will continue running. 
> usually what is done is that you create a request object, and then 
> register success and failure handlers that are executed after the 
> request is done.
>
> you can do that using iajaxcalldecorator, or what you tried...calling 
> ajaxtarget.appendjavascript() should work as well.
>
> if you show us some more code/try to describe your actual usecase we 
> can probably help you more, right now its all very abstract.
>
> -igor
>
>
> On 5/3/07, *James Renfro* <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
>     Hi,
>     I'd like to do something slightly unusual and wrap the
>     wicketSubmitFormById call in another javascript function -- I'm
>     able to
>     do this with no problem by overriding
>     AjaxFormSubmitBehavor.onRenderHeadInitContribution and calling
>     JavascriptUtils.writeJavascript on a wrapped getEventHandler. I
>     can stop
>     the normal attribute for 'onclick' or whatever from appearing
>     inside the
>     component tag by overriding onComponentTag. And by using text input
>     boxes, I can pass 'arguments' to my method on the server inside using
>     FormComponent.getConvertedInput. So far so good.
>
>     The problem I have is that I'd like to actually 'return' a value back
>     from the server in that Javascript function... so my function ends up
>     looking just like a normal function call inside of my Javascript and
>     returns the value that the server provides.
>
>     I can see inside of wicket-ajax.js that there are three special tags:
>     "component", "evaluate" and "header-contribution", each with their
>     appropriate purpose -- I tried messing around with
>     AjaxRequestTarget.prependJavascript so I could pass something through
>     the 'evaluate' tag, but my javascript isn't sufficient to the
>     task. Then
>     I tried using AjaxRequestTarget.addComponent to modify another
>     TextField
>     and return the value through the DOM tree -- that works fine
>     except for
>     the fact that the order is wrong, so my method returns _before_ the
>     component is updated.
>
>     Then I noticed this interesting Wicket.Ajax.invokePostCallHandlers()
>     call, which makes me wonder if there is already some nice clean
>     mechanism in place for updating javascript variables thru wicket's
>     java
>     code.
>
>     Apologies if this all makes no sense, but any advice or suggestions
>     would be much appreciated. The basic requirement is just that I
>     make a
>     call in Javascript and get data back from the server as a 'returned'
>     variable on the client.
>
>     Thanks,
>     James
>
>     --
>     James Renfro
>     Programmer
>     IET Mediaworks, UC Davis
>     [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>     W: 530-754-5097
>
>
>     -------------------------------------------------------------------------
>     This SF.net email is sponsored by DB2 Express
>     Download DB2 Express C - the FREE version of DB2 express and take
>     control of your XML. No limits. Just data. Click to get it now.
>     http://sourceforge.net/powerbar/db2/
>     _______________________________________________
>     Wicket-user mailing list
>     Wicket-user@lists.sourceforge.net
>     <mailto:Wicket-user@lists.sourceforge.net>
>     https://lists.sourceforge.net/lists/listinfo/wicket-user
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> ------------------------------------------------------------------------
>
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>   

-- 
James Renfro
Programmer
IET Mediaworks, UC Davis
[EMAIL PROTECTED]
W: 530-754-5097


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to