以上信息主要是为了在添加应用窗口中显示定义的portlet。如果做了Step3,那么最终在添加应用窗口中显示是第三步所定义的名字。在本例中将显示“Default Message”。添加应用窗口如下图所示,因使用liferay版本不同页面效果会不太一样。
Step5:定义Struts页面流
在配置文件?\\ext-web\\docroot\\WEB-INF\\struts-config.xml中定义struts页面流。 view plaincopy to clipboardprint?
注意:
这里的path=\值就是portlet-ext.xml中对应的view-action的值。 view plaincopy to clipboardprint?
这里的path=\\值就是liferay-portlet-ext.xml中对应的标签
Step6:定义tiles页面布局
在配置文件?\\ext-web\\docroot\\WEB-INF\\tiles-defs.xml中定义页面布局。 view plaincopy to clipboardprint?
这理portlet.ext.defaultmessage.view 继承 portlet。这意味着portlet.ext.defaultmessage.view将会使用 portlet.jsp 作为它的模板。portlet.portlet_configuration.edit_configuration道理相同。 注意: 这里的name=\值就是struts-config.xml中对应的forward=\的值。 这里的name=\值就是struts-config.xml中对应的forward=\的值。 Step7:创建目录defaultmessage 创建一个叫defaultmessage的目录,你的目录结构应该像这样: ?\\ext-web\\docroot\\html\\portlet\\ext\\defaultmessage。 Step8:创建init.jsp 在defaultmessage中创建init.jsp你的目录结构应该像这样:?\\ext-web\\docroot\\html\\portlet\\ext\\ defaultmessage \\init.jsp。输入下列内容到init.jsp中: view plaincopy to clipboardprint? <%@ include file=\ 看看我们在这行中包含了什么? view plaincopy to clipboardprint? <%@ include file=\ 实际对应目录是:?\\portal\\portal-web\\docroot\\html\\common\\init.jsp。这将会让我们使用Liferay 标签库 Step9:创建view.jsp 在defaultmessage中创建view.jsp文件。在本例中,可以直接复制如下代码。 view plaincopy to clipboardprint? <%@ include file=\ String defaultMessage = (String) request.getAttribute(\ %> <%=defaultMessage %> <%@ include file=\ 这将会让我们使用在上一步这定义的init.jsp Step10:创建config.jsp 在defaultmessage中创建config.jsp文件。在本例中,可以直接复制如下代码。 view plaincopy to clipboardprint? <%@ include file=\ <%@ include file=\ Setup the default message: <%@ include file=\ 这将会让我们使用在上一步这定义的init.jsp Step11:创建Action类 创建 action 类来处理信息,DefaultMessageViewAction.java。 view plaincopy to clipboardprint? package com.ext.portlet.defaultmessage.action; import javax.portlet.PortletConfig; import javax.portlet.PortletPreferences; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.struts.PortletAction; import com.liferay.util.Validator; public class DefaultMessageViewAction extends PortletAction { public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config, RenderRequest request, RenderResponse response) throws Exception { PortletPreferences prefs = request.getPreferences(); String defaultMessage = prefs.getValue(\ if (Validator.isNull(defaultMessage)) { return mapping.findForward(\ } request.setAttribute(\ return mapping.findForward(\ } } DefaultMessageConfigAction.java view plaincopy to clipboardprint? package com.ext.portlet.defaultmessage.action; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; import javax.portlet.PortletPreferences; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.struts.PortletAction; import com.liferay.portlet.PortletPreferencesFactory; import com.liferay.util.ParamUtil; import com.liferay.util.servlet.SessionMessages; public class DefaultMessageConfigAction extends PortletAction { public void processAction(ActionMapping mapping, ActionForm form, PortletConfig config, ActionRequest request, ActionResponse response) throws Exception { String defaultMessage = ParamUtil.getString(request, \ if (defaultMessage != null) { String portletResource = ParamUtil.getString(request, \ PortletPreferences prefs = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource, true, true); prefs.setValue(\ prefs.store(); SessionMessages.add(request, config.getPortletName() + \ } } public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config, RenderRequest request, RenderResponse response)
The default message is:
<%