繁体   English   中英

在操作方法Liferay中重定向到另一个portlet

[英]Redirect to another portlet in action method Liferay

我有问题 当我单击按钮搜索时,我将重定向到另一个portlet,并在同一操作中保存一些数据。 现在,当我单击按钮搜索时,它将以Java代码执行动作方法searchEntry。 我可以在Java中的此操作方法搜索中重定向到另一个portlet吗? 我该怎么做? 或一些其他想法解决此问题? 我张贴了一部分jsp和Java代码,其中的动作方法是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来实现。

重定向完成到您要放置所需portlet的页面,而不是portlet本身。 就像我们在大多数Web应用程序环境中所做的那样。

因此,如果您可以记住(硬编码)放置portlet的页面,则只需执行以下操作:

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");
}

但是,如果要绑定负责呈现放置在其他页面上的portlet的某些参数,则需要使用PortletURLFactoryUtil.create动态创建URL,如下所示:

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());
}

上面代码中的棘手部分是获取plid PortalUtil还有其他可用的方法,根据您的要求和数据,它们可以用于相同的目的。

获得getFriendlyURLLayout(long groupId, boolean privateLayout, String friendlyURL)的另一种方法是,当您要基于friendlyURL获得LayoutLocalServiceUtil并且确定私有/公共布局getFriendlyURLLayout(long groupId, boolean privateLayout, String friendlyURL)使用getFriendlyURLLayout(long groupId, boolean privateLayout, String friendlyURL)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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