1

I have a problem in jsf panelgrid while populating data from arraylist.. I'm getting error as javax.el.PropertyNotFoundException: /facelet/crew/searchCrew.xhtml @14,95 value="#{searchCrewBean.searchCrewParam.staffNum}": Target Unreachable, 'searchCrewParam' returned null

please find my code below kindly help me ..

JSF code below:

<?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://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<h:body>
    <ui:composition template="/facelet/layout/mainlayout.xhtml">
    <ui:define name="content">
        <h:form>
            <h:panelGrid columns="7" border="2" title="Crew information"
                rendered="true">
                <f:facet name="header">
                    <h:panelGroup border="2">
                        <h:inputText value="Staffnum" size="6" />
                        <h:inputText value="Surname" size="10" maxlength="25" />
                        <h:inputText value="Age" size="2" />
                        <h:inputText value="Rank" size="3" />
                        <h:inputText value="Type" size="1" />
                        <h:inputText value="Scexpiry" size="10" />
                        <h:inputText value="Mailboxno" size="4" />
                    </h:panelGroup>
                <ui:repeat var="o" value="#{searchCrewBean.listOfSearchCrew}">
                    <h:panelGroup rendered="true">
                        <h:inputText id="staffnum" value="o.staffNum" size="6" />
                        <h:inputText id="surname" value="o.surName" size="10"
                            maxlength="25" />
                        <h:inputText id="age" value="o.age" size="2" />
                        <h:inputText id="rank" value="o.rank" size="3" />
                        <h:inputText id="type" value="o.type" size="1" />
                        <h:inputText id="scexpiry" value="o.scExpiry" size="10" />
                        <h:inputText id="mailboxno" value="o.mailBoxNo" size="4" />
                    </h:panelGroup>
                </ui:repeat>

            </h:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>
</h:body>
</html>

my backing bean here...

@ManagedBean(name="searchCrewBean")
public class SearchCrewBean {
    private ArrayList<Crew> listOfSearchCrew ;

        public ArrayList<Crew> getListOfSearchCrew() {
        return listOfSearchCrew;
    }

    public void setListOfSearchCrew(ArrayList<Crew> listOfSearchCrew) {
        this.listOfSearchCrew = listOfSearchCrew;
}

//business logic goes here to add listofcrew
    }

and my crew class here...

public class Crew {

private String staffNum;

private String surName;

private Integer age;

private String rank;

private Character type;

private String scExpiry;

private Long mailBoxNo;
}

@Akselwillgert I am loading the crew list as below private ArrayList listOfCrew ; private ArrayList listOfSearchCrew ;

public void loadCrew()
{
    listOfCrew = new ArrayList<Crew>();
    listOfCrew.add(new Crew("000212", "HATHELY", 70, "CPT",'T',"13.03.2013",Long.parseLong("1012")));
    listOfCrew.add(new Crew("000213", "MIKE", 52, "F/O",'T',"14.03.2013",Long.parseLong("1013")));
    listOfCrew.add(new Crew("000214", "JOHN", 45, "S/O",'T',"15.03.2013",Long.parseLong("1014")));
    listOfCrew.add(new Crew("000215", "NOTE", 35, "CPT",'T',"16.03.2013",Long.parseLong("1015")));
    listOfCrew.add(new Crew("000216", "KARTHIK", 27, "CPT",'T',"17.03.2013",Long.parseLong("1016")));
    listOfCrew.add(new Crew("000217", "JESSIE", 30, "PUR",'C',"18.02.2013",Long.parseLong("1017")));
    listOfCrew.add(new Crew("000218", "LISSA", 29, "F/A",'C',"19.02.2013",Long.parseLong("1018")));
    listOfCrew.add(new Crew("000219", "MARKUS", 40, "CPT",'T',"13.03.2013",Long.parseLong("1019")));
    listOfCrew.add(new Crew("000220", "JONTHAN", 46, "F/O",'T',"13.03.2013",Long.parseLong("1020")));
    listOfCrew.add(new Crew("000221", "BATMAN", 33, "S/O",'T',"13.03.2013",Long.parseLong("1021")));

}

Still facing the same issue...

@ManagedBean(name="searchCrewBean")
public class SearchCrewBean {

private SearchCrew searchCrewParam;
}


public class SearchCrew {

private String staffNum;

private String surName;

private String rank;
//getters and setters goes here..
}
nallskarthi
  • 281
  • 1
  • 8
  • 19

2 Answers2

0

So if you have the loadCrew method in the same class, try this

public ArrayList<Crew> getListOfSearchCrew() {
  if( listOfSearchCrew == null ) {
     loadCrew() ;
   }
   return listOfSearchCrew;
}
vels4j
  • 11,208
  • 5
  • 38
  • 63
  • just put a log in getListOfSearchCrew() to ensure whether its called or not. It must be called. Where did u call that load method ? – vels4j Nov 24 '12 at 19:27
  • I am calling when an action trigger for a commandButton .. as follows.. first loaded crewlist and then am calling method for searching findcrew .. `public String search() { if(listOfCrew == null) { loadCrew(); } listOfSearchCrew = findCrew(); if(listOfSearchCrew.size()>0) { return "success" ; } else return "failure" ; }` – nallskarthi Nov 24 '12 at 19:33
0

I Have made one mistake here, In backing bean I forgot to instantiate the search crew param as below @ManagedBean(name="searchCrewBean") public class SearchCrewBean { private SearchCrew searchCrewParam; // old line private SearchCrew searchCrewParam= new SearchCrew(); // newline }

And for displaying arraylist in jsf page I have used h:dataTable tag from jsf it is helpful. refer http://www.mkyong.com/jsf2/jsf-2-datatable-example/

nallskarthi
  • 281
  • 1
  • 8
  • 19