在 Liferay 7.x 中替换 renderRequest.getParameter("param")

Replacement of renderRequest.getParameter("param") in Liferay 7.x

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

renderRequest.getParameter("param")

然后我用了

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

这是 v3.0 建议的。但是在那之后 运行 time

出现以下错误
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 

这个问题是因为我的 portlet 模块默认使用 portlet API v2.0,而 getRenderParameters() 从 v3.0 开始可用。因此,当我在组件 class 中明确提到使用 v3.0 并 Gradle 刷新时,问题得到了解决。

我可以通过添加

来解决这个问题
"javax.portlet.version=3.0"

在 portlet 的组件中 class。

@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