Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Dave Weitzel
sendRedirects not working
April 11, 2013 11:59 AM
Answer

Dave Weitzel

Rank: Regular Member

Posts: 204

Join Date: November 18, 2009

Recent Posts

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?
David H Nebinger
RE: sendRedirects not working
April 11, 2013 1:15 PM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11779

Join Date: September 1, 2006

Recent Posts

For item (c), shouldn't you be using lcartURL.setParameter() to set the parameters rather than manually appending them on the end?
Dave Weitzel
RE: sendRedirects not working
April 16, 2013 12:17 PM
Answer

Dave Weitzel

Rank: Regular Member

Posts: 204

Join Date: November 18, 2009

Recent Posts

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.