LifeRay中portlet.xml文件中的portlet配置究竟是什么意思?

时间:2014-12-22 09:44:46

标签: java struts2 liferay liferay-6 portlet

我是LifeRay portlet开发中的新手,现在我正在开发一个使用 Struts 2 的portlet的项目,我对如何配置portlet有很多疑问。

例如,我有一个“Hello World”portlet,它在 portlet.xml 文件中具有以下配置:

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

那么你能帮助我理解这个文件的设置是什么吗?

我的怀疑是:

1)在 部分中设置的标题与在portlet配置开头设置的 portlet-name 之间有什么区别?

2)然后有一些 部分。在我看来,这些设置了我的portlet的行为(如果它处于查看模式或配置模式)。

所以我有两对,第一对与查看模式有关:

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

但究竟是什么意思?

例如,究竟代表 viewNamespace defaultViewAction 的是什么?我认为这与我的 struts.xml 文件的内容有关,因为在其中我有类似

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

或者它与我的控制器类中的metodo调用有关吗?

public String startTest() {

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

    return SUCCESS;
}

究竟如何运作?

1 个答案:

答案 0 :(得分:0)

&#39; init-param&#39;使用getInitParameter(&#34; init-parameter-name&#34;)从MVCPortlet扩展类中的init()方法加载属性;我从未使用过Struts2 portlet,但我认为你可以使用相同的方法。

portlet-name和display-name用于代码和部署标识,但portlet-info标记用于人类可读的文本(例如,在要添加的可用portlet列表中查看portlet的名称)门户网站的顶部栏。)

supports标签用于设置mime-type(通常是text / html)和可用的portlet模式;即使没有设置,VIEW模式也可用。通常使用的其他模式是EDIT(用于使用portlet首选项)和HELP(有关portlet及其使用的信息)。

您可以查看这篇文章了解更多信息:https://www.liferay.com/es/documentation/liferay-portal/6.0/development/-/ai/anatomy-of-a-portlet

问候。