替换liferay 7.x中的renderrequest.getparameter(“param”)

7dl7o3gd  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(475)

当我使用下面的代码得到警告,它是不赞成的

renderRequest.getParameter("param")

然后我用

renderRequest.getRenderParameters().getValue("param")

正如v3.0所建议的那样。但在运行时出现了以下错误

2020-11-19 02:58:02.537 ERROR [http-nio-8080-exec-6][render_portlet_jsp:131] null
java.lang.UnsupportedOperationException: Requires 3.0 opt-in
    at com.liferay.portlet.internal.PortletRequestImpl.getRenderParameters(PortletRequestImpl.java:520)
    at com.training.portlet.MyPortlet5.doView(MyPortlet5.java:61)
    at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:303)
    at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:478)
    at javax.portlet.GenericPortlet.render(GenericPortlet.java:291)
    at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.render(MVCPortlet.java:302)
    at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:127)
    at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:58)
    at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:124)
    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71)
    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:115)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
    at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:62)
    at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:120)
    at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48)
    at com.liferay.portlet.internal.InvokerPortletImpl.invoke(InvokerPortletImpl.java:573)
    at com.liferay.portlet.internal.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:670)
    at com.liferay.portlet.internal.InvokerPortletImpl.render(InvokerPortletImpl.java:362)
    at
zhte4eai

zhte4eai1#

这个问题是因为我的portlet模块默认使用的是PortletAPIv2.0,而getrenderparameters()从v3.0开始就可用。所以,当我在component类中明确提到要使用v3.0并且gradle刷新时,问题得到了解决。
我可以通过添加

"javax.portlet.version=3.0"

在portlet的组件类中。

@Component(
    immediate = true,
    property = {
        "javax.portlet.version=3.0",
        "com.liferay.portlet.display-category=category.app",
        "com.liferay.portlet.instanceable=true",
        "javax.portlet.init-param.template-path=/",
        "javax.portlet.resource-bundle=content.Language",
        "javax.portlet.security-role-ref=power-user,user",
        "javax.portlet.init-param.view-template=/myportlet5/view.jsp",
        "javax.portlet.name=" + MyModuleMainPortletKeys.MY_PORTLET5
    },
    service = Portlet.class

相关问题