如何在BackBean中使用SelectMany 对象

来源:互联网 发布:网络销售怎么找客户聊 编辑:程序博客网 时间:2024/06/14 00:27

This page was made fast and I hope don't be a nuisance to someboby

首先我们定义backbean来管理我们的 selectMany "list" :

 <managed-bean>  <managed-bean-name>Manager</managed-bean-name> <managed-bean-class>demo.Manager</managed-bean-class>  <managed-bean-scope>request</managed-bean-scope> <managed-bean>

现在Manager类应该有个 SelectMany object来管理信息;

 

 

package demo;
import javax.faces.component.UISelectMany;
import javax.faces.component.UIComponent;

class Manager{
   
    private UISelectMany list;
       

      /*
       * Here we must create our list of objects
       * obviously we may add a cycle "while" or "for" 
       * if we wouldn't know the number of items
       */ 
    public UIComponentBase getList(){
      
         list=new UISelectMany();
         SelectItem item = new SelectItem"value""Description" );
         UISelectItem uiItem = new UISelectItem();
         uiItem.setValueitem );
         
         list.getChildren().adduiItem );
      
      return list;
    }

    public void setList(UIComponentBase list){
        this.list=(UISelectMany)list; 
    }
    
   public void actionListener(ActionEvent ev){
       
       Object obj [] = list.getSelectedValues();
       // obj is an array of string that contents the values of our selectItems
   }

}

 

JSP页面的代码如下: 

<h:selectManyMenu binding="#{Manager.list}">

如果你想使用CheckBox or a ListBox仅仅在JSF文件中该变标签就可以了.如 <h:selectManyCheckBox> by either <h:selectManyListbox> or <h:selectManyCheckbox>, it is great!!

WRITTEN BY JOSE HERNAN VALDES MURGUIA. CBBA-BOLIVIA.
Hitoriki in jsf's java's forum

 
原创粉丝点击