简体   繁体   中英

Redirect to another portlet in action method Liferay

I have some issue. I will, when I click to the button search, to redirect to another portlet and save some data in the same action. Now, when I click the button search, it will execute the actions method searchEntry in Java code. Can I redirect to another portlet in this actions method search in java? How I can do that? Or some another Idee for resolve this problem? I post a part of the jsp and java code where is actions method searchEntry.

JSP:

<portlet:actionURL name="searchEntry" var="customerURL"></portlet:actionURL>

<aui:form action="<%= customerURL %>" name="
    <portlet:namespace />fm">
    <aui:fieldset>
        <aui:input label="Customer ID" name="customerid"></aui:input>
    </aui:fieldset>
    <aui:button-row>
        <aui:button type="submit" onClick="<%= customerURL.toString() %>" value="Search">
        </aui:button>
    </aui:button-row>
</aui:form>

JAVA:

public void searchEntry(ActionRequest request, ActionResponse response) {
    int index = dataCustomerID.indexOf(ParamUtil.getString(request, "customerid"));
    System.out.println("You are now in method searchEntry " + index);
}

是的,您可以通过使用PortletURLFactoryUtil.create()并调用response.sendRedirect()为该Portlet创建URL来实现。

Redirection is done to the page where your desired portlet is dropped, not to the portlet iteself. Like, we do in most of the web application environment.

So, if you can remember (hard-code) the page, where you have dropped your portlet, you can simply do as following:

public void searchEntry(ActionRequest request, ActionResponse response) {
    int index = dataCustomerID.indexOf(ParamUtil.getString(request, "customerid"));
    System.out.println("You are now in method searchEntry " + index);

    /* perform operation with your data */

    response.sendRedirect("/html/customerpage");
}

However, if you want to bind certain parameter(s) responsible for the rendering of the portlet dropped on other page, you need to create URL dynamically using PortletURLFactoryUtil.create as following:

public void searchEntry(ActionRequest request, ActionResponse response) {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    int index = dataCustomerID.indexOf(ParamUtil.getString(request, "customerid"));
    System.out.println("You are now in method searchEntry " + index);

    /* perform operation with your data */

    long groupId = themeDisplay.getScopeGroupId();
    String portletId = "customerpage_WAR_customerpageportlet";
    long plid = PortalUtil.getPlidFromPortletId(groupId, portletId);

    LiferayPortletURL renderURL = PortletURLFactoryUtil.create(request,
        portletId, plid, PortletRequest.RENDER_PHASE); 
    renderURL.setParameter("show.jsp", "/html/customerpage/show.jsp"); 

    response.sendRedirect(renderURL.toString());
}

The tricky part from the above code is to get plid . There are other method available in PortalUtil , which can be used for the same purpose depending on the requirement and data you have.

The other way to get plid is to use getFriendlyURLLayout(long groupId, boolean privateLayout, String friendlyURL) of LayoutLocalServiceUtil when you want to get plid based on the friendlyURL and you are sure about the private / public layout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM