在Liferay中未调用commandButton操作方法

Dan*_*rch 2 jsf portlet liferay

我有下面的portlet view.xhtml:

 <?xml version="1.0"?>
    <f:view xmlns="http://www.w3.org/1999/xhtml"
        xmlns:c="http://java.sun.com/jsp/jstl/core"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:p="http://primefaces.org/ui">

            <h:body>

                <h:form>
                    <h:commandButton value="TESTButton" action="#{navigationViewBean.submit}" />
                    <h:outputText value="TESTGetter: #{navigationViewBean.testField}" />
                </h:form>
            </h:body>
    </f:view>
Run Code Online (Sandbox Code Playgroud)

而这个托管bean:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean(name = "navigationViewBean")
@RequestScoped
public class NavigationViewBean {
    private String testField;
    public boolean lol = false;

    public void submit() {
        System.out.print("TEST BUTTON INVOKED");
    }

    public String getTestField() {
        System.out.print("TEST GETTER INVOKEDx");
        return testField;
    }

    public void setTestField(String testField) {
        this.testField = testField;
    }

}
Run Code Online (Sandbox Code Playgroud)

我尝试做的唯一一件事就是调用一个方法来打印我的控制台.问题在于,无论我做什么,都不会调用action方法.正确调用getter方法.

我究竟做错了什么?

Dan*_*rch 6

我不知道为什么,但在将此行添加到我的liferay-portlet.xml修复后.

<requires-namespaced-parameters>false</requires-namespaced-parameters>
Run Code Online (Sandbox Code Playgroud)

整个街区:

<portlet>
        <portlet-name>Test1</portlet-name>
        <icon>/icon.png</icon>
        <requires-namespaced-parameters>false</requires-namespaced-parameters>
        <header-portlet-css>/css/main.css</header-portlet-css>
</portlet>
Run Code Online (Sandbox Code Playgroud)

  • 丹尼尔,你的回答是正确的.在Liferay 6.2中,门户网站命名空间默认使用portlet命名空间请求参数.但是,mojarra和JSF组件库当时与该功能不兼容,因此您需要指定`<requires-namespaced-parameters> false </ requires-namespaced-parameters>`. (2认同)
  • 由于这些库已更新为可以使用命名空间参数,因此我们(Liferay Faces团队)目前正在使用&lt;requires-namespaced-parameters&gt; true &lt;/ requires-namespaced-parameters&gt;( (这是默认设置),这样您以后就无需指定该选项了。 (2认同)