[英]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.