You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Alec Swan <al...@gmail.com> on 2011/12/16 00:24:05 UTC

Update FeedbackPanel from AbstractAjaxBehavior

Hello,

I have an AbstractAjaxBehavior which is invoked by clicking on a link.
The behavior needs to write a message to FeedbackPanel upon
completion. I wasn't able to access AjaxRequestTarget from
AbstractAjaxBehavior so I switched to using
AbstractDefaultAjaxBehavior. I implemented
AbstractDefaultAjaxBehavior#respond(AjaxRequestTarget target) but now
when the user clicks on a link the browser displays raw ajax response
(shown below) instead of just updating the feedback panel.

The behavior is used as follows:

getPage().add(ajaxBehaviour);
ExternalLink ajaxLink = new ExternalLink("ajaxLink",
ajaxBehaviour.getCallbackUrl(true).toString());

Is there anything special I need to do in
AbstractDefaultAjaxBehavior#respond method?

Thanks,

Alec

<ajax-response><component id="infoFeedbackd"><div
wicket:id="infoFeedback" class="feedbackPanel"
id="infoFeedbackd"><wicket:panel>

</wicket:panel></div></component><component id="debugFeedback63"><div
wicket:id="debugFeedback" class="feedbackPanel"
id="debugFeedback63"><wicket:panel>

</wicket:panel></div></component></ajax-response>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Update FeedbackPanel from AbstractAjaxBehavior

Posted by Alec Swan <al...@gmail.com>.
I'll give it a try. Thanks!

On Thu, Dec 15, 2011 at 5:06 PM, Dan Retzlaff <dr...@gmail.com> wrote:
> Gotcha. Sorry for not answering your actual question. :)
>
> The ExternalLink navigates the browser to the given URL which is why you're
> seeing the response. AJAX behaviors are designed to be invoked from
> JavaScript. For example, AjaxEventBehavior renders Javascript into
> "onclick" attributes or whatever, which makes the request
> using wicketAjaxGet() in wicket-ajax.js.
>
> For your particular case, if you create a Link instead of ExternalLink,
> then you can use its href in your redirect. The redirect will trigger its
> onClick(), you can add feedback messages, then the whole page will be
> rendered. If you need to avoid rerendering the whole page, then I think
> you'll need to get jQuery to invoke wicketAjaxGet() instead of redirecting
> on completion.
>
> On Thu, Dec 15, 2011 at 3:46 PM, Alec Swan <al...@gmail.com> wrote:
>
>> The click on the link is intercepted and a prompt is shown using
>> jQuery. The user fills in the prompt and clicks OK which redirects to
>> the original link href. So, I need to have a stable URL that I can
>> invoke from jQuery and have the behavior execute.
>>
>> Maybe it's possible to do this with AjaxLink, but I would like to
>> understand how to use AbstractDefaultAjaxBehavior correctly.
>>
>> Thanks,
>>
>> Alec
>>
>> On Thu, Dec 15, 2011 at 4:33 PM, Dan Retzlaff <dr...@gmail.com> wrote:
>> > Is there a reason you're avoiding AjaxLink? Its onClick gives you the
>> > AjaxRequestTarget which you can use to render the feedback panel.
>> >
>> > On Thu, Dec 15, 2011 at 3:24 PM, Alec Swan <al...@gmail.com> wrote:
>> >
>> >> Hello,
>> >>
>> >> I have an AbstractAjaxBehavior which is invoked by clicking on a link.
>> >> The behavior needs to write a message to FeedbackPanel upon
>> >> completion. I wasn't able to access AjaxRequestTarget from
>> >> AbstractAjaxBehavior so I switched to using
>> >> AbstractDefaultAjaxBehavior. I implemented
>> >> AbstractDefaultAjaxBehavior#respond(AjaxRequestTarget target) but now
>> >> when the user clicks on a link the browser displays raw ajax response
>> >> (shown below) instead of just updating the feedback panel.
>> >>
>> >> The behavior is used as follows:
>> >>
>> >> getPage().add(ajaxBehaviour);
>> >> ExternalLink ajaxLink = new ExternalLink("ajaxLink",
>> >> ajaxBehaviour.getCallbackUrl(true).toString());
>> >>
>> >> Is there anything special I need to do in
>> >> AbstractDefaultAjaxBehavior#respond method?
>> >>
>> >> Thanks,
>> >>
>> >> Alec
>> >>
>> >> <ajax-response><component id="infoFeedbackd"><div
>> >> wicket:id="infoFeedback" class="feedbackPanel"
>> >> id="infoFeedbackd"><wicket:panel>
>> >>
>> >> </wicket:panel></div></component><component id="debugFeedback63"><div
>> >> wicket:id="debugFeedback" class="feedbackPanel"
>> >> id="debugFeedback63"><wicket:panel>
>> >>
>> >> </wicket:panel></div></component></ajax-response>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >>
>> >>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Update FeedbackPanel from AbstractAjaxBehavior

Posted by Dan Retzlaff <dr...@gmail.com>.
Gotcha. Sorry for not answering your actual question. :)

The ExternalLink navigates the browser to the given URL which is why you're
seeing the response. AJAX behaviors are designed to be invoked from
JavaScript. For example, AjaxEventBehavior renders Javascript into
"onclick" attributes or whatever, which makes the request
using wicketAjaxGet() in wicket-ajax.js.

For your particular case, if you create a Link instead of ExternalLink,
then you can use its href in your redirect. The redirect will trigger its
onClick(), you can add feedback messages, then the whole page will be
rendered. If you need to avoid rerendering the whole page, then I think
you'll need to get jQuery to invoke wicketAjaxGet() instead of redirecting
on completion.

On Thu, Dec 15, 2011 at 3:46 PM, Alec Swan <al...@gmail.com> wrote:

> The click on the link is intercepted and a prompt is shown using
> jQuery. The user fills in the prompt and clicks OK which redirects to
> the original link href. So, I need to have a stable URL that I can
> invoke from jQuery and have the behavior execute.
>
> Maybe it's possible to do this with AjaxLink, but I would like to
> understand how to use AbstractDefaultAjaxBehavior correctly.
>
> Thanks,
>
> Alec
>
> On Thu, Dec 15, 2011 at 4:33 PM, Dan Retzlaff <dr...@gmail.com> wrote:
> > Is there a reason you're avoiding AjaxLink? Its onClick gives you the
> > AjaxRequestTarget which you can use to render the feedback panel.
> >
> > On Thu, Dec 15, 2011 at 3:24 PM, Alec Swan <al...@gmail.com> wrote:
> >
> >> Hello,
> >>
> >> I have an AbstractAjaxBehavior which is invoked by clicking on a link.
> >> The behavior needs to write a message to FeedbackPanel upon
> >> completion. I wasn't able to access AjaxRequestTarget from
> >> AbstractAjaxBehavior so I switched to using
> >> AbstractDefaultAjaxBehavior. I implemented
> >> AbstractDefaultAjaxBehavior#respond(AjaxRequestTarget target) but now
> >> when the user clicks on a link the browser displays raw ajax response
> >> (shown below) instead of just updating the feedback panel.
> >>
> >> The behavior is used as follows:
> >>
> >> getPage().add(ajaxBehaviour);
> >> ExternalLink ajaxLink = new ExternalLink("ajaxLink",
> >> ajaxBehaviour.getCallbackUrl(true).toString());
> >>
> >> Is there anything special I need to do in
> >> AbstractDefaultAjaxBehavior#respond method?
> >>
> >> Thanks,
> >>
> >> Alec
> >>
> >> <ajax-response><component id="infoFeedbackd"><div
> >> wicket:id="infoFeedback" class="feedbackPanel"
> >> id="infoFeedbackd"><wicket:panel>
> >>
> >> </wicket:panel></div></component><component id="debugFeedback63"><div
> >> wicket:id="debugFeedback" class="feedbackPanel"
> >> id="debugFeedback63"><wicket:panel>
> >>
> >> </wicket:panel></div></component></ajax-response>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Update FeedbackPanel from AbstractAjaxBehavior

Posted by Alec Swan <al...@gmail.com>.
The click on the link is intercepted and a prompt is shown using
jQuery. The user fills in the prompt and clicks OK which redirects to
the original link href. So, I need to have a stable URL that I can
invoke from jQuery and have the behavior execute.

Maybe it's possible to do this with AjaxLink, but I would like to
understand how to use AbstractDefaultAjaxBehavior correctly.

Thanks,

Alec

On Thu, Dec 15, 2011 at 4:33 PM, Dan Retzlaff <dr...@gmail.com> wrote:
> Is there a reason you're avoiding AjaxLink? Its onClick gives you the
> AjaxRequestTarget which you can use to render the feedback panel.
>
> On Thu, Dec 15, 2011 at 3:24 PM, Alec Swan <al...@gmail.com> wrote:
>
>> Hello,
>>
>> I have an AbstractAjaxBehavior which is invoked by clicking on a link.
>> The behavior needs to write a message to FeedbackPanel upon
>> completion. I wasn't able to access AjaxRequestTarget from
>> AbstractAjaxBehavior so I switched to using
>> AbstractDefaultAjaxBehavior. I implemented
>> AbstractDefaultAjaxBehavior#respond(AjaxRequestTarget target) but now
>> when the user clicks on a link the browser displays raw ajax response
>> (shown below) instead of just updating the feedback panel.
>>
>> The behavior is used as follows:
>>
>> getPage().add(ajaxBehaviour);
>> ExternalLink ajaxLink = new ExternalLink("ajaxLink",
>> ajaxBehaviour.getCallbackUrl(true).toString());
>>
>> Is there anything special I need to do in
>> AbstractDefaultAjaxBehavior#respond method?
>>
>> Thanks,
>>
>> Alec
>>
>> <ajax-response><component id="infoFeedbackd"><div
>> wicket:id="infoFeedback" class="feedbackPanel"
>> id="infoFeedbackd"><wicket:panel>
>>
>> </wicket:panel></div></component><component id="debugFeedback63"><div
>> wicket:id="debugFeedback" class="feedbackPanel"
>> id="debugFeedback63"><wicket:panel>
>>
>> </wicket:panel></div></component></ajax-response>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Update FeedbackPanel from AbstractAjaxBehavior

Posted by Dan Retzlaff <dr...@gmail.com>.
Is there a reason you're avoiding AjaxLink? Its onClick gives you the
AjaxRequestTarget which you can use to render the feedback panel.

On Thu, Dec 15, 2011 at 3:24 PM, Alec Swan <al...@gmail.com> wrote:

> Hello,
>
> I have an AbstractAjaxBehavior which is invoked by clicking on a link.
> The behavior needs to write a message to FeedbackPanel upon
> completion. I wasn't able to access AjaxRequestTarget from
> AbstractAjaxBehavior so I switched to using
> AbstractDefaultAjaxBehavior. I implemented
> AbstractDefaultAjaxBehavior#respond(AjaxRequestTarget target) but now
> when the user clicks on a link the browser displays raw ajax response
> (shown below) instead of just updating the feedback panel.
>
> The behavior is used as follows:
>
> getPage().add(ajaxBehaviour);
> ExternalLink ajaxLink = new ExternalLink("ajaxLink",
> ajaxBehaviour.getCallbackUrl(true).toString());
>
> Is there anything special I need to do in
> AbstractDefaultAjaxBehavior#respond method?
>
> Thanks,
>
> Alec
>
> <ajax-response><component id="infoFeedbackd"><div
> wicket:id="infoFeedback" class="feedbackPanel"
> id="infoFeedbackd"><wicket:panel>
>
> </wicket:panel></div></component><component id="debugFeedback63"><div
> wicket:id="debugFeedback" class="feedbackPanel"
> id="debugFeedback63"><wicket:panel>
>
> </wicket:panel></div></component></ajax-response>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>