user550738
user550738

Reputation:

simple JSF commandButton not hitting the action

I have the simplest little JSF example (JSF2 with GlassFish) and I can't figure out why the command button is not hitting the action method. This is what I have ... when I click the button, nothing happens.

What am I doing wrong?

testForm.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

    <h:form>
        <h:messages />
        <p/>
        <h:inputText />
        <p/>
        <h:commandButton value="test1" action="#{testController.action1}" />
    </h:form>


</html>

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">

    <managed-bean>
        <managed-bean-name>testController</managed-bean-name>
        <managed-bean-class>com.app.controller.TestController</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

</faces-config>

TestController.java

package com.app.controller;

public class TestController {

    public String action1() {
        return "testPage2";
    }

}

Upvotes: 1

Views: 4334

Answers (2)

user550738
user550738

Reputation:

Eureka! After rebuilding the Eclipse project from scratch I realize what I did wrong. Apache MyFaces is in the project path and the app is being deployed on GlassFish which has it's own JSF implementation. The two JSF implementations don't want to play nicely together.

What a pain. And, you know, I made this exact same mistake once before. Eclipse should warn you about this or there should be some error reported in the GlassFish log or the h:messages tag.

Upvotes: 2

Maddy
Maddy

Reputation: 3816

1)For JSF2.0, Its not required to configure managed bean in Facesconfig.xml.

2)can use @managedban annotation.

   package com.app.controller;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    @ManagedBean(name = "testController")
    @SessionScoped
    public class TestController {
        public String action1() {
            return "testPage2";
        }
/** Constructor, getters and setters*/
    }

Upvotes: -1

Related Questions