JSF中得到selectOneMenu的使用

来源:互联网 发布:tpshop源码 编辑:程序博客网 时间:2024/05/16 08:43

首先我在网页中

 

<h:form rendered="true">
     选择要设置的文件名称:
    
<h:selectOneMenu id="wj" required="true" binding="#{WjlcBean.wjMenu}">
         
<f:selectItems value="#{WjBean.notSetWj}" />
    
</h:selectOneMenu>
    
<h:panelGrid>
        
<h:panelGroup>
           
<h:commandButton value="设置文件流程" action="#{WjlcBean.addAction}" />
       
</h:panelGroup>
    
</h:panelGrid>
</h:form>

 给这个selectItems赋值时是这样的(WjlcBean.notSetWj),一个Java方法:

 

public ArrayList getNotSetWj() throws WorkflowWjException{
                             
    List notSetWj
=this.getWorkflowWjService().browserNotset();//这个从数据库中得到数据的list
    
//用迭代器遍历这个List
                     Iterator iWj=notSetWj.iterator();
    ArrayList aList
=new ArrayList();
    
while(iWj.hasNext()){
         WorkflowWj wjL
=(WorkflowWj)iWj.next();
                          
//这个就是selectItem的值,第一个是ID(不显示),第二个是value(显示的)
         SelectItem  itemNotSetWj=new SelectItem(wjL.getWjid(),wjL.getMc());
         aList.add(itemNotSetWj);
    }

    
return aList;
}

 

这时这个SelectOneMemu就有值了,但是怎么再得到它的值,费了好半天劲才弄出来,这要用到两个类UISelectItems和SelectItem,代码如下:

 

//得到选择的文件名称
        Iterator itawj = this.wjMenu.getChildren().iterator();        
        
while (itawj.hasNext()) {        
            UISelectItems sitwj 
= (UISelectItems) itawj.next();       
             
//又一次迭代,注意这里是getValue,还有返回是一个ArrayList     
            Iterator itawjItem = ((ArrayList) (sitwj.getValue())).iterator();        
            
while (itawjItem.hasNext()) {
                SelectItem ustwj 
= (SelectItem) itawjItem.next();
                
if ((ustwj.getValue().toString()).equals(this.wjMenu.getValue()
                        .toString())) 
{                
                    
//设置文件名称
                    newLcwjdy.setWjmc(ustwj.getLabel());
                }


            }

        }

这次多亏了同事的帮忙!!!!

 

 
原创粉丝点击