1、页面参数传递
在processAction方法中获取页面参数值
String action_target = actionRequest.getParameter("action_target");
将参数值传递到Render方法中
actionResponse.setRenderParameter("action_target", action_target);
在Render的doView方法中获取参数值
String action_target = renderRequest.getParameter("action_target");
将参数值传递回页面
renderRequest.setAttribute("result", "from doView: " + action_target);
在页面取得参数值
<c:out value="${requestScope.result}"/>
2、页面信息国际化
<liferay-ui:message key="cuss.username.success"/>
LanguageUtil.format(pageContext, "you-are-signed-in-as-x", signedInAs);
LanguageUtil.get(pageContext, "add-new-product");
you-are-signed-in-as-x=您已经以{0}身份登录
3、获取HttpServletRequest等对象
HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(resourceRequest);
HttpServletResponse servletResponse = PortalUtil.getHttpServletResponse(resourceResponse);
HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(resourceRequest);
ServletContext servletContext = servletRequest.getSession().getServletContext();
ThemeDisplay themeDisplay = (ThemeDisplay)resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
String portletId = portletDisplay.getId();
PortletBag portletBag = PortletBagPool.get(portletId);
ServletContext servletContext = portletBag.getServletContext();
4、Portal路径获取:
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute (WebKeys.THEME_DISPLAY);
//return http://localhost:8080
PortalUtil.getPortalURL(renderRequest);
//return /web/guest/home?uid=cjm
PortalUtil.getLayoutURL(themeDisplay);
//return /E:/liferay6_tomcat/bundles/tomcat-6.0.29/webapps/ROOT/
PortalUtil.getPortalWebDir();
//return http://localhost:8080/web/guest/home
PortalUtil.getPortal().getLayoutFullURL(themeDisplay);
//return /web/guest/home?uid=cjm
PortalUtil.getCurrentURL(renderRequest);
6、ROOT相关子目录的获取
System.out.println("2. " + themeDisplay.getPathImage()); /image
System.out.println("3. " + themeDisplay.getPathJavaScript()); /html/js
System.out.println("4. " + themeDisplay.getPathMain()); /zh/c
System.out.println("5. " + themeDisplay.getPathThemeCss()); /html/themes/classic/css
System.out.println("6. " + themeDisplay.getPathThemeImages()); /html/themes/classic/imags
System.out.println("7. " + themeDisplay.getPathThemeJavaScript()); /html/themes/classic/js
System.out.println("8. " + themeDisplay.getPathThemeRoot()); /html/themes/classic
System.out.println(themeDisplay.getPortalURL()); http://localhost:8080
System.out.println(themeDisplay.getURLCurrent()); /zh/web/guest/kstd/convenienttravel
System.out.println(themeDisplay.getURLHome()); http://localhost:8080/web/guest
System.out.println(themeDisplay.getURLPortal()); http://localhost:8080
7、为控制面板创建Portlet
一个Portlet如果需要显示在控制面板中,需要在/WEB-INF/liferay-portlet.xml文件中未Portlet添加如下内容:
<!-- 菜单项分类,包括my、content、portal、server四种 -->
<control-panel-entry-category>content</control-panel-entry-category>
<!-- 菜单项在该分类中的相对位置 -->
<control-panel-entry-weight>1.5</control-panel-entry-weight>