Results 1 to 2 of 2
  1. #1
    hornet7288 is offline Member
    Join Date
    Sep 2016
    Posts
    32
    Rep Power
    0

    Default Error help:target unreachable

    I am brand new to JSF and have to do a small project for class that's due next week. I already have completed the same project in JSP and I now have to do the same thing in JSF. I cannot seem to figure out why I keep getting the following error:

    /index.xhtml @20,66 value="#{staff.ID}": Target Unreachable, identifier 'staff' resolved to null

    I've tried all kinds of different scopes and have had no luck. Really kind of lost on this one. This project is a small web application which has a form with various fields. When completed I should be able to insert, update and view entries with staff information into a database.

    xhtml file
    Java Code:
    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://xmlns.jcp.org/jsf/html">
        <h:head>
            <title>JSF Staff Info</title>
        </h:head>
        <h:body>
            <h:form>
                <table>
                    <tr>
                        <td>
                            <fieldset>
                                <legend>Staff Information</legend>
                                <p>
                                    <h:outputLabel value ="ID:"/>&nbsp;
                                    <h:inputText id="IDInputText" required="true"
                                                 requiredMessage="ID field required"
                                                 size="2"
                                                 value="#{staff.ID}">
                                    </h:inputText>
                                </p>
                                <p>
                                    <h:outputLabel value ="Last Name:"/>&nbsp;
                                    <h:inputText id="lastNameInputText" 
                                                 size="15"
                                                 value="#{staff.lastName}">
                                    </h:inputText>&nbsp;
                                    <h:outputLabel value ="First Name:"/>&nbsp;
                                    <h:inputText id="firstNameInputText" 
                                                 size="15"
                                                 value="#{staff.firstName}">
                                    </h:inputText>&nbsp;
                                    <h:outputLabel value ="Middle:"/>&nbsp;
                                    <h:inputText id="MIInputText" 
                                                 size="2"
                                                 value="#{staff.MI}">
                                    </h:inputText>
                                </p>
                                <p>
                                    <h:outputLabel value ="Address:"/>&nbsp;
                                    <h:inputText id="addressInputText" 
                                                 size="25"
                                                 value="#{staff.address}">
                                    </h:inputText>
                                </p>
                                <p>
                                    <h:outputLabel value ="City:"/>&nbsp;
                                    <h:inputText id="cityInputText" 
                                                 size="15"
                                                 value="#{staff.city}">&nbsp;
                                    </h:inputText>&nbsp;
                                    <h:outputLabel value ="State:"/>&nbsp;
                                    <h:inputText id="stateInputText" 
                                                 size="2"
                                                 value="#{staff.state}">
                                    </h:inputText>
                                </p>
                                <p>
                                    <h:outputLabel value ="Telephone:"/>&nbsp;
                                    <h:inputText id="telephoneInputText" 
                                                 size="15"
                                                 value="#{staff.telephone}">
                                    </h:inputText>
                                </p>
                                <p>
                                    <h:commandButton type="submit" action="#{staff.storeStaff()}" value ="Insert"/>&nbsp;
                                    <h:commandButton type="submit"  value ="View"/>&nbsp;
                                    <h:commandButton type="submit"  value ="Update"/>&nbsp;
                                    <h:commandButton type="reset" action="index" value ="Clear"/>
                                </p>
                                <p>
                                    <h:outputText style="color: red" 
                                                  value="#{staff.response}" /> 
                                </p>
                            </fieldset>
                        </td>
                    </tr> 
                </table>
            </h:form>
        </h:body>
    </html>
    Last edited by hornet7288; 02-27-2017 at 07:07 AM.

  2. #2
    hornet7288 is offline Member
    Join Date
    Sep 2016
    Posts
    32
    Rep Power
    0

    Default Re: Error help:target unreachable

    java managed bean file code:

    Java Code:
    package Chapter;
    
    import javax.inject.Named;
    import java.io.*;
    import java.sql.*;
    import javax.enterprise.context.SessionScoped;
    import javax.faces.bean.ViewScoped;
    
    
    @Named(value = "staff")
    
    @ViewScoped
    public class StaffInfoJSFBean implements Serializable {
    
        private String ID;
        private String lastName;
        private String firstName;
        private String mi;
        private String address;
        private String city;
        private String state;
        private String telephone;
        private String response;
    
        private PreparedStatement pstmt;
    
        public String getID() {
            return ID;
        }
    
        public void setID(String ID) {
            this.ID = ID;
        }
    
        public String getLastName() {
            return lastName;
        }
    
        public void setName(String lastName) {
            this.lastName = lastName;
        }
    
        public String getFirstName() {
            return firstName;
        }
    
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
    
        public String getMI() {
            return mi;
        }
    
        public void seMI(String mi) {
            this.mi = mi;
        }
    
        public String getAddress() {
            return address;
        }
    
        public void setAddress(String address) {
            this.address = address;
        }
    
        public String getCity() {
            return city;
        }
    
        public void setCity(String city) {
            this.city = city;
        }
    
        public String getState() {
            return state;
        }
    
        public void setState(String state) {
            this.state = state;
        }
    
        public String getTelephone() {
            return telephone;
        }
    
        public void setTelephone(String telephone) {
            this.telephone = telephone;
        }
    
        public String getResponse() {
            return response;
        }
    
        public void setResponse(String response) {
            this.response = response;
        }
    
        public StaffInfoJSFBean() {
            initializeJdbc();
        }
    
        private void initializeJdbc() {
            try {
    // Load the JDBC driver
                Class.forName("com.mysql.jdbc.Driver");
                System.out.println("Driver loaded");
    // Establish a connection
    
                
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/staffRecord", "user", "password");
                System.out.println("Database connected");
    // Create a Statement
                pstmt = conn.prepareStatement("insert into staffinfo "
                        + "(ID, lastName, firstName, mi, address, city, state, telephone) "
                        + "values (?, ?, ?, ?, ?, ?, ?, ?)");
            } catch (ClassNotFoundException | SQLException ex) {
            }
        }
    
        public void storeStaff() throws SQLException {
            try {
                System.out.println("IN STORE STAFF");
                pstmt.setString(1, ID);
                pstmt.setString(2, lastName);
                pstmt.setString(3, firstName);
                pstmt.setString(4, mi);
                pstmt.setString(5, address);
                pstmt.setString(6, city);
                pstmt.setString(7, state);
                pstmt.setString(8, telephone);
                pstmt.executeUpdate();
                response = firstName + " " + lastName + " is now stored in the database";
            } catch (Exception ex) {
                response = ex.getMessage();
            }
        }
    }
    Last edited by hornet7288; 02-27-2017 at 05:28 PM.

Similar Threads

  1. Unreachable statement. please take a look.
    By gbonecapone in forum Advanced Java
    Replies: 1
    Last Post: 05-22-2013, 01:52 PM
  2. Unreachable statement???
    By dangolf in forum New To Java
    Replies: 5
    Last Post: 02-12-2013, 10:55 AM
  3. Replies: 2
    Last Post: 03-26-2012, 04:27 PM
  4. Strange unreachable statement error...
    By silafirion in forum New To Java
    Replies: 5
    Last Post: 12-11-2010, 05:05 AM
  5. Error Message:Invocation Target Exception
    By Deepa in forum New To Java
    Replies: 1
    Last Post: 11-27-2008, 07:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •