简体   繁体   English

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

[英]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. 当我单击按钮搜索时,我将重定向到另一个portlet,并在同一操作中保存一些数据。 Now, when I click the button search, it will execute the actions method searchEntry in Java code. 现在,当我单击按钮搜索时,它将以Java代码执行动作方法searchEntry。 Can I redirect to another portlet in this actions method search in java? 我可以在Java中的此操作方法搜索中重定向到另一个portlet吗? 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和Java代码,其中的动作方法是searchEntry。

JSP: 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: 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. 重定向完成到您要放置所需portlet的页面,而不是portlet本身。 Like, we do in most of the web application environment. 就像我们在大多数Web应用程序环境中所做的那样。

So, if you can remember (hard-code) the page, where you have dropped your portlet, you can simply do as following: 因此,如果您可以记住(硬编码)放置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");
}

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: 但是,如果要绑定负责呈现放置在其他页面上的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());
}

The tricky part from the above code is to get plid . 上面代码中的棘手部分是获取plid There are other method available in PortalUtil , which can be used for the same purpose depending on the requirement and data you have. PortalUtil还有其他可用的方法,根据您的要求和数据,它们可以用于相同的目的。

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. 获得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.

相关问题 Liferay通过特定操作链接到另一个Portlet - Liferay link to another portlet with a specific action 如何在liferay 7的liferay模块项目中将一个portlet的jsp重定向到另一个portlet的jsp - how to redirect from jsp of one portlet to jsp of another portlet inside liferay module project in liferay 7 如何在liferay + springmvc中调用另一个portlet @RenderMapping方法? - How to call another portlet @RenderMapping method in liferay + springmvc? 在Liferay Portlet中重定向到Java Servlet - Redirect to Java Servlet in Liferay Portlet Liferay Portlet(使用JSF)-在重定向期间将参数从一个bean传递到另一个 - Liferay portlet (with JSF) - pass parameter from one bean to another during redirect liferay问题:显示从Portlet到另一个的图像 - liferay issue : display an image from a portlet to another 从另一个portlet获取Portlet应用程序上下文(Liferay + Spring) - Get Portlet Application Context from another portlet (Liferay + Spring) 如何在Liferay中从另一个Portlet调用一个Portlet? - How to call one portlet from another portlet in Liferay? 定义默认的Portlet Action方法 - Defining default Portlet Action method 如何创建自定义portlet操作/模式以及如何在Liferay中调用它们? - How to create custom portlet action/mode and how to call them in Liferay?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM