Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Michael Bravo
Passing actionRequest params using actionResponse.sendRedirect
May 15, 2012 5:14 AM
Answer

Michael Bravo

Rank: New Member

Posts: 20

Join Date: April 26, 2012

Recent Posts

We are using a third party payment processing vendor that requires the form data be posted from a static html form.

I've created a portlet action, using MVCPortlet, where we pull data from the form, persist it using liferay services, and then TRY to forward processing to a static JSP that redirects with a javascript event sending the form data that we collected in the MVC action.

When using actionResponse.sendRedirect, I CAN"T seem to get the request parameters to pass when using:

actionRequest.setAttribute("chargetotal", chargeTotal);
actionResponse.sendRedirect(redirectJSP);

(this is the method by which we would ahve to do it in order to make the refferring page a static URL and not the dynamic URL that liferay generates using the setRenderParameter...


I can get them to pass using:

actionRequest.setAttribute("chargetotal", chargeTotal);
actionResponse.setRenderParameter("jspPage", redirectJSP);

The question is. Is there a way to pass the actionRequest using the actionResponse.sendRedirect(redirectJSP); by setting some configuration or something. OR is there a way to use actionResponse.setRenderParameter("jspPage", redirectJSP); so that the URL is a static url and not the dynamically generated one?

Thanks in advance.
~Michael Bravo
Amit Doshi
RE: Passing actionRequest params using actionResponse.sendRedirect
May 15, 2012 7:35 AM
Answer

Amit Doshi

Rank: Liferay Master

Posts: 549

Join Date: December 29, 2010

Recent Posts

Hi Bravo,

There are so many ways you can pass the parameter. Below are some of them.

1) Using Session.

1
2
3actionRequest.getPortletSession().setAttribute("chargetotal", chargetotal);


2) In Request itself as you required. Please check below code for the same.

1
2String redirectJSP= "/sample.jsp"
3        redirectJSP += "&chargetotal="+chargetotal;


Hope it helps.

Thanks & Regards,
Amit Doshi
Michael Bravo
RE: Passing actionRequest params using actionResponse.sendRedirect
May 15, 2012 7:41 AM
Answer

Michael Bravo

Rank: New Member

Posts: 20

Join Date: April 26, 2012

Recent Posts

Amit,

Thanks for the response! I'll give it a try.

Mike B.
Michael Bravo
RE: Passing actionRequest params using actionResponse.sendRedirect
May 15, 2012 8:15 AM
Answer

Michael Bravo

Rank: New Member

Posts: 20

Join Date: April 26, 2012

Recent Posts

Hi Amit,

Sorry to bother again. The first solution would be ideal for our project. After redirecting, I get a bean not in scope. I am using session as you mentioned, then do a sendRedirect, like this:

// setting value from the form action in a bean called ChargeTotal
ChargeTotal chargeTotal = new ChargeTotal();
chargeTotal.setTotal(actionRequest.getParameter("chargetotal"));

// setting the attribute in session
actionRequest.getPortletSession().setAttribute("chargeTotal", chargeTotal);

// sending redirect to the redirect JSP
actionResponse.sendRedirect(actionRequest.getContextPath()+redirectJSP);



In the JSP i am trying to read the bean like this:

<jsp:useBean id="chargeTotal" type="com.emory.law.registration.ChargeTotal" scope="session" />

Tomcat throws this error: (Partial Stack Trace)

java.lang.InstantiationException: bean chargeTotal not found within scope
org.apache.jsp.html.registration.redirect_jsp._jspService(redirect_jsp.java:139)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
sun.reflect.GeneratedMethodAccessor382.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:54)
$Proxy397.doFilter(Unknown Source)

~Mike
Amit Doshi
RE: Passing actionRequest params using actionResponse.sendRedirect
May 16, 2012 5:44 AM
Answer

Amit Doshi

Rank: Liferay Master

Posts: 549

Join Date: December 29, 2010

Recent Posts

Hi,

I tried the below code and it is working fine in jsp page.

1<% ChargeTotal chargeTotal=(ChargeTotal) renderRequest.getPortletSession().getAttribute("chargeTotal");
2if(chargeTotal != null)
3{
4    System.out.println(chargeTotal.getChargeTotal());
5}
6
7%>


Please check and let me know.

Thanks & Regards,
Amit Doshi
Michael Bravo
RE: Passing actionRequest params using actionResponse.sendRedirect
May 16, 2012 7:21 AM
Answer

Michael Bravo

Rank: New Member

Posts: 20

Join Date: April 26, 2012

Recent Posts

Amit,

Thanks again .. Unfortunately, I am still getting an error. It looks that after i do a redirect via:

actionRequest.getPortletSession().setAttribute("chargeTotal", chargeTotal);

actionResponse.sendRedirect(actionRequest.getContextPath()+redirectJSP);

.. I get a null pointer on the renderRequest object. Somehow I am losing the params when i do a straight actionResponse.sendRedirect.

When I use the actionResponse.setRenderParameter("jspPage","/thejsppage.jsp") .. i get the parameters. theissue with this is that the url is a dynamic url that we can't use when calling the payment vendor we are using. that's why i am trying to just redirect to the static jsp.

i'm wondering if there is a way to access the HttpServletRequest objects and set these .. I'm thinking that might help, but not sure ..

Again, thanks for the help. I am still pluggin away to find a solution! =)

Regards,
~Mike
Amit Doshi
RE: Passing actionRequest params using actionResponse.sendRedirect
May 17, 2012 12:28 AM
Answer

Amit Doshi

Rank: Liferay Master

Posts: 549

Join Date: December 29, 2010

Recent Posts

Please use below code. It will help you to redirect to the Static page as you are aspecting.

For resonse.sendRedirect you should make one url by following code..

Code ::

 1String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);
 2
 3ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
 4
 5PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),
 6portletName,
 7themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);
 8
 9redirectURL.setParameter("jspPage", "your jsp path");
10
11actionResponse.sendRedirect(redirectURL.toString());


Hope it helps.

Thanks & Regards,
Amit Doshi
Michael Bravo
RE: Passing actionRequest params using actionResponse.sendRedirect
May 17, 2012 5:46 AM
Answer

Michael Bravo

Rank: New Member

Posts: 20

Join Date: April 26, 2012

Recent Posts

Thanks Amit. I will give it a shot .. I appreciate all the help! ~Mike
Michael Bravo
RE: Passing actionRequest params using actionResponse.sendRedirect
May 17, 2012 6:38 AM
Answer

Michael Bravo

Rank: New Member

Posts: 20

Join Date: April 26, 2012

Recent Posts

Amit ..

Awesome! That did it!! You're the man .. Thanks a million!.. emoticon
Abdulbasit Shaikh
RE: Passing actionRequest params using actionResponse.sendRedirect
February 3, 2015 11:55 PM
Answer

Abdulbasit Shaikh

Rank: New Member

Posts: 18

Join Date: May 16, 2013

Recent Posts

Thanks Amit. It really worked.

Thanks and Regards,
Abdulbasit F Shaikh.