掲示板

Redirect to an action method through a URL with querystring params

6年前 に Ketan Solanki によって更新されました。

Redirect to an action method through a URL with querystring params

Junior Member 投稿: 63 参加年月日: 14/05/28 最新の投稿
Hi All,

We have 2 websites, old (not liferay) and new (liferay) websites. I want to redirect a few pages from Old to New website's e.g. Contact Us page along with a few query string parameters.

I am able to read query string parameters using

HttpServletRequest originalServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));
inside the render method of the portlet, but from here I can't redirect to Contact Us page because renderResponse doesn't have that method. Though I can get
HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(renderResponse);

and invoke sendRedirect of this object, it is not advisable. Also that render method is invoked multiple times so it doesn't make sense to have it here.

Other way is to invoke an action from render method but that doesn't work for the same reason that render will be invoked multiple times.

One more way is to have an aui:form on the portlet page with a submit button (which should invoke action) and have this submit button clicked automatically while page is loading!

I could get the button clicked in pure HTML way following:



    <script type="text/javascript">
        function loadTime() {
            document.getElementById("myButton").click();
        };

        function clicked() {
            alert('I am clicked');
        }
    </script>



    <input type="button" name="myButton" id="myButton" value="Click Me" onclick="clicked();">




Can someone tell me how to do this in aui context? Because we don't have body tag on aui taglib and hence onload event (aui-tld-summary).
thumbnail
6年前 に Andrew Jardine によって更新されました。

RE: Redirect to an action method through a URL with querystring params (回答)

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hi Ketan,

I'm not entirely clear on the problem you are having. I think I know what you are trying to do though, so maybe I can explain how I might try to solve it and that might help.

1. You have an existing website with a contact-us page ... let's say the url is http://www.myoldsite.com/contact-us
2. You want requests to this page to now go to http://www.mynewliferaysite.com/contact-us?name=andrew

First and foremost, you know both urls so if you can cut out the old system entirely by using a proxy routing rule to catch the http://www.myoldsite.com/contact-us and then redirect to Liferay. The rewrite should also be able to add any parameters you need, assuming you don't need to get them from the old system. If you do, then you should still be able to craft a url in the old tool that will route to the Liferay url (as shown in #2).

In Liferay now you have a Contact Us page that is created with /contact-us set as the friendly URL. On this page you add your Contact Us Portlet that you have created. Depending on your version of the portal, and how you build that portlet you will have access to the renderRequest in a java class. In there you can use the code you referenced to get the original http request and read the query string. If you need to pass those values to the view for the portlet, you can use the renderRequest.setAttribute("key", value); to place the data into the request and then access it in the JSP using the JSTL ${key} reference.

How close am I? Or did I totally misunderstand your question?
6年前 に Ketan Solanki によって更新されました。

RE: Redirect to an action method through a URL with querystring params

Junior Member 投稿: 63 参加年月日: 14/05/28 最新の投稿
Hi Andrew,

Apologies for my late reply. First of all, thanks very much for your time and response.

We had a change of requirement a little bit, rather than determining whether to redirect based on the input parameter to different pages, we merged those 2 pages and hence the redirection was removed from the requirement. So when a URL is hit, I read the parameters and act accordingly.

So in a way, my requirement was simplified.

Regards,
Ketan