yeah indeed it is only called once when the template is rendered, I
discovered now. 
However i don't need to return a dynamic url or whatever based on the
getTheLink-method. 

what I need is a way to reliably catch a event at the server/java side (in
this case onChange) every time that event occurs. I don't want to submit my
form when that happens (otherwise I could use the method you suggested) but
I want to update some information on the current page and stay there. 

This means that i have to redirect to my currentpage with a couple of
queryparameters in the url which depend on the selected fields in the form. 

hmm, the more i think about it, I don't think i really need to catch the
event server-side. I just redirect to the current page on onChange using
javascript:window.location=... and parse the querystrings correctly in it. 

hope this makes sense, 
thanks!
Geert-Jan



HugoPalma wrote:
> 
> That's the way it's supposed to be.
> You only see the getTheLink method executed once because that what it 
> need to replace ${theLink} in your template with the correct link that 
> is returned from your method. This is done once when the page renders. 
> If you look at the rendered page source you won't see ${theLink} there, 
> instead you will the the generated link to your listener.
> 
> Anyway, does it really matter how many times the getTheLink method is 
> invoked ? I think not.  What really matters is that the listener method 
> to which your getTheLink method should be returning the URL to is called 
> whenever you call the "sendRequest" function.
> 
> 
> Britske wrote:
>> thanks that works partially. 
>>
>> However, the event is only catched twice: 
>> 1. on pageload (??m the sendRequest isn't called, but somehow the
>> getTheLink()-method is executed.)
>> 2. the first time i send a onchange. 
>>
>> However after the first onchange all other onchange-event don't get
>> getTheLink() executed, although sendRequest() is called on the
>> client-side
>> each time. 
>>
>> This is my relevant code: 
>>
>> in  html: 
>> <script>
>> function sendRequest() 
>>     {
>>      alert("sendRequest reached");
>>      new Ajax.Request('${theLink}',
>> {asynchronous:true,onSuccess:handleResponse});
>>     } 
>> </script>
>> ...
>> <select t:type="select" t:model="themaList" t:value="thema"
>> onchange="sendRequest()" name="thema" id="thema" tabindex="4" 
>> class="formElement"/>
>>
>> in the page-class: 
>>      public String getTheLink() 
>>      {
>>              System.out.println("catched!!");
>>              return "catched!";
>>      } 
>>
>> Do you 've got any idea what causes this behavior? 
>>
>> Thanks,
>> Geert-Jan
>>
>>
>>
>>
>> HugoPalma wrote:
>>   
>>> 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
>>>>   
>>>>       
>>>     
>>
>>   
> 
> 

-- 
View this message in context: 
http://www.nabble.com/t5-form-submit-not-fired-tf4645307.html#a13271792
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to