Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.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 在h:SelectOne菜单中选择默认值_Jsf_Seam - Fatal编程技术网

Jsf 在h:SelectOne菜单中选择默认值

Jsf 在h:SelectOne菜单中选择默认值,jsf,seam,Jsf,Seam,我试图显示一个select one菜单,这样默认选择的值就是城市的名称(如果变量“item”中有一个城市)。如果没有值,我想显示“未选择任何内容” 我试着做一些事情,比如: <h:selectOneMenu value="#{(item.city!=null)?itemTmp.city.name:''}"> <s:selectItems .... /> </h:selectOneMenu> 但是会抛出一个解析异常。如果有默认值,如何在h:sele

我试图显示一个select one菜单,这样默认选择的值就是城市的名称(如果变量“item”中有一个城市)。如果没有值,我想显示“未选择任何内容”

我试着做一些事情,比如:

<h:selectOneMenu value="#{(item.city!=null)?itemTmp.city.name:''}">
    <s:selectItems .... />
</h:selectOneMenu>


但是会抛出一个解析异常。如果有默认值,如何在
h:selectOneMenu
中设置默认值?如果相反,如何设置“no selection”(无选择)?

如果要显示空值,则必须在列表中添加一个带有空字符串或任何其他类似内容的选择项--“选择城市--”

    cityItemList.add(new SelectItem(""));  
// or cityItemList.add(new SelectItem("--Select City--"));
    cityItemList.add(new SelectItem("Greenville"));
    cityItemList.add(new SelectItem("Franklin"));
    cityItemList.add(new SelectItem("Clinton"));
    cityItemList.add(new SelectItem("Fairview"));

作为更好的选择,为什么不在索引0处使用类似于
selectcity
,这样就不需要处理
null