如何在 JSF 2.0 的 panelGrid 中填充数组列表



我在从arraylist填充数据时在jsf panelgrid中遇到了问题。我收到错误javax.el.PropertyNotFoundException: /facelet/crew/searchCrew.xhtml @14,95 value="#{searchCrewBean.searchCrewParam.staffNum}": Target Unreachable, 'searchCrewParam' returned null

请在下面找到我的代码,请帮助我..

JSF 代码如下:

<?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>

我的背豆在这里...

@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
    }

还有我的船员班在这里...

公共类船员 {

private String staffNum;
private String surName;
private Integer age;
private String rank;
private Character type;
private String scExpiry;
private Long mailBoxNo;
}

@Akselwillgert我正在加载船员名单,如下所示 私人阵列列表列表船员 ; 私有数组列表列表搜索船员 ;

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")));
}

仍然面临同样的问题...

@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..
}

因此,如果您在同一类中有 loadCrew 方法,请尝试此操作

public ArrayList<Crew> getListOfSearchCrew() {
  if( listOfSearchCrew == null ) {
     loadCrew() ;
   }
   return listOfSearchCrew;
}

我在这里犯了一个错误,在支持bean时,我忘了实例化搜索人员参数,如下所示 @ManagedBean(name="searchCrewBean") public class SearchCrewBean { private SearchCrew searchCrewParam; // old line private SearchCrew searchCrewParam= new SearchCrew(); // newline }

为了在 jsf 页面中显示数组列表,我使用了 jsf 中的h:dataTable标签,这很有帮助。请参阅 http://www.mkyong.com/jsf2/jsf-2-datatable-example/

相关内容

  • 没有找到相关文章

最新更新