0
votes

I am absolutely new in LifeRay portlet development and now I am working on a project that use Struts 2 based portlet and I have many doubts about how a portlet is configured.

So for example I have an "Hello World" portlet that have the following configuration inside the portlet.xml file:

    <portlet-name>provaAndrea</portlet-name>
    <display-name>Prova Andrea</display-name>
    <portlet-class>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher</portlet-class>

    <init-param>
        <name>viewNamespace</name>
        <value>/nuovaPortlet</value>
    </init-param>

    <init-param>
        <name>defaultViewAction</name>
        <value>startTestPortlet1</value>
    </init-param>

    <init-param>
        <name>editNamespace</name>
        <value>/nuovaPortlet</value>
    </init-param>

    <init-param>
        <name>defaultEditAction</name>
        <value>provaAndreaPropertiesShowAction</value>
    </init-param>

    <expiration-cache>0</expiration-cache>

    <supports>
        <mime-type>text/html</mime-type>
        <portlet-mode>VIEW</portlet-mode>
    </supports>

    <portlet-info>
        <title>Prova Andrea</title>
    </portlet-info>

</portlet>

So can you help me to understand what exactly this file is setting?

My doubts are:

1) What exactly is the difference between the title setted into the section and the portlet-name setted at the beginning of the portlet configuration?

2) Then there are some sections. It seems to me that these sets the behavior of my portlet (if it is in view mode or in configuration mode).

So I have two couple, the first one is related to the view mode:

    <init-param>
        <name>viewNamespace</name>
        <value>/nuovaPortlet</value>
    </init-param>

    <init-param>
        <name>defaultViewAction</name>
        <value>startTestPortlet1</value>
    </init-param>

and the second one is related to the edit mode:

    <init-param>
        <name>editNamespace</name>
        <value>/nuovaPortlet</value>
    </init-param>

    <init-param>
        <name>defaultEditAction</name>
        <value>provaAndreaPropertiesShowAction</value>
    </init-param>

But what exactly mean?

For example what exactly represent the viewNamespace and the defaultViewAction ? I think that this is something related to the content of my struts.xml file because inside it I have something like

    <action name="startTestPortlet1" class="testPortlet1Action" method="startTest">
        <result name="success">/testPortlet1/testPortlet1.jsp</result>
    </action>

Or is it related to the metodo call inside my controller class?

public String startTest() {

    this.setMessage("Hello World inner !!!");

    return SUCCESS;
}

How exactly work?

1

1 Answers

0
votes

The 'init-param' property is loaded from the init() method in MVCPortlet extended classes with getInitParameter("init-parameter-name"); I never used a Struts2 portlet but I think you can use the same method.

The portlet-name and display-name are used for code and deployment identity but portlet-info tags are used for human-readable text (for example, to see the name of the portlet in the list of available portlets to add in the portal's topbar).

The supports tag is used to set the mime-type (usually text/html) and the available portlet modes; the VIEW mode is available even if it isn't set. Other modes usually used are EDIT (for use portlet preferences) and HELP (info about the portlet and its use).

You can take a look to this article for more info: https://www.liferay.com/es/documentation/liferay-portal/6.0/development/-/ai/anatomy-of-a-portlet

Regards.