1

当我使用下面的代码时,收到警告说它已被弃用

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 
4

1 回答 1

2

这个问题是因为我的 portlet 模块默认使用 portlet API v2.0,而 getRenderParameters() 从 v3.0 开始可用。因此,当我在组件类中明确提到使用 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
于 2020-11-19T03:40:58.933 回答