What's JAVA ?

发现在我走近java之后,感觉自己什么都不会了!
posts - 13, comments - 7, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

JSF SelectItems 使用

Posted on 2005-12-29 00:09 Eddie Lee 阅读(3085) 评论(2)  编辑  收藏 所属分类: JSF
jsf提供了<h:selectOneMenu>标签,来定义单选下拉框,直接写在jsp的文件里的做法,很简单,不写了。

在托管Bean里初始化这个标签的时候,可以使用SelectItem[] 数组类型,也可以使用List 、Map等类型。

具体做法如下:
private List<SelectItem> okItems = null;
    
/**
     * 
@return Returns the okItems.
     
*/

public List < SelectItem > getOkItems ( )
    
{
        
this.okItems = new LinkedList< SelectItem >();
        
this.okItems.add(new SelectItem("a","aaa"));
        
this.okItems.add(new SelectItem("b","bbb"));
        
return okItems ;
    }

然后在jsp页面中:
<h:selectOneMenu id="sortpid" value="#{booksort.sortPid}">
    
<f:selectItems value="#{booksort.okItems}" />
</h:selectOneMenu>

selectItems他拥有一个value这个属性,赋值为托管Bean里的初始化下拉框的那个属性,也就是okItems。

评论

# re: JSF SelectItems 使用  回复  更多评论   

2006-08-29 17:49 by cxm
private List<SelectItem> okItems = null;
时提示SelectItem cannot be resolved to a type

# re: JSF SelectItems 使用  回复  更多评论   

2006-08-29 17:53 by cxm
小弟初学JSF,能不能用MSN加上我,我的MSN是cyou007@hotmail.com

只有注册用户登录后才能发表评论。


网站导航: