Search code examples
jsfliferayportlet

commandButton action method not invoked in Liferay


I've the below 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>

And this managed 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;
    }

}

The only thing I try to do, is to call a method which prints something to my console. The problem is that no matter what I do, the action method is never invoked. The getter method is properly called.

What am I doing wrong?


Solution

  • Im not sure why, but after adding this line to my liferay-portlet.xml it fixed it.

    <requires-namespaced-parameters>false</requires-namespaced-parameters>
    

    And here the whole block:

    <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>