Liferay7 3 ways to communicate between the 33:portlet of BPM Portal Development (session, IPC Render Parameter, IPC Event, Cookies)

Source: Internet
Author: User

The article introduces 5 kinds of methods, 4 kinds are more commonly used:

    • Portlet session
    • IPC Public Render Parameters
    • IPC Event
    • Cookies

Reference Address:

Https://web.liferay.com/zh/community/wiki/-/wiki/Main/Portlet%E9%97%B4%E7%9A%84%E9%80%9A%E4%BF%A1

Way 1:session

Portlet Session Scope:

    • Application_scope: Global

    • Portlet_scope: Single instance scope, default scope

Step 1: To pass information between different portlets, you need to modify the default scope scope

Liferay-portlet.xml settings do not support private sessions

< Portlet >        < private-session-attributes >false</private-session-attributes></portlet  >

Step 2: Set up seesion
portletsession session = renderrequest.getportletsession (); Session.setattribute ("  SessionName1", Some-value, Portletsession.application_scope);

Step 3: Get the values in the seesion in Portlet2
    Portletsession PS = renderrequest.getportletsession ();     = (String) ps.getattribute ("sessionName1", Portletsession.application_scope);

This method is the simplest.

Way 2:IPC Render Parameter

Adding the following attributes to the portal-ext.properties allows portlets in different pages to share their render status with each other:

    Portlet.public.render.parameter.distribution=all_portlets

Step 1: Add the following attribute in "Sender-portlet"
    <portlet-app>        <portlet>            <supported-public-render-parameter>id1</ supported-public-render-parameter>        </portlet>                 <public-render-parameter>            < identifier>id1</identifier>            <qname xmlns:x= "Http://abc.com/userId" >x:param1</qname>        </public-render-parameter>    </portlet-app>

Note: We can declare a list of public paramters for a portlet application.

Note: We can declare a public Render Parameter list for the Portlet .

Step 2

We can set the public Render Parameter in the Processaction method. As key, we are using a defined public Render Parameter identifier:

    public void Processaction (actionrequest  request, actionresponse response) throws IOException, Portletexception  {        ........        Response.setrenderparameter ("Id1", "Someidvalue"); ........    }
Step 3: "Portlet.xml" file for "Receiver Portlet"

Specify which public Render Parameter is allowed to be shared in the Porltet definition

    <portlet-app>        <portlet>            <portlet-name >PortletB</portlet-name>            < supported-public-render-parameter>id1</supported-public-render-parameter>        </portlet >        <public-render-parameter>            <identifier>id1</identifier>            <qname xmlns:x= "/http Abc.com/userid ">x:param1</qname>        </public-render-parameter>    </portlet-app>
Step 4

Portlets can read public Render Parameter by using the Request.getpublicparametermap () method.

Note: Because public Render Parameter is incorporated into the global Parameter, we can also use the following method to read:

    Request.getparameter ("Id1");
Step 5

We can also use the following method to remove a public Render Parameter:

    Response.removepublicrenderparameter ("Id1")

Example:
JSP:
view.jsp<%@ taglib URI="Http://java.sun.com/portlet_2_0"prefix="Portlet" %><%@ taglib URI="Http://liferay.com/tld/aui"prefix="AUI" %><portlet:defineobjects/> <Portlet:actionurlvar= "ActionURL"name= "Setrenderparameter"/> <Aui:formAction= "<%=actionurl.tostring ()%>"Method= "POST"><Aui:inputname= "Name"label= "Set Your Name in Public"/><Aui:button-row><Aui:buttontype= "Submit"value= "Set"/></Aui:button-row></Aui:form>
the received JSP<%@page Import="Com.liferay.portal.kernel.util.ParamUtil"%><%@ taglib URI="Http://java.sun.com/portlet_2_0"prefix="Portlet" %> <portlet:defineobjects/> <!--In JSP we can directly read public render parameter -<!--Also Public render parameter was available in any other life cycle methods - <%Stringname=paramutil.getstring (Request,"myname");%> <H3>Public parameter name is ' MyName '</H3><H3>Its value is</H3><b><%=name%></b>

Way 3:IPC Event

Slightly

Refer to Address:

Https://web.liferay.com/zh/community/wiki/-/wiki/Main/Portlet%E9%97%B4%E7%9A%84%E9%80%9A%E4%BF%A1

Way 4:cookies

This method is not recommended.

There are some limitations:

1. No more than 4KB of data is allowed

2. Each server is limited to a maximum of 20 cookies.

Liferay7 3 ways to communicate between the 33:portlet of BPM Portal Development (session, IPC Render Parameter, IPC Event, Cookies)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.