Hi, On Sun, Oct 21, 2012 at 11:54 AM, Ernesto Reinaldo Barreiro <reier...@gmail.com> wrote: > Hi, > > On Sun, Oct 21, 2012 at 10:57 AM, Gonzalo Aguilar Delgado < > gagui...@aguilardelgado.com> wrote: > >> Hello Ernesto, >> >> I sometimes get confused myself. ;-) I think that I don't understand >> well this piece of code: >> >> @Override >> public final void onRequest() >> { >> WebApplication app = >> (WebApplication)getComponent().getApplication(); >> AjaxRequestTarget target = >> app.newAjaxRequestTarget(getComponent().getPage()); >> >> RequestCycle requestCycle = RequestCycle.get(); >> requestCycle.scheduleRequestHandlerAfterCurrent(target); >> >> respond(target); >> } >> >> >
> AJAX requests are handled int two steps (please Martin and/or other core > developers correct me if I'm saying something wrong;-). First is is Actually everything is in two steps, not only Ajax. The first step is the ACTION phase and the second is the RENDER phase. > executed ListenerInterfaceRequestHandler (which delegates > on IBehaviorListener#onRequest). So, there you a new request handler is > scheduled after current, so once wicket finishes processing current request > handler it will start processing the new scheduled request handler (that > will produce the AJAX output). This technique is used in many places on the > framework, Eg. DownloadLink#click() > > public void onClick() > { > final File file = getModelObject(); > if (file == null) > { > throw new IllegalStateException(getClass().getName() + > " failed to retrieve a File object from model"); > } > > String fileName = fileNameModel != null ? fileNameModel.getObject() : null; > if (Strings.isEmpty(fileName)) > { > fileName = file.getName(); > } > > fileName = UrlEncoder.QUERY_INSTANCE.encode(fileName, > getRequest().getCharset()); > > IResourceStream resourceStream = new FileResourceStream( > new org.apache.wicket.util.file.File(file)); > getRequestCycle().scheduleRequestHandlerAfterCurrent( > new ResourceStreamRequestHandler(resourceStream) > { > @Override > public void respond(IRequestCycle requestCycle) > { > super.respond(requestCycle); > > if (deleteAfter) > { > Files.remove(file); > } > } > }.setFileName(fileName) > .setContentDisposition(ContentDisposition.ATTACHMENT) > .setCacheDuration(cacheDuration)); > } > > > >> Because the AjaxRequestTarget is really a handler like >> TextRequestHandler but I don't know the >> call machanism. >> > > Look at the code RequestCycle#processRequestAndDetach.... and the calls it > makes. > >> >> What does the requestCycle.scheduleRequestHandlerAfterCurrent(target); >> here and when used >> with a TextRequestHandler. What's the difference? >> > > There is no difference, you tell wicket that after current handler it > should "discard" the results and execute next handler. In your case instead > of returning an AJAX response return some text (JSON) response. > > >> Is there any way where this mechanism is explained? >> >> > I don't know if Martin or other core developers explain this somewhere? > RequestCycle's javadoc contains a bit but it can definitely be extended. Another docu that can explain this is https://cwiki.apache.org/confluence/display/WICKET/RequestCycle+in+Wicket+1.5. I'll try to extend both soon. > >> Thank you a lot! >> >> > You are welcome:-) > > -- > Regards - Ernesto Reinaldo Barreiro > Antilia Soft > http://antiliasoft.com -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org