Liferay Genric Portlet Dem 空值

Liferay Genric Portlet Dem Null Value

这是我的带有@ProcessAction 注释的class。当我在文本字段中输入时,它将在控制台中显示输入数据:

public class FirstGenericDemo extends GenericPortlet {

    public void init() {
        viewTemplate = getInitParameter("view-template");
    }

    @RenderMode(name= "view")
    public void myView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
        include(viewTemplate, renderRequest, renderResponse);
    }

   //Annotation
   @ProcessAction(name = "myActionMethod")
   public void myActionMethod(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    // TODO Auto-generated method stub
        String name = ParamUtil.getString(request,"name");
        System.out.println("Name => " + name);
    }

    protected 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);
        }
    } 
    protected String viewTemplate;
    private static Log _log = LogFactoryUtil.getLog(FirstGenericDemo.class);

}

这里是 myView.jsp:

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

This is the <b>First Generic Demo</b> portlet in View mode.

<portlet:actionURL var="myaction" name="myActionMethod">
</portlet:actionURL>
<form action="${myaction}" method="post">
Name: <input type = "text" name="name">
<input type="submit" value="SUBMIT">
</form>

但是当我 运行 它总是在控制台中打印 "Name => null"。我该如何解决?

Portlet 的参数通常需要在 HTML 中命名空间 - 由于一个页面由如此多的 Portlet 组成,这是为了消除页面上可以共存的各个输入的歧义。将您的 JSP 更改为包含

<input type="text" name="<portlet:namespace/>name" />

大功告成。在 Java 方面,这将被消歧为 "name".

您也可以尝试使用 <aui:input /> 标签库,因为它会自动进行这种修饰。

第三个选项是为此 portlet 配置特定于 Liferay 的设置,使其不需要命名空间参数。您在 WAR 打包的 portlet in liferay-portlet.xml, or in an OSGi bundle (Liferay 7.0 and up) as a com.liferay.portlet.requires-namespaced-parameters=false component property.

中执行此操作