不同页面中 portlet 的事件不会重新加载 view.jsp

event for portlets in different page doesnt reload view.jsp

我有两个 portlet,正在尝试将事件从 portletA 发送到 portletB。现在的问题是,当我将两个 portle 放在同一个页面时,它可以工作,但是当我将它们放在不同的页面时,PortletB 的 view.jsp 页面不会刷新,即使控制进入了 portletB 的方法 ProcessAction(值我正在印刷,所以我想控制权在那个部分。

组件 A view.jsp

<portlet:actionURL var="changedb" name="processEvent"/>


<aui:form method="post" action="<%=changedb.toString() %>">
<aui:fieldset>
    <aui:select label="Select Bot" id="options" name="botname" 
required="true" showEmptyOption="true">
        <aui:option value="otion1" name="option1" 
>option1</aui:option>
        <aui:option value="option2" name="option2" 
>option2</aui:option>
    </aui:select>
<aui:button type="submit" value="Send"/>
</aui:fieldset>
</aui:form>

Java 方法:

@ProcessAction(name="processEvent")
public void process(ActionRequest request, ActionResponse response) {
    String bot = ParamUtil.getString(request, "botname","");
    String url = "somehttplink" + bot;
    System.out.print("control came inside changedbportlet");
    System.out.println(url);
    QName qName = new QName("botchange");
    response.setEvent(qName, url);

}

Portlet B(接收方)

<portlet:defineObjects />

<%
String url = (String) renderRequest.getParameter("url");
%> 
<main class="container">
<div class="row">
<div class="col-lg-12">
    <div id="initial-screen">
 <iframe class="iframe" src="<%= url %>"  width = "1000" height="800" 
></iframe>
</div>
</div>
</div>
</main> 

Java 方法:

@ProcessEvent(qname = "botchange")
public void myEvent(EventRequest request, EventResponse response)
        throws javax.portlet.PortletException,
    java.io.IOException {
    Event event = request.getEvent();
    String url = (String) event.getValue();
    System.out.println("control came to showpageportlet");
    System.out.print(url);
    response.setRenderParameter("url", url);
}

我正在使用 Liferay 7 和 osgi modules.I 还按照 https://web.liferay.com/community/wiki/-/wiki/Main/portlet+to+portlet+communication.

中的说明在 portlet-ext.properties 文件中添加了以下命令
portlet.event.distribution=layout-set

我做错了什么?

在 PortletA 向 PortletB 发送需要更改其状态但不在当前页面上的信息的情况下,您需要有一种方法来记住这一事实。

事件只是传递信息,ProtletB 负责记住它。

您可以使用存储值的会话属性,或者更好的 portlet 首选项将在事件处理程序方法中编辑并在呈现 (doView) 方法中读取。不要忘记有一个默认值。

你可以用这个在事件中存储值。

PortletPreferences preferences = request.getPreferences();
preferences.setValue("url", url);
preferences.store();

然后通过这个访问它。

request.getPreferences();
String state = (String) preferences.getValue("url", "")