最近公司的项目涉及到了将做好的项目整合到Jahia中,所有我做了一个小的Demo测试了一下Jahia的view mode,关于Jahia是什么请到
http://www.jahia.com/jahia/Jahia 中了解。步骤如下:
1.在WEB-INF/下添加portlet.xml文件.以我的NewsDemo为例
- <?xml version="1.0" encoding="UTF-8"?>
- <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
- <portlet>
- <portlet-name>NewsTest Portlet</portlet-name>
- <display-name>News Test Portlet</display-name>
- <portlet-class>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher</portlet-class>
- <init-param>
- <name>viewNamespace</name>
- <value>/view</value>
- </init-param>
- <init-param>
- <name>defaultViewAction</name>
- <value>newsView!show</value>
- </init-param>
- <expiration-cache>0</expiration-cache>
- <supports>
- <mime-type>text/html</mime-type>
- <portlet-mode>view</portlet-mode>
- </supports>
- <portlet-info>
- <title>NewsTest Portlet</title>
- <short-title>NewsTest Portlet</short-title>
- <keywords>NewsTest Portlet</keywords>
- </portlet-info>
- </portlet>
- </portlet-app>
其中:
- <init-param>
- <name>viewNamespace</name>
- <value>/view</value>
- </init-param>
- <init-param>
- <name>defaultViewAction</name>
- <value>newsView!show</value>
- </init-param>
viewNamespace定义action的namespace 类似的还有editNamespace,helpNamespace。
defaultViewAction为Portlet启动后默认执行的action名.如果定义action的时候 类似 newsView!*这种的话,要写newsView,此时Portlet将会去寻找acton的execute()方法,否则直接写成newsView!show。
2. 修改struts.xml文件,以我的NewsDemo为例
- <?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>
- <include file="struts-portlet-default.xml" />
- <package name="newsViewDemo" extends="struts-portlet-default" namespace="/view">
- <action name="newsView!*" class="newsViewAction" method="{1}">
- <result name="input">/view/list.jsp</result>
- <result name="detail">/view/detail.jsp</result>
- <result name="classnewslist">/view/classnewslist.jsp</result>
- </action>
- </package>
- </struts>
package
的namespace可以写成别的,这样的话
viewNamespace也要做相应的变化。
其中要注意的有:
- 添加 <include file="struts-portlet-default.xml" />
- 将extens 改为 : extends="struts-portlet-default"
- 路径要写成绝对的形式如:/view/list.jsp
3.将项目打成war包放到$jahiahome/tomcat/webapps/jahia/WEB-INF/var/new_webapp/下,jahia会自动调用。