一个典型的Portlet应该有如下的结构:
源代码文件:
java源代码存放在<项目名>/docroot/WEB-INF/src 目录下
配置文件:
配置文件都在<项目名>/docroot/WEB-INF目录下,典型的有4个配置文件
portlet.xml是JSR-286相关的一些配置,它作为portlet的部署描述文件
剩余3个配置文件都是和Liferay相关的:
liferay-display.xml 文件显示portlet在Add菜单的哪个分类下
liferay-portlet.xml 文件显示Liferay对JSR-286做了哪些增强,比如配置某个portlet是否是实例化的,如下面代码第6行所示:
- <liferay-portlet-app>
-
- <portlet>
- <portlet-name>clusternodeinfoportlet</portlet-name>
- <icon>/icon.png</icon>
- <instanceable>false</instanceable>
- <header-portlet-css>/css/main.css</header-portlet-css>
- <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
- <css-class-wrapper>clusternodeinfoportlet-portlet</css-class-wrapper>
- </portlet>
- <role-mapper>
- <role-name>administrator</role-name>
- <role-link>Administrator</role-link>
- </role-mapper>
- <role-mapper>
- <role-name>guest</role-name>
- <role-link>Guest</role-link>
- </role-mapper>
- <role-mapper>
- <role-name>power-user</role-name>
- <role-link>Power User</role-link>
- </role-mapper>
- <role-mapper>
- <role-name>user</role-name>
- <role-link>User</role-link>
- </role-mapper>
- </liferay-portlet-app>
liferay-plugin-package.properties 文件一般用于配置这个portlet所依赖jar包,然后这个portlet会被打包成war.
资源文件:
客户端的资源文件分别在<项目名>/docroot/目录下的js,css,html 目录下。需要注意的是,所有的html/jsp文件都不应该有全局的头比如<html><head>,所有的js,css文件都应该在指定名字空间中。
比如我们写的一段jsp页帧:
- <%--
- /**
- * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- *
- * This library is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- */
- --%>
-
- <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
-
- <portlet:defineObjects />
-
- <h4>
- This is the <b>ClusterNodeInfoPortlet</b> portlet in View mode.
- It will display the node information in the cluster.<br>
- </h4>
-
- <br>
-
- <jsp:useBean id="serverName" class="java.lang.String" scope="request" />
- <jsp:useBean id="serverPort" class="java.lang.String" scope="request"/>
- <jsp:useBean id="sessionId" class="java.lang.String" scope="request"/>
- <jsp:useBean id="portletSessionId" class="java.lang.String" scope="request"/>
- <jsp:useBean id="portalInfo" class="java.lang.String" scope="request"/>
-
-
- <b><font color="red">Cluster Node Information:</font></b><br>
- <b>Current Server Name:</b> <%=serverName%> <br>
- <b>Current Server Port:</b> <%=serverPort%> <br>
- <b>Current Session Id: </b> <%=sessionId %> <br>
- <b>Current Portlet Session Id:<%=portletSessionId %></b>
- <b>Current Portal Info:<%=portalInfo%></b>
-
-
-
-
-
- <b>Current Server Session Id:<%=session.getId() %></b>
- <hr>
可以看出,这段页面是没有全局的标记<html><head>的
本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/881475,如需转载请自行联系原作者