Search code examples
jsfjsf-2liferaycommandbuttonmethod-invocation

commandButton doesn't invoke managed bean action


I've been reading and searching among the many pages with similar questions, but I cannot find why my commandButton is not invoking the action (I have debugged it and that is the problem). My code looks simple but... doesn't work. Maybe it's a newbie problem, but I don't know where it is.

I'm writing a portlet for liferay using JSF2 and Liferay Faces Alloy.

I've also read the question commandLink/commandButton/ajax backing bean action/listener method not invoked, very educational for me, but none of the points have solved my problem.

Here is my mainView.xhtml file:

<?xml version="1.0"?>

<f:view
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:aui="http://liferay.com/faces/aui"
    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">

    <h:head />
    <h:body>
        <h:form>
            <h:messages globalOnly="true" layout="table" />
            <h:outputText id="esteTexto" value="#{ramSession.texto}" />
            <br />
            <h:commandButton action="#{ramSession.add}" styleClass="btn btn-default" value="#{ramSession.texto}">
            </h:commandButton>
        </h:form>
    </h:body>
</f:view>

And here is my SessionScoped ManagedBean file, RamSession.java:

@ManagedBean
@SessionScoped
public class RamSession extends AbstractBaseBean implements Serializable {

    private static final long serialVersionUID = 919724848720360000L;
    private String texto;

    public void add() {
        this.texto = new String("Entrando");
    }

    @PostConstruct
    public void postConstruct() {
        this.texto = new String("Jereje");
    }

    public String getTexto() {
        logger.info("gettingTexto");
        addGlobalSuccessInfoMessage();
        return this.texto;
    }

    public void setTexto(String texto) {
        this.texto = texto;
    }
}

I have also tried returning a String (even not necessary), with an actionListener method and even with ajax but nothing. Can anybody help me? Thanks a lot.


Solution

  • Maybe your mojarra listner is not configured correctly.

    Follow one of the two following sub-steps

    a. Add the liferay-faces-init.jar dependency in each Liferay JSF project by adding the following code to each pom.xml :

    <dependency>
         <groupId>com.liferay.faces</groupId>
         <artifactId>liferay-faces-init</artifactId>
         <version>3.1.3-ga4</version>
    </dependency>
    

    b. Add the following code in each WEB-INF/web.xml of all your JSF projects :

    <listener>
         <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>