Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info

The Portlet Plugin

Excerpt

is used for developing JSR168 JSR286 portlets using Struts 2

.

portlet-class

To use the Struts 2 Portlet framework, use org.apache.struts2.portlet.dispatcher.Jsr168DispatcherJsr286Dispatcher as the portlet class in your portlet.xml file:

Code Block
titleportlet.xml

<portlet-app
    <?xml version="1.0" encoding="UTF-8"?>

<portlet-app id="my-portlet-app"
	xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_12_0.xsd"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     version="2.0"
	xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_12_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_12_0.xsd"
    id="my-portlet-app">

    <portlet id="MyPortlet">
        <description xml:lang="EN">My Portlet</description>
        <portlet-name>MyPortlet</portlet-name>
        <display-name xml:lang="EN">my-portlet</display-name>
    
        <portlet-class>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher<Jsr286Dispatcher</portlet-class>
        
        <!-- SNIP -->

    </portlet>
</portlet-app>

...

Code Block
titleportlet.xml

<init-param>
    <!-- Portlet namespace -->
    <name>portletNamespace</name>
    <value>/portletA</value>
</init-param>
<init-param>
    <!-- The base namespace of the view portlet mode -->
    <name>viewNamespace</name>
    <value>/view</value>
</init-param>
<init-param>
    <!-- The default action to invoke in view mode -->
    <name>defaultViewAction</name>
    <value>index</value>
</init-param>

...

If you want to access to expose the OGNL value stack through request attributes (e.g. if you want to use regular JSTL tags to access values in the stack), you have to configure the dispatcher servlet in your web application descriptor:

Code Block
titleweb.xml

<servlet id="Struts2PortletDispatcherServlet">
    <servlet-name>Struts2PortletDispatcherServlet</servlet-name>
    <servlet-class>org.apache.struts2.portlet.dispatcher.DispatcherServlet</servlet-class>
</servlet>

...

Code Block
titlestruts.xml

<result type="redirectAction" name="success">
    <param name="actionName">displayCart</param>
    <param name="userId">${userId}</param>  
    <!-- If you want to redirect to a different portlet mode, use the portletMode parameter 
    <param name="portletMode">view</param>
    -->
</result>

...

Typical usage for the portletUrlType is if you have a delete link that removes something from a database. To ensure this is done in the event phase, as recommended by the portlet specification (since it is a change of state), the url can use this attribute, e.g. <s:url action="deleteEntry" portletUrlType="action"/>

Security

Basically the Struts2 Portlet Plugin doesn't support different auth level in the same portlet. If you want to achieve that you must create two separated portlets and configure access level with portlet engine for each of them.

Other resources

Struts 2 Portlet Tutorial
JSR168 Specification
JSR286 Specification