Versions Compared

Key

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

...

This snippet from portlet.xml will set up the portlet with a namespace of /portletA/. This means that all requests to this portlet will get the namespace prepended when looking up the action. In addition, the _view portlet mode will map to the /view namespace, so a request for action myAction will resolve to the namespace and action /portletA/view/myAction. It also means that if no action is requested, the default action of index will be used for the request.

web.xml

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>
Note

If you're only using Struts 2 tags, configuring the dispatcher servlet is optional

Portlet Phases

The portlet specification describes that a portlet request cycle can consist of two phases, an event phase and a render phase. In case of an event in the portlet, it will always execute before the render phase. The event phase is typically for changing the state of the application. In a portlet, this is typically when a form is submitted. The render phase will then prepare and dispatch to the view. It's recommended that you set up the result from an action that is executed in the event phase to point to another action that is executed in the render phase, which again is responsible for dispatching to the actual view.

...