Gonzalo,

You want to use AbstractDefaultAjaxBehavior as context to serve some JSON?
Then what you do is

add(behavior = new AbstractDefaultAjaxBehavior() {
 @Override
protected void respond(AjaxRequestTarget target) {
TextRequestHandler handler = new TextRequestHandler(...);
RequestCycle.get().scheduleRequestHandlerAfterCurrent(handler);
}
});

then use use behavior.getCallbackUrl() to generate the URL you need to use
on client side to retrieve that JSON.


On Sat, Oct 20, 2012 at 5:57 PM, Gonzalo Aguilar Delgado <
gagui...@aguilardelgado.com> wrote:

> Hello again,
>
> Sorry. I was thinking about extending AbstractAjaxBehavior directly. It
> seems to have cleaner code but I loss some functionality.
>
> Could it be right?
>
>
> And doing like you said. The getRequestHandler(); returns your
> TextRequestHandler. Do I need the stuff inside
> AbstractDefaultAjaxBehavior?
>
> Functions like updateAjaxAttributes, renderAjaxAttributes,
> appendListenerHandler, getCallbackFunction and so on, does not seem
> useful for me now.
>
>
>         public final void onRequest()
>         {
> //              WebApplication app =
> (WebApplication)getComponent().getApplication();
> //              AjaxRequestTarget target =
> app.newAjaxRequestTarget(getComponent().getPage());
> //
> //              RequestCycle requestCycle = RequestCycle.get();
> //              requestCycle.scheduleRequestHandlerAfterCurrent(target);
> //
> //              respond(target);
>
>                 IRequestHandler handler = getRequestHandler();
>
>                 if(handler!=null)
>
> RequestCycle.get().scheduleRequestHandlerAfterCurrent(handler);
>         }
>
>
> El sáb, 20-10-2012 a las 16:08 +0200, Ernesto Reinaldo Barreiro
> escribió:
>
> > on the respond method of your AbstractDefaultAjaxBehavior
> >
> > On Sat, Oct 20, 2012 at 4:07 PM, Ernesto Reinaldo Barreiro <
> > reier...@gmail.com> wrote:
> >
> > > Try the following
> > >
> > > TextRequestHandler textRequestHandler = new
> > > TextRequestHandler("application/json", "UTF-8", "Your JSON HERE");
> > >
> RequestCycle.get().scheduleRequestHandlerAfterCurrent(textRequestHandler);
> > >
> > > On Sat, Oct 20, 2012 at 4:00 PM, Gonzalo Aguilar Delgado <
> > > gagui...@aguilardelgado.com> wrote:
> > >
> > >> Hello,
> > >>
> > >> I was looking to some code and googling around but cannot find a
> > >> suitable solution for my problem.
> > >>
> > >>
> > >> I have an AbstractDefaultAjaxBehavior that I'm implemented the
> function
> > >> respond(AjaxRequestTarget target) like this
> > >>
> > >> ---
> > >>         @Override
> > >>         protected void respond(AjaxRequestTarget target) {
> > >>
> > >>
> > >>
> > >>                 JsonChoiceRenderer<T> jsonRenderer = new
> > >> JsonChoiceRenderer<T>(getChoices());
> > >>
> > >> target.appendJavaScript(jsonRenderer.renderJsonArray(getComponent(),
> > >> getRenderer()));
> > >>
> > >>         }
> > >>
> > >> ---
> > >>
> > >> But this is not a JSON response when it is called from javascript. I
> > >> want to respond with an application/json response.
> > >>
> > >> I saw something like:
> > >>
> > >>   RequestCycle requestCycle = RequestCycle.get();
> > >>   requestCycle.getResponse().setCharacterEncoding("UTF-8");
> > >>
> requestCycle.getResponse().setContentType("application/json;");
> > >>
> > >> But it means that I have to override the final void onRequest() of the
> > >> AbstractAjaxBehavior class, but this is final so I cannot.
> > >>
> > >>
> > >> What's the best way to do it with newer versions of wicket?
> > >>
> > >>
> > >> Thank you a lot in advance.
> > >>
> > >
> > >
> > >
> > > --
> > > Regards - Ernesto Reinaldo Barreiro
> > > Antilia Soft
> > > http://antiliasoft.com
> > >
> > >
> >
> >
>



-- 
Regards - Ernesto Reinaldo Barreiro
Antilia Soft
http://antiliasoft.com

Reply via email to