I would suggest that you use AJAX instead of doing the form submit. Although the AJAX integration in T5 is still not implemented it's very easy to do using the provided prototype and json javascripts. I did this successfully for some simple events also.
Shortly, here's how i did it:

In my page i have these two javascript functions:

function handleResponse(xhrResponse) {
       var json = xhrResponse.responseText.evalJSON(true);

       //Do whatever you want with the server response
   }
   // -->

   function sendRequest() {
new Ajax.Request('${theLink}', {asynchronous:true, onSuccess:handleResponse});
   }

On the page class i have:

public String getTheLink() {
       Link l = _resources.createActionLink("myAction", false);
       return l.toURI();
   }

public StreamResponse onMyAction() {
       Collection<Casta> castas = _regiaoDao.getRegiao(regiao).getCastas();

       JSONObject jsonObject = new JSONObject();
         // Add whatever info you want to send to the client

       return new TextStreamResponse("text/xml", jsonObject.toString());
   }

And that's it. Works great. All you have to do now is call the sendRequest function from whatever javascript event you want to catch.
Hope this helps.

Britske wrote:
I have a use-case in which i need to catch a onchange of of select-component
on the server-side. The only way I know how to do that is do a javascript
onchange='this.form.submit()' and catch the onsubmit() event on the
serverside.

This works well when i don't have a submit-component in the form as well. However, when I do have a submit the onchange doesn't give a onsubmit() on the serverside anymore.
So, the onchange in the following snippet doesn't give a server side
onsubmit()-event:

<body>
<form t:type="form" t:id="form" id="form">
        <select t:type="select" t:model="countryList" t:value="country"
onchange="this.form.submit();"/>
    <input t:type="Submit" value="All results"/>
</form>
</body>

However, the following does:

<body>
<form t:type="form" t:id="form" id="form">
        <select t:type="select" t:model="countryList" t:value="country"
onchange="this.form.submit();"/>
    <!--<input t:type="Submit" value="All results"/>-->
</form>
</body>

This isn't expected behavior since both examples do work with plain html
form elements. anyone?

Geert-Jan

Reply via email to