表单提交后,值为null

时间:2016-03-26 20:40:24

标签: jsf jsf-2.2

I want to create simple login form:

    <h:body>
            <section class="container login-form">
                <section>
                    <h:form role="login">
                        <img src="images/logo.png" alt="" class="img-responsive" />

                        <div class="form-group">
                            <h:inputText pf:type="email" pf:name="email" required="true" styleClass="form-control" pf:placeholder="Email address" value="#{login.user}"/>
                        </div>

                        <div class="input-group">
                            <h:inputSecret pf:type="password" pf:name="password" required="true" class="form-control" pf:placeholder="Password" value="#{login.password}" autocomplete="off"/>

                            <span class="input-group-btn">
                                <button class="btn btn-default" type="button" id="tooltip" data-toggle="tooltip" data-placement="top" title="Forgot password ?">?</button>
                            </span>
                        </div>
                        <h:commandLink type="submit" pf:name="go" class="btn btn-primary btn-block button-layout" action="#{login.userAuthanticate}">Login Now</h:commandLink>

                        Not yet a member ? <h:commandLink class="link-layout">Register now</h:commandLink>
                    </h:form>
                </section>
            </section>

            <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
            <script src="resources/bootstrap/js/bootstrap.min.js"></script>

            <script>
                <!--
            $(document).ready(function () {
                    $('#tooltip').tooltip();
                });
    -->
            </script>

        </h:body>

**Managed bean**


    @Named
    @ViewScoped
    public class Login implements Serializable
    {
        private String user;
        private String password;

        public void userAuthanticate() throws IOException
        {
                System.out.println(">>>>>>>>>>>>>>>>> user " + user + "   >>>>>>>>>>>>>>>>>>> password " + password);
                FacesContext.getCurrentInstance().getExternalContext().redirect("pricing_calculator.xhtml");
        }
    .......
    }

When I click button Login I get null for outpu    


Do you have any idea why username and password are null?
Can I remove some component from the code which is not used?

**context.xml**

    <?xml version="1.0" encoding="UTF-8"?>
    <Context antiJARLocking="true" path="/Crm_site"/>

**beans.xml**

    <?xml version="1.0" encoding="UTF-8"?>
    <beans
        xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
        version="1.1" bean-discovery-mode="all">
    </beans>

**context.xml**

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/tomcat-test">
    <Resource
        name="BeanManager"
        auth="Container"
        type="javax.enterprise.inject.spi.BeanManager"
        factory="org.jboss.weld.resources.ManagerObjectFactory"
    />
</Context>

面-consig.xml

<?xml version="1.0"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
            http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
              version="2.2">
</faces-config>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    version="3.1">

JSF核心库

<dependency>
            <groupId>javax.faces</groupId>
            <artifactId>javax.faces-api</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.faces</artifactId>
            <version>2.2.13</version>
            <scope>runtime</scope>
        </dependency>

我认为这个问题的原因是xml文件配置库的版本错误。

我也试过使用Mojarra 2.3.0-m05,但我无法使用此版本启动应用程序。

0 个答案:

没有答案