我绝对不是Liferay Portlet开发的新手,但遇到以下问题。
当我尝试在Portlet中添加我的第一个Portlet(由我开发)时,我听错了此错误消息:
testPortlet1暂时不可用。
在我的IDE的stacktrace中,我看到以下错误消息:
2014-12-19 11:37:55,874 [[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'] ERROR commons.CommonsLogger.error(38) - Could not find action
There is no Action mapped for namespace /testPortlet1 and action name startTestPortlet1. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
..............................................................................
..............................................................................
..............................................................................
11:37:55,883 ERROR [PortletServlet:96] javax.portlet.PortletException: Could not find action startTestPortlet1
javax.portlet.PortletException: Could not find action startTestPortlet1
at org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher.serviceAction(Jsr168Dispatcher.java:454)
at org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher.render(Jsr168Dispatcher.java:322)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:101)
..............................................................................
..............................................................................
..............................................................................
Caused by: There is no Action mapped for namespace /testPortlet1 and action name startTestPortlet1. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
..............................................................................
..............................................................................
..............................................................................
11:37:55,892 ERROR [jsp:154] There is no Action mapped for namespace /testPortlet1 and action name startTestPortlet1. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
..............................................................................
..............................................................................
..............................................................................
因此,这是与我的Portlet相关的structs.xml部分:
<package name="TestPortlet1Package" extends="struts-portlet-default" namespace="/">
<action name="startTestPortlet1" class="TestPortlet1Action" method="startTestPortlet1">
<result name="success">/testPortlet1/testPortlet1.jsp</result>
</action>
</package>
这是我的JSP视图(在\ 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>
这是我在portlet.xml文件中定义的portlet配置:
<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>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>
我想念什么?我该如何解决这个问题?我快疯了。
特纳克斯
最佳答案
在struts.xml中定义的包名称空间和porlet.xml中的viewNamespace
之间不匹配。解决方案:修复struts.xml
<package name="TestPortlet1Package"
extends="struts-portlet-default"
namespace="/testPortlet1">