Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JSF中创建多个依赖/级联选择组件_Jsf_Hierarchy_Selectonemenu_Cascading_Ajax Update - Fatal编程技术网

在JSF中创建多个依赖/级联选择组件

在JSF中创建多个依赖/级联选择组件,jsf,hierarchy,selectonemenu,cascading,ajax-update,Jsf,Hierarchy,Selectonemenu,Cascading,Ajax Update,我正在尝试制作4个相关/级联选择组件。在这个问题中,选择组件恰好是,但这当然适用于任何其他类型的选择组件,例如,,等等 当用户从第一个菜单中选择项目时,第二个菜单将显示相关数据,当用户从第二个菜单中选择项目时,第三个菜单将显示相关数据,依此类推 用户将只看到第一个菜单上的项目,其他项目将为空。如果他在第一个菜单上选择一个项目,第二个菜单将显示数据,但第三个和第四个菜单将保持空白,依此类推。用户最终必须从所有4个菜单中选择条目 <h:selectOneMenu id="first" valu

我正在尝试制作4个相关/级联选择组件。在这个问题中,选择组件恰好是
,但这当然适用于任何其他类型的选择组件,例如
,等等

当用户从第一个菜单中选择项目时,第二个菜单将显示相关数据,当用户从第二个菜单中选择项目时,第三个菜单将显示相关数据,依此类推

用户将只看到第一个菜单上的项目,其他项目将为空。如果他在第一个菜单上选择一个项目,第二个菜单将显示数据,但第三个和第四个菜单将保持空白,依此类推。用户最终必须从所有4个菜单中选择条目

<h:selectOneMenu id="first" value="#{nodes.selectState"}>
    <f:selectItems value="#{nodes.stateList}"/>
    <f:ajax render="second">
</h:selectOneMenu>
<h:selectOneMenu id="second" value="#{nodes.selectCity"}>
    <f:selectItems value="#{nodes.cityList}"/>
    <f:ajax render="third">
</h:selectOneMenu>
<h:selectOneMenu id="third" value="#{nodes.selectRegion"}>
    <f:selectItems value="#{nodes.regionList}"/>
    <f:ajax render="fourth">
</h:selectOneMenu>
<h:selectOneMenu id="fourth" value="#{nodes.selectStation"}>
    <f:selectItems value="#{nodes.stationList}"/>
</h:selectOneMenu>

节点bean

private String selectState; //+setters, getters
private String selectCity; //+setters, getters
private String selectRegion; //+setters, getters
private String selectStation; //+setters, getters
private List<SelectItem> stateList; //+setters, getters
private List<SelectItem> cityList; //+setters, getters
private List<SelectItem> regionList; //+setters, getters
private List<SelectItem> stationList; //+setters, getters

public getStateList(){
    stateList= new ArrayList<SelectItem>();
    stateList.add(new SelectItem("A"));
}

public getCityList(){
    CityList= new ArrayList<SelectItem>();
    if(selectState.equals("A")){
        CityList.add(new SelectItem("B"));
    }
}

public getRegionList(){
    RegionList= new ArrayList<SelectItem>();
    if(selectCity.equals("B")){
        RegionList.add(new SelectItem("C"));
   }
}

public getStationList(){
    StationList= new ArrayList<SelectItem>();
    if(selectRegion.equals("C")){
        StationList.add(new SelectItem("D"));
    }
}
私有字符串选择状态//+二传手
私人城市//+二传手
私有字符串选择区域//+二传手
专用字符串选择站//+二传手
私人名单国家名单//+二传手
私人名单城市名单//+二传手
私有列表区域列表//+二传手
私有列表统计列表//+二传手
公共getStateList(){
stateList=新的ArrayList();
stateList.add(新建SelectItem(“A”));
}
公共getCityList(){
CityList=newarraylist();
如果(选择state.equals(“A”)){
城市列表。添加(新选择项(“B”);
}
}
公共getRegionList(){
RegionList=新的ArrayList();
如果(选择city.equals(“B”)){
RegionList.add(新选择项(“C”);
}
}
公共getStationList(){
StationList=新的ArrayList();
if(选择region.equals(“C”)){
StationList.add(新建SelectItem(“D”));
}
}

它只适用于前两个菜单。其他两个菜单获得
null
值。

试试这个,它可能会对您有所帮助

通过使用--Select City--、--Select Region--、--Select Station--来避免空指针异常

    public getStateList(){
    stateList= new ArrayList<SelectItem>();
    stateList.add(new SelectItem("A"));
    }

    public getCityList(){
    CityList= new ArrayList<SelectItem>();
    if(selectState.equals("A"))
    {
      CityList.add(new SelectItem("B"));
    }
    else
    {
      CityList.add(new SelectItem("--Select City--"));
      selectCity = "--Select City--";
    }

    public getRegionList(){
    RegionList= new ArrayList<SelectItem>();
    if(selectCity.equals("B"))
    {
      RegionList.add(new SelectItem("C"));
    }
    else
    {
      RegionList.add(new SelectItem("--Select Region--"));
      selectRegion = "--Select Region--";
    }
    }

    public getStationList(){
    StationList= new ArrayList<SelectItem>();
    if(selectRegion.equals("C"))
    {
       StationList.add(new SelectItem("D"));
    }
    else
    {
      StationList.add(new SelectItem("Select Station"));
      selectStation = "--Select Station--";
    }
    }
public getStateList(){
stateList=新的ArrayList();
stateList.add(新建SelectItem(“A”));
}
公共getCityList(){
CityList=newarraylist();
如果(选择state.equals(“A”))
{
城市列表。添加(新选择项(“B”);
}
其他的
{
添加(新的SelectItem(“--selectcity--”);
selectCity=“--选择城市--”;
}
公共getRegionList(){
RegionList=新的ArrayList();
如果(选择city.equals(“B”))
{
RegionList.add(新选择项(“C”);
}
其他的
{
RegionList.add(新的SelectItem(“--selectregion--”);
selectRegion=“--选择区域--”;
}
}
公共getStationList(){
StationList=新的ArrayList();
if(选择region.equals(“C”))
{
StationList.add(新建SelectItem(“D”));
}
其他的
{
StationList.add(新建SelectItem(“选择站点”));
selectStation=“--选择电台--”;
}
}

试试这个,它可能会对你有所帮助

通过使用--Select City--、--Select Region--、--Select Station--来避免空指针异常

    public getStateList(){
    stateList= new ArrayList<SelectItem>();
    stateList.add(new SelectItem("A"));
    }

    public getCityList(){
    CityList= new ArrayList<SelectItem>();
    if(selectState.equals("A"))
    {
      CityList.add(new SelectItem("B"));
    }
    else
    {
      CityList.add(new SelectItem("--Select City--"));
      selectCity = "--Select City--";
    }

    public getRegionList(){
    RegionList= new ArrayList<SelectItem>();
    if(selectCity.equals("B"))
    {
      RegionList.add(new SelectItem("C"));
    }
    else
    {
      RegionList.add(new SelectItem("--Select Region--"));
      selectRegion = "--Select Region--";
    }
    }

    public getStationList(){
    StationList= new ArrayList<SelectItem>();
    if(selectRegion.equals("C"))
    {
       StationList.add(new SelectItem("D"));
    }
    else
    {
      StationList.add(new SelectItem("Select Station"));
      selectStation = "--Select Station--";
    }
    }
public getStateList(){
stateList=新的ArrayList();
stateList.add(新建SelectItem(“A”));
}
公共getCityList(){
CityList=newarraylist();
如果(选择state.equals(“A”))
{
城市列表。添加(新选择项(“B”);
}
其他的
{
添加(新的SelectItem(“--selectcity--”);
selectCity=“--选择城市--”;
}
公共getRegionList(){
RegionList=新的ArrayList();
如果(选择city.equals(“B”))
{
RegionList.add(新选择项(“C”);
}
其他的
{
RegionList.add(新的SelectItem(“--selectregion--”);
selectRegion=“--选择区域--”;
}
}
公共getStationList(){
StationList=新的ArrayList();
if(选择region.equals(“C”))
{
StationList.add(新建SelectItem(“D”));
}
其他的
{
StationList.add(新建SelectItem(“选择站点”));
selectStation=“--选择电台--”;
}
}

将bean放在视图范围内,去掉getter方法中的任何业务逻辑

bean必须放在视图范围内,以便记住所有以前的选择和新的可用项,否则当JSF需要根据以前的选择中预先填充的可用项列表验证所选项时,或者当属性取决于s仅在以前的请求中设置

getter方法可能不包含任何业务逻辑,因为它们也将在验证阶段被调用。您应该使用
根据更改执行业务逻辑。您应该在侦听器方法中还显式清除子选择组件的选定值。您可以使用
更新子选择组件的内容

因此,因此:


@Named
@视域
公共类节点{
私有字符串selectedState;//getter+setter
私有字符串selectedCity;//getter+setter
私有字符串selectedRegion;//getter+setter
私有字符串selectedStation;//getter+setter
私有列表可用属性;//getter(不需要setter!)
私有列表可用性;//getter(不需要setter!)
私有列表可用区域;//getter(不需要setter!)
私有列表可用状态;//getter(不需要setter!)
@EJB
私人服务;
@施工后
公共void init(){
availableStates=someService.listStates();
}
公共无效更改状态(AjaxBehaviorEvent事件){
AvailableRecities=someService.listCities(selectedState);
selectedCity=selectedRegion=selectedStation=null;
availableRegions=availableStations=null;
}
公共无效变更城市(AjaxBehaviorEvent事件){
可用区域=