0

I hope you are doing well. I just got this error, I don't know its source. Could someone help me please. I create a managedBean and give it a name, then call it and JSF code followed by the method within the ManagedBean. But I don't see the source of the error.

import java.sql.Timestamp;

public class Track {

    private int TrackID;
    private String Employee;
    private String note;
    private Timestamp timestamp;
    private String DocumentID;

    public Track(int TrackID, String Employee, String note, Timestamp timestamp, String DocumentID) {
        this.TrackID = TrackID;
        this.Employee = Employee;
        this.note = note;
        this.timestamp = timestamp;
        this.DocumentID = DocumentID;
    }

    public int getTrackID() {
        return TrackID;
    }

    public void setTrackID(int TrackID) {
        this.TrackID = TrackID;
    }

    public String getEmployee() {
        return Employee;
    }

    public void setEmployee(String Employee) {
        this.Employee = Employee;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public Timestamp getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Timestamp timestamp) {
        this.timestamp = timestamp;
    }

    public String getDocumentID() {
        return DocumentID;
    }

    public void setDocumentID(String DocumentID) {
        this.DocumentID = DocumentID;
    }
}

Here is the Bean:

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="searchBean")
@SessionScoped 
public class SearchBean implements Serializable{

    private String SearchQuery;

    public ArrayList<Track> find(){

        ArrayList array = new ArrayList();

        Connection con = null;
        PreparedStatement ps = null;
        try {
            con = Database.getConnection();
            ps = con.prepareStatement("Select * from track where documentID like ?");
            ps.setString(1, SearchQuery);
            ResultSet rs = ps.executeQuery();

            if (rs!=null) {

                while(rs.next()){
                Track track = new Track();
                track.setTrackID(rs.getInt(1));
                track.setNote(rs.getString(2));
                track.setEmployee(rs.getString(3));
                track.setTimestamp(rs.getTimestamp(4));

                array.add(track);
                }
            return array;    
            }

        }catch(SQLException e){
            e.printStackTrace();
        }  

        return null;

    }

    public String getSearchQuery() {
        return SearchQuery;
    }

    public void setSearchQuery(String SearchQuery) {
        this.SearchQuery = SearchQuery;
    }

    public String SearchBean(){

        return SearchQuery;

    }

}

JSF code:

    <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title> Title</title>
    </h:head>
    <h:body>
        <p:layout fullPage="true" >
            <p:layoutUnit position="center" >
                <h:form>
                <p:panel id="pan1" header="input" >
                    <p:panelGrid columns="2" >
                        <p:column>
                            <p:outputLabel id="lbll" for="Search" value="Track :" />
                        </p:column> 
                        <p:column>
                            <p:inputText id="Search" value="#{searchBean.searchQuery}" />
                        </p:column>
                        <f:facet name="footer" >
                            <p:commandButton id="btn" value="Search" action="#{searchBean.find()}" update="table" />
                        </f:facet>
                    </p:panelGrid>
                </p:panel>
                    <p:panel id="pan2" header="Result" >
                        <p:dataTable id="table" var="track" value="#{searchBean.find}" >

                            <p:column>
                                <p:outputLabel id="ID" value="#{track.TrackID}"/>
                            </p:column>
                            <p:column>
                                <p:outputLabel id="Employee" value="#{track.Employee}"/>
                            </p:column>
                            <p:column>
                                <p:outputLabel id="Note" value="#{track.note}"/>
                            </p:column>
                            <p:column>
                                <p:outputLabel id="Timestamp" value="#{track.Timestamp}"/>
                            </p:column>


                        </p:dataTable> 
                </p:panel>
                </h:form>    
            </p:layoutUnit>
        </p:layout>
    </h:body>
</html>

Here is the error that I got:

    WARNING [http-nio-8080-exec-95] com.sun.faces.lifecycle.ProcessValidationsPhase.execute /index.xhtml @20,90 value="#{searchBean.searchQuery}": Target Unreachable, identifier 'searchBean' resolved to null
 javax.el.PropertyNotFoundException: /index.xhtml @20,90 value="#{searchBean.searchQuery}": Target Unreachable, identifier 'searchBean' resolved to null

Thank you so much guys, really appreciate it.

Kukeltje
  • 11,924
  • 4
  • 19
  • 44
  • Tried posting the title in a search engine? Why not? – Kukeltje May 18 '20 at 05:32
  • See [ask]... about the searching... Errors make great search engine queries – Kukeltje May 18 '20 at 07:14
  • And off-topic, but very important: https://stackoverflow.com/questions/30639785/jsf-controller-service-and-dao (are you using an old or bad tutorial or is this a school/student assignment?) – Kukeltje May 18 '20 at 07:43

0 Answers0