我正在使用Liferay,我的portlet类如下:
public class HospitalPortlet extends MVCPortlet {
private static Log _log = LogFactory.getLog(HospitalPortlet.class);
public void doLogin(ActionRequest actionRequest,
ActionResponse actionResponse)
throws IOException, PortletException{
actionRequest.setAttribute("test", "this is a test");
}
public void doView(RenderRequest renderRequest,
RenderResponse renderResponse)
throws IOException, PortletException{
renderRequest.setAttribute("test", "this is a test");
include("view.jsp", renderRequest, renderResponse);
}
public void include(String path,
RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException{
PortletRequestDispatcher portletRequestDispatcher =
getPortletContext().getRequestDispatcher(path);
if (portletRequestDispatcher == null){
_log.error(path + " is not a valid include");
}
else{
portletRequestDispatcher.include(renderRequest, renderResponse);
}
}
}
我的viw.jsp如下:
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
This is the <b>Hospital</b> portlet.
<%
String testVar = (String)renderRequest.getAttribute("test");
%>
<br />
<p><%= testVar %></p>
我将此portlet解密并将其放在页面上,但它是空的,并且liferay日志文件中没有错误消息。这有什么问题?
答案 0 :(得分:1)
只需删除包含方法
即可 public void include(String path,
RenderRequest renderRequest, RenderResponse renderResponse)
不要删除include("view.jsp", renderRequest, renderResponse)
;
doView()
中的
并部署您的代码
答案 1 :(得分:0)
尝试删除include方法并在doView方法中包含line。我假设你只有一个名为view.jsp的页面。还要仔细检查portlet的portlet.xml,看看portlet-class是不是指向MVCPortlet而是指向HospitalPortlet类。
答案 2 :(得分:0)
在spring mvc portlet中我遇到了这个问题,我犯的错误就是忘了替换line portlet.xml文件
com.liferay.util.bridges.mvc.MVCPortlet
我必须替换为
org.springframework.web.portlet.DispatcherPortlet
一旦我将此错误替换掉了。