Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Cannot set class fields using textInput

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cannot set class fields using textInput

    when the validation function for a user's login runs, the username and password fields are null. i have written the code according to many examples that i have seen on the internet. please help me understand why these fields are not being set.

    also, when i run this app in a browser, the fields literally say #{Login.username}, and #{Login.password} instead of being blank like in other people's examples and tutorials. i assume it is a symptom of the problem here.

    thanks in advance
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
     
        <context-param>
            <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
            <param-value>server</param-value>
        </context-param>
     
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.jsf</url-pattern>
        </servlet-mapping>
     
    </web-app>
     
    <faces-config>
     
        <managed-bean>
            <managed-bean-name>Login</managed-bean-name>
            <managed-bean-class>Security.Login</managed-bean-class>
            <managed-bean-scope>request</managed-bean-scope>
     
        </managed-bean>
     
        <navigation-rule>
            <from-view-id>/Login.jsp</from-view-id>
     
            <navigation-case>
                <from-action>#{Login.ValidateLogin}</from-action>
                <from-outcome>success</from-outcome>
                <to-view-id>/LoginValid.jsp</to-view-id>
            </navigation-case>
     
           <navigation-case>
                <from-action>#{Login.ValidateLogin}</from-action>
                <from-outcome>failure</from-outcome>
                <to-view-id>/LoginInvalid.jsp</to-view-id>
            </navigation-case>
     
        </navigation-rule>
     
    </faces-config>
     
    <f:view>
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
                <title>JSP Page</title>
            </head>
     
            <body>
                <h:form>
                    <table>
                        <tr>
                            <td><h:outputText value="Username: "/></td>
                            <td><h:inputText id="username" required="true" value="#{Login.username}" /></td>
                        </tr>
     
                        <tr>
                            <td><h:outputText value="Password: "/></td>
                            <td><h:inputText id="password" required="true" value="#{Login.password}"/></td>
                        </tr>
     
                        <tr>
                            <td>&nbsp;</td>
                            <td><h:commandButton value="login" action="#{Login.ValidateLogin}"/></td>
                        </tr>
                    </table>
                </h:form>
            </body>
     
        </html>
    </f:view>
     
    package Security;
     
    public class Login {
     
        private String username;
        private String password;
     
        public Login() {} // Inline Constructor for Login class
     
        public void setUsername(String username) { this.username = username; }
        public void setPassword(String password) { this.password = password; }
     
        public String ValidateLogin() {
     
            if("ianmcdavid".equals(username) && "cole".equals(password)) {
                return "success";
            }
     
            else {
                return "failure";
            }
        }
    }
    Last edited by copeg; August 26th, 2010 at 08:49 AM. Reason: Please use the code tags


Similar Threads

  1. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM
  2. problem with data access when a class call another class
    By ea09530 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 4th, 2010, 05:20 PM
  3. Putting text fields in an array
    By Movies32 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 10th, 2010, 06:46 PM
  4. Validating fields in a js shopping cart
    By rockc in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 10th, 2010, 02:37 PM
  5. Static fields and inheritance
    By helloworld922 in forum Java Programming Tutorials
    Replies: 1
    Last Post: January 22nd, 2010, 03:02 AM