Thursday, 10 March 2016

SelectOneChoice ListofValues

In Select One Choice we can creat a list of values by
1.Model Driven.: Means the list coming from the database
2.Custom List:Means through a managed Bean we will add a list.



  1.We have to create a variable of type "JAVA.UTILL.LIST" and generate getters and setter for that variable.
  2.now that list should be a specific type of "SelectItem."
  3."javax.faces.model.SelectItem" is supported by af:SelectOneChoce
  4.List<SelectItem> variable_name;

NOTE: In order to create a list of values we have to create a object of list type
      eg: List<String> variable_name= new ArrayList<>();
          list.add("a");
          list.add("b");
          list.add("c");
  5.We have to add values in the list through getter method...

    public List<SelectItem> getvariable_name()
    {

     if(variable_name==null)
     {
 
      variable_name=new ArrayList<SelectItem>();  // here we are creating a object
      variable_name.add(new SelectItem("i1","Item 1"));
      variable_name.add(new SelectItem("i2","Item 2"));
      variable_name.add(new SelectItem("i3","Item 3"));

     }
     }

No comments:

Post a Comment