为什么我的第一个"Hello World" LifeRay Portlet结果为“暂时不可用". [英] Why my first "Hello World" LifeRay portlet result to be "temporarily unavailable."?

查看:128
本文介绍了为什么我的第一个"Hello World" LifeRay Portlet结果为“暂时不可用".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绝对不是LifeRay Portlet开发的新手,但在将"Hello World"测试Portlet创建到我正在研究的项目中时遇到了一些问题.

I am absolutly new in LifeRay portlet development and I have some problem to create an "Hello World" test portlet into a project on which I am working on.

在该项目中,使用结构2进行调度.

In this project it is used Structs 2 to do the dispatchment.

所以我完成了以下操作:

So I have done the following operations:

1)我在该文件夹中创建 TestPortlet1Action 类:/Web/src/main/java/mypackage/actions/,在其中定义 startTestPortlet1( )方法是我的protlet的启动方法(我认为这是portlet的入口点):

1) I create the TestPortlet1Action class into this folder: /Web/src/main/java/mypackage/actions/ where I define the startTestPortlet1() method that is the starting method of my protlet (I think that this is the portlet entry point):

package egp.prc.km.actions.testPortlet1;

import egp.prc.km.actions.KMAction;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller("TestPortlet1")
@Scope("prototype")
public class TestPortlet1Action extends KMAction {

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    private String message;


    public String startTestPortlet1() {

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

        return SUCCESS;
    }
}

KMAction 向我提供了该 Action 界面:

package com.opensymphony.xwork2;

package com.opensymphony.xwork2;

public interface Action  {
    java.lang.String SUCCESS = "success";
    java.lang.String NONE = "none";
    java.lang.String ERROR = "error";
    java.lang.String INPUT = "input";
    java.lang.String LOGIN = "login";

    java.lang.String execute() throws java.lang.Exception;
}

因此,返回成功语句返回成功字符串.

So the return SUCCESS statment return the success string.

2)然后,我为此名为 testPortlet1.jsp 的portlet创建一个 JSP视图(进入以下文件夹:/Web/src/main/webapp/testPortlet1/testPortlet1.jsp ):

2) Then I have create a JSP view for this portlet named testPortlet1.jsp (into thi folder : /Web/src/main/webapp/testPortlet1/testPortlet1.jsp):

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
<style>
    .portlet-topper#portlet_SliderNewsPortlet_WAR_KMPortlets, .portlet-title#portlet_SliderNewsPortlet_WAR_KMPortlets {
        display: none
    }

    .portlet#portlet_SliderNewsPortlet_WAR_KMPortlets, .portlet-content#portlet_SliderNewsPortlet_WAR_KMPortlets {
        border: 0;
        margin: 0;
        padding: 0;
        background: 0;

    }
</style>
<hr style="height:1px;border:none;color:#1d8843;background-color:#1d8843;width: 98%" size="4px">
<table width="100%">
    <tr>
        <td>
            <table class="homePortletTitle">
                <tr>
                    <td style="padding-bottom: 0px;"><img src="/km-theme/images/km-icons/section_icon_focus.png"></td>
                    <th style="">TestPortlet1</th>
                    <td style="">Hello World Portlet</td>
                </tr>
            </table>
        </td>
    </tr>

    <tr>
        <td>
          <p>Hello World !!!</p>
        </td>
    </tr>
</table>

3)现在,我知道我必须更新包含以下内容的 struts.xml 文件(该文件位于 Web/main/resources 文件夹中):

3) So now I know that I have to update the struts.xml file (that it is into Web/main/resources folder) that contains something like:

<struts>
    <constant name="struts.objectFactory" value="spring"/>
    <constant name="struts.devMode" value="false"/>
    <constant name="struts.locale" value="en_US"/>
    <constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
    <constant name="struts.custom.i18n.resources" value="km_international"/>

    <package name="kmAjaxPackage" extends="struts-default" namespace="/">
        <interceptors>
            <interceptor name="liferayAjax" class="liferayAjaxInterceptor"/>
            <interceptor-stack name="kmAjaxStack">
                <interceptor-ref name="defaultStack"/>
                <interceptor-ref name="liferayAjax"/>
            </interceptor-stack>
        </interceptors>
        <default-interceptor-ref name="kmAjaxStack"/>
    </package>

    <include file="chat-struts.xml"/>
    ..................................
    ..................................
    ..................................
    <include file="TestPortlet1-struts.xml"/>
</struts>

如您所见,我已经包含了与hello world portlet相关的struts配置文件,该文件是:

As you can see I have included the struts configuration file related to my hello world portlet, this one:

<include file="TestPortlet1-struts.xml"/>

4)现在,我已经以这种方式配置了 TestPortlet1-struts.xml 文件:

4) So now I have configured the TestPortlet1-struts.xml file, in this way:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <package name="TestPortlet1Package" extends="struts-portlet-default" namespace="/testPortlet1">
        <action name="startFocusAction" class="FocusAction" method="startFocus">
            <result name="success">/testPortlet1/testPortlet1.jsp</result>
        </action>
    </package>

</struts>

5)现在,我的问题是了解如何正确配置 web.xml 文件(该文件位于** \ Web \ src \ main \ webapp \ WEB-INF **文件夹中) .根据我对该文件的了解,我已经使用Struts 2 servlet进行了映射(或者我错了吗?)

5) Now my problem is to understand how correctly configure the web.xml file (that I have into the folder **\Web\src\main\webapp\WEB-INF**). From what I understand in this file I have the mapping with the Struts 2 servlets (or am I wrong?)

所以我有这样的东西(对于另一个工作的servlet):

So I have something like this (for another working servlet):

<servlet>
    <servlet-name>calendar</servlet-name>
    <servlet-class>com.liferay.portal.kernel.servlet.PortletServlet</servlet-class>
    <init-param>
        <param-name>portlet-class</param-name>
        <param-value>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>calendar</servlet-name>
    <url-pattern>/calendar/*</url-pattern>
</servlet-mapping>

因此,第一部分定义了servlet,第二部分定义了映射为由该servlet处理的URL模式.是真的还是我错过了什么?

So the first section definied the servlet and the second section definied the URL pattern mapped to be handled by this servlet. Is it true or am I missing something?

那么我该怎么做才能配置我以前的"Hello World测试" servlet?可以吗?

So what have I to do to configure my previous "Hello World test" servlet? Is this ok?

<servlet>
    <servlet-name>testPortlet1</servlet-name>
    <servlet-class>com.liferay.portal.kernel.servlet.PortletServlet</servlet-class>
    <init-param>
        <param-name>portlet-class</param-name>
        <param-value>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>testPortlet1</servlet-name>
    <url-pattern>/testPortlet1/*</url-pattern>
</servlet-mapping>

这还好吗?或者我想念什么吗?

Is this ok or am I missing something?

6)然后,我必须将 portlet.xml 文件配置到文件夹** \ Web \ src \ main \ webapp \ WEB-INF **中,并添加:

6) Then I have to configure the portlet.xml file into the folder **\Web\src\main\webapp\WEB-INF**, adding:

<portlet>

        <portlet-name>testPortlet1</portlet-name>
        <display-name>testPortlet1</display-name>
        <portlet-class>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher</portlet-class>

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

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

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

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

        <portlet-info>
            <title>testPortlet1</title>
        </portlet-info>

    </portlet>

其中 startTestPortlet1 代表在我的操作类中定义的方法 startTestPortlet1().

where startTestPortlet1 represent the method startTestPortlet1() definied in my action class.

7)然后,我将此声明添加到 liferay-portlet.xml 配置文件中:

7) Then i add this statment into the liferay-portlet.xml configuration file:

<portlet>
    <portlet-name>testpPortlet1</portlet-name>
    <instanceable>false</instanceable>
</portlet>

8)最后,我配置了文件 liferay-display.cml 来设置portlet的类别,如下所示:

8) Finally I configured the file liferay-display.cml to set the categories of my portlet, something like this:

<?xml version="1.0"?>
<!DOCTYPE display PUBLIC
        "-//Liferay//DTD Display 6.0.0//EN"
        "http://www.liferay.com/dtd/liferay-display_6_0_0.dtd">

<display>

    <category name="First category">

        <category name="Second inner category">

            <category name="Third inner category">

                <category name="chat">
                    <portlet id="ChatNavigatorUser"/>
                    <portlet id="ChatNavigator"/>
                </category>

                <category name="testcategory">
                    <portlet id="TestPortlet1"/>
                    <portlet id="testPortlet1"/>
                </category>

              </category>

        </category>

    </category>

</display>

问题是,当我尝试在门户的主页上添加我的portlet时,我得到了这个竞争信息,而不是预期的Hello World输出:

The problem is that when I try to add my portlet on the homepage of the portal I obtain this contet instead the expected Hello World output:

testPortlet1暂时不可用.

推荐答案

您必须像下面这样配置web.xml:

you have to configure the web.xml like below:

<web-app id="WebApp_ID" version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>com.liferay.portal.kernel.spring.context.PortletContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>struts2servlet</servlet-name>
<servlet-class>org.apache.struts2.dispatcher.ng.servlet.StrutsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>struts2servlet</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>struts2Resources</servlet-name>
<servlet-class>org.apache.struts2.dispatcher.ng.servlet.StrutsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>struts2Resources</servlet-name>
<url-pattern>/struts/*</url-pattern>
</servlet-mapping>
</web-app>

http://www.roytuts.com/中获得它集成struts-2-in-liferay-portlet/

这篇关于为什么我的第一个"Hello World" LifeRay Portlet结果为“暂时不可用".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆