Fórumok

sendRedirects not working

thumbnail
Dave Weitzel, módosítva 11 év-val korábban

sendRedirects not working

Regular Member Bejegyzések: 208 Csatlakozás dátuma: 2009.11.18. Legújabb bejegyzések
I am trying to "hand off" the user from m y own portlet to the shopping cart so that they can pay for an item my portlet has put into their cart in the background.

I am trying to do this by using actionResponse.sendRedirect(redirectURL)

However even though I am creating a valid url by:
a) detect edfault PLid:
LayoutLocalServiceUtil.getDefaultPlid(groupId, false , "34");

b) create PortletURL:
LiferayPortletURL lcartURL = PortletURLFactoryUtil.create(actionRequest, shoppingPid , defPlid, "0");

c) adding some properties:
String addProps= "&_34_struts_action=/shopping/cart&p_p_state=maximized";

d) combining
String redirectURL= lcartURL.toString() + addProps;

e) send the redirect
actionResponse.sendRedirect(redirectURL);

It will not redirect there and just returns to the final page of my portlet.
I can trace the url and cut and paste it in to that users window and it displays fine so the URL is OK but for some reason not visible in eclipse console the redirect isnot working?

Any advice?
thumbnail
David H Nebinger, módosítva 11 év-val korábban

RE: sendRedirects not working

Liferay Legend Bejegyzések: 14915 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
For item (c), shouldn't you be using lcartURL.setParameter() to set the parameters rather than manually appending them on the end?
thumbnail
Dave Weitzel, módosítva 11 év-val korábban

RE: sendRedirects not working

Regular Member Bejegyzések: 208 Csatlakozás dátuma: 2009.11.18. Legújabb bejegyzések
Thanks David but it doesn't affect the behavior at all (I tried that approach first!)

I have found the answer though. In the original request we have a redirect parameter (as sees to be standard practice).

If that exists it seems that actionResponse.sendRedirect(redirectURL); will not go to the redirectURl you specify but will go to the redirect parameter in the request,

I have renamed my parameter redirectFail (as that is what it really was for) and everything started working like magic.

Not got time to try other variants of this workaround.