Hello,

I have a page with a form and an AjaxSubmitLink. onSubmit(), I need to
either render an ajax response or a plain redirect to the same page,
depending on a certain condition. I cannot get the latter case (redirect to
same page) to work correctly:

The Page is mounted like so:
mount(new HybridUrlCodingStrategy("/pages/mypage", MyPage.class));

protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
     if(condition)
     {
          target.addComponent(c);
     } else {
          setResponsePage(getPage().getClass());
          setRedirect(true);
     }
}

The problem is in the 'else' case I get redirected to: 'pages/mypage' -
without the leading slash; so the location bar URL ends up:

http://localhost:8080/pages/mypage/pages/mypage (and I get a 404).

I think this is happening because of the following in
WebRequestCodingStrategy.encode():

                boolean isAjax =
((WebRequestCycle)requestCycle).getWebRequest().isAjax();
if (url != null && !portletRequest)
{
// We've found the URL and it's mounted.

// In the case of Ajax, we don't want to prepend a relative path
// to the mounted URL. See WICKET-2312.
skipRelativePathPrefix = isAjax;
}

seems like in this case skipRelativePathPrefix  should remain false because
BookmarkablePageRequestTarget is being used.

If the above is indeed a bug, how else can I combine Ajax validation + plain
form submits?

thanks,

-nikita

Reply via email to