Открытый параметр рендеринга не работает в Inter Portletlet Communication(IPC) JSR 286 Jdeveloper Приложение производителя портлета

Я пытаюсь установить связь между портлетами с использованием общедоступных параметров рендеринга (JSR 286), чтобы использовать одну переменную для двух разных портлетов в одном приложении. Вот процесс, за которым я следовал formPortlet.jsp -> FormPortlet -> StockPortlet -> stockPortlet.jsp

Получите стоимость акций, представленную в formPortlet.jsp, и отобразите ее в stockPortlet.jsp, используя общедоступные параметры рендеринга. Но я получаю нулевой объект в stockPortlet.jsp. После отладки я обнаружил, что объект renderRequest отличается от FormPortlet.java для StockPortlet.java(получил другой хэш-код для renderRequest).

Код:

portlet.xml -> определяется как FormPortlet.java и StockPortlet.java

<?xml version="1.0" encoding="UTF-8"?>
    <ns0:portlet-app xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:ns0="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">

       <ns0:portlet id="1513125171228">
          <ns0:description xml:lang="en-US">FormPortlet - Stock</ns0:description>
          <ns0:description xml:lang="en">English Description</ns0:description>
          <ns0:portlet-name>FormPortlet</ns0:portlet-name>
          <ns0:display-name xml:lang="en-US">FormPortlet</ns0:display-name>
          <ns0:display-name xml:lang="en">English Display Name</ns0:display-name>
          <ns0:portlet-class>ipcparam.portlet.FormPortlet</ns0:portlet-class>
          <ns0:expiration-cache>0</ns0:expiration-cache>
          <ns0:supports>
             <ns0:mime-type>text/html</ns0:mime-type>
             <ns0:portlet-mode>edit</ns0:portlet-mode>
          </ns0:supports>
          <ns0:supported-locale>en-US</ns0:supported-locale>
          <ns0:resource-bundle>ipcparam.portlet.resource.FormPortletBundle</ns0:resource-bundle>
          <ns0:portlet-info>
             <ns0:title>FormPortlet</ns0:title>
             <ns0:short-title>FormPortlet</ns0:short-title>
             <ns0:keywords>FormPortlet, FirstPortlet</ns0:keywords>
          </ns0:portlet-info>
          <ns0:portlet-preferences>
             <ns0:preference>
                <ns0:name>portletTitle</ns0:name>
             </ns0:preference>
          </ns0:portlet-preferences>
          <ns0:supported-public-render-parameter>FormParameter</ns0:supported-public-render-parameter>
       </ns0:portlet>


       <ns0:portlet id="1513126488906">
          <ns0:description xml:lang="en-US">StockPortlet - PublicParams</ns0:description>
          <ns0:description xml:lang="en">English Description</ns0:description>
          <ns0:portlet-name>StockPortlet</ns0:portlet-name>
          <ns0:display-name xml:lang="en-US">StockPortlet</ns0:display-name>
          <ns0:display-name xml:lang="en">English Display Name</ns0:display-name>
          <ns0:portlet-class>ipcparam.portlet.StockPortlet</ns0:portlet-class>
          <ns0:expiration-cache>0</ns0:expiration-cache>
          <ns0:supports>
             <ns0:mime-type>text/html</ns0:mime-type>
             <ns0:portlet-mode>edit</ns0:portlet-mode>
          </ns0:supports>
          <ns0:supported-locale>en-US</ns0:supported-locale>
          <ns0:resource-bundle>ipcparam.portlet.resource.StockPortletBundle</ns0:resource-bundle>
          <ns0:portlet-info>
             <ns0:title>StockPortlet</ns0:title>
             <ns0:short-title>StockPortlet</ns0:short-title>
             <ns0:keywords>Interportlet,Communication,Stock,portlet</ns0:keywords>
          </ns0:portlet-info>
          <ns0:portlet-preferences>
             <ns0:preference>
                <ns0:name>portletTitle</ns0:name>
             </ns0:preference>
          </ns0:portlet-preferences>
          <ns0:supported-public-render-parameter>FormParameter</ns0:supported-public-render-parameter>
       </ns0:portlet>


       <ns0:custom-portlet-mode>
          <ns0:portlet-mode>about</ns0:portlet-mode>
       </ns0:custom-portlet-mode>
       <ns0:custom-portlet-mode>
          <ns0:portlet-mode>config</ns0:portlet-mode>
       </ns0:custom-portlet-mode>
       <ns0:custom-portlet-mode>
          <ns0:portlet-mode>edit_defaults</ns0:portlet-mode>
       </ns0:custom-portlet-mode>
       <ns0:custom-portlet-mode>
          <ns0:portlet-mode>preview</ns0:portlet-mode>
       </ns0:custom-portlet-mode>
       <ns0:custom-portlet-mode>
          <ns0:portlet-mode>print</ns0:portlet-mode>
       </ns0:custom-portlet-mode>

      <ns0:public-render-parameter>
          <ns0:description>First Parameter set by portlet</ns0:description>
          <ns0:identifier>FormParameter</ns0:identifier>
          <ns0:qname xmlns:x="http://sun.com/params">x:FormParameter</ns0:qname>
       </ns0:public-render-parameter> 

    </ns0:portlet-app>

formPortlet.jsp

<%@ page contentType = "text/html; charset=UTF-8"
         pageEncoding = "UTF-8"
         import = "javax.portlet.*, java.util.*, ipcparam.portlet.FormPortlet, ipcparam.portlet.resource.FormPortletBundle"%>
<%@ taglib uri = "http://java.sun.com/portlet_2_0" prefix="portlet"%>

<portlet:defineObjects/>

<form action="<portlet:actionURL/>" method="post">
    Stock Value: <input type="text" name="stockValue"><br>
    <input type="submit" value="Submit"> 
    Entered Stock value: "<% request.getParameter("FormParameter");%>"
</form>

FormPortlet.java -> определяет действие отправки и запрос на отправку для formPortlet.jsp.

package ipcparam.portlet;
import ipcparam.portlet.resource.FormPortletBundle;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.WindowState;

public class FormPortlet extends GenericPortlet {
    protected String getTitle(RenderRequest request) {
        // Get the customized title. This defaults to the declared title.
        PortletPreferences prefs = request.getPreferences();
        return prefs.getValue(PORTLETTITLE_KEY, super.getTitle(request));
    }

    protected void doDispatch(RenderRequest request, RenderResponse response) throws PortletException, IOException {
        // Do nothing if window state is minimized.

        System.out.println("\nEntering doDispatch method of FormPortlet....");

        System.out.println("Form Parameter is set to " + request.getParameter("FormParameter"));


        WindowState state = request.getWindowState();
        if (state.equals(WindowState.MINIMIZED)) {
            super.doDispatch(request, response);
            return;
        }

        // Get the content type for the response.
        String contentType = request.getResponseContentType();

        // Get the requested portlet mode.
        PortletMode mode = request.getPortletMode();

        // Reference a request dispatcher for dispatching to web resources
        PortletContext context = getPortletContext();
        PortletRequestDispatcher rd = null;

        // Dispatch based on content type and portlet mode.
        if (contentType.equals("text/html")) {
            System.out.println("Content tpe is text/html....");
            if (mode.equals(PortletMode.VIEW)) {
                System.out.println("Portlet mode is view....");
                rd = context.getRequestDispatcher("/FormPortlet/html/formPortlet.jsp");
            } 
        } else {
            super.doDispatch(request, response);
        }
        if (rd != null) {
            rd.include(request, response);
        } else {
            super.doDispatch(request, response);
        }
    }


    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
        // Determine which action.


        String okAction = request.getParameter(OK_ACTION);
        String applyAction = request.getParameter(APPLY_ACTION);

        if (okAction != null || applyAction != null) {
            // Save the preferences.
            PortletPreferences prefs = request.getPreferences();
            String param = request.getParameter(PORTLETTITLE_KEY);
            prefs.setValues(PORTLETTITLE_KEY, buildValueArray(param));
            prefs.store();
            if (okAction != null) {
                response.setPortletMode(PortletMode.VIEW);
                response.setWindowState(WindowState.NORMAL);
            }
        }

        String formParam = request.getParameter("stockValue");
        System.out.println("Entered Stock Value: " + formParam);

        response.setRenderParameter("FormParameter", formParam);

    }

    public void doView(RenderRequest request, RenderResponse response)
                throws PortletException, IOException
    {
      System.out.println("\nEntering doView method of FormPortlet....");
    }
}

StockPortlet.java -> в методе отправки получить стоимость акций с помощью объекта renderRequest

package ipcparam.portlet;
import ipcparam.portlet.resource.StockPortletBundle;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.WindowState;

public class StockPortlet extends GenericPortlet {
    protected String getTitle(RenderRequest request) {
        // Get the customized title. This defaults to the declared title.
        PortletPreferences prefs = request.getPreferences();
        return prefs.getValue(PORTLETTITLE_KEY, super.getTitle(request));
    }

    protected void doDispatch(RenderRequest request, RenderResponse response) throws PortletException, IOException {
        // Do nothing if window state is minimized.


        System.out.println("Request Parameter :" + request.getParameter("FormParameter")); // returns null object..


        WindowState state = request.getWindowState();
        if (state.equals(WindowState.MINIMIZED)) {
            super.doDispatch(request, response);
            return;
        }

        // Get the content type for the response.
        String contentType = request.getResponseContentType();

        // Get the requested portlet mode.
        PortletMode mode = request.getPortletMode();



        // Reference a request dispatcher for dispatching to web resources
        PortletContext context = getPortletContext();
        PortletRequestDispatcher rd = null;

        // Dispatch based on content type and portlet mode.
        if (contentType.equals("text/html")) {
            if (mode.equals(PortletMode.VIEW)) {
                rd = context.getRequestDispatcher("/StockPortlet/html/view.jsp");
            } 
        } else {
            super.doDispatch(request, response);
        }
        if (rd != null) {
            rd.include(request, response);
        } else {
            super.doDispatch(request, response);
        }
    }


}

0 ответов

Другие вопросы по тегам