The whole point of AJAX is not having to return the whole page. You just
want to return the part of the page that needs updating. If selecting a
field in a drop down is supposed to add a dependant drop down (choose a
country changes possible address fields for instance), then you only return
enough information for that field to be updated and use Javascript to
populate the field.

Your stream response can be XML, JSON, or HTML depending on what your needs
are...

Josh


On 10/18/07, Britske <[EMAIL PROTECTED]> wrote:
>
>
> A changes your method somehwat to return void --> redirect to current page
> (Thanks Nick for mentioning the difference)
>
> Could you eleborate what exactly you stream to the client in the
> StreamReponse you give back?
> This must be the entire page right? You can't just stream changes back to
> the client at least to my knowledge.
>
> I'm curious if in your opinion streaming the response gives a noticable
> performance difference than doing a redirect to the same page.
> //Geert-Jan
>
>
> HugoPalma wrote:
> >
> > If your getting a page redirect then your doing something wrong in your
> > code.
> > If you post it i can try and find the problem.
> >
> > Britske wrote:
> >> after the onchange occurs, this is what happens in my app:
> >>
> >> 1. onMyAction is executed()  (this is an actionlink which returns
> nothing
> >> (void) which results in a client-side redirect to the same page
> >> (as per documentation:
> >> http://tapestry.apache.org/tapestry5/tapestry-core/guide/pagenav.html )
> >>
> >> 2. onActivate() is executed on the server, which I think proofs that
> >> there
> >> was indeed a redirect.
> >>
> >> please don't get me wrong, I still think it's an elegant solution...
> >>
> >> //Geert-Jan
> >>
> >>
> >> HugoPalma wrote:
> >>
> >>> Why do you say a redirect happens ? Does your page refresh when you
> >>> change the selectbox value ?
> >>> It won't refresh because all your doing is call a javascript function.
> >>> There's no redirect.
> >>>
> >>> Britske wrote:
> >>>
> >>>> since your example effectively calls a ActionLink through AJAX, a
> >>>> redirect
> >>>> DOES happen. It's the result of the ActionLink. If I'm seeing this
> >>>> correctly
> >>>> what then is the advantage of doing a call through AJAX or a
> >>>> form.submit()
> >>>> for the discussed purpose, since both result in a redirect?
> >>>>
> >>>> //Geert-Jan
> >>>>
> >>>>
> >>>>
> >>>> HugoPalma wrote:
> >>>>
> >>>>
> >>>>> The method i suggested is implemented so that you don't have to
> submit
> >>>>> the form. That's what AJAX is all about, you make a request to the
> >>>>> server and then update a portion of your page based on the response
> >>>>> from
> >>>>> the server using javascript. There's no page reload of for
> submission.
> >>>>>
> >>>>> Britske wrote:
> >>>>>
> >>>>>
> >>>>>> 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#a13289207
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

Reply via email to