Forum Stats

  • 3,873,351 Users
  • 2,266,538 Discussions
  • 7,911,514 Comments

Discussions

How to autoselect the selectmanychoice's "All" option

user8696578
user8696578 Member Posts: 483
edited Jul 25, 2013 5:31AM in JDeveloper and ADF


Hi ADF Experts,

I have a requirement on selection of a checkbox the below SelectManyCheckBox's "ALL" option is selected. How to handle the "ALL" option.

Best Regards,

Rahul

Tagged:
«1

Answers

  • Arunkumar Ramamoorthy-Oracle
    Arunkumar Ramamoorthy-Oracle Member Posts: 5,880 Employee

    Rahul,

    Always mention your JDev version. Your usecase is unclear. Can you elaborate with an example?

    -Arun

  • user8696578
    user8696578 Member Posts: 483

    Hi Arun,

    Jdev Version is 11.1.1.7.0. Use case is I have a checkbox and a selectmanychoice. Whenever the user selects the checkbox,

    the "ALL" option in the selectmanychoice is selected automatically.

    Thanks,

    Rahul


  • Arunkumar Ramamoorthy-Oracle
    Arunkumar Ramamoorthy-Oracle Member Posts: 5,880 Employee

    How are you populating the selectManyChoice? Is it bound to an Array in your bean? If yes, add the value of the ALL option to the array in the ValueChangeLisetner of the checkbox and ppr the selectManyChoice component.

    -Arun

  • user8696578
    user8696578 Member Posts: 483

    Hi Arun,

    Thanks for the response. Yes thats what I doing. I will post the answer once done.

    Thanks,

    Rahul

  • user8696578
    user8696578 Member Posts: 483

    Hi Arun,

    Right now I am able to populate the selectmanychoice programmatically. And on value change listener of the checkbox I am able to get all the values. But I want to select all the values of the selectmanychoice(on click of checkbox .i.e true). Following is the code snippet.

    Can you suggest how can I select all the values.

    <af:selectBooleanCheckbox text="selectBooleanCheckbox 1" label="Label 1"

              valueChangeListener="#{viewScope.StatusBean.statusValueChange}"           autoSubmit="true"       id="sbc1" binding="#{viewScope.StatusBean.status}"/>

      <af:selectManyChoice label="Options" id="smc1"

                    binding="#{viewScope.StatusBean.choiceItem}">

          <af:forEach items="#{viewScope.StatusBean.itemList}" var="item" >

          <af:selectItem value="item" id="si4"

                       label="#{item.value}"/>

           </af:forEach>           

      </af:selectManyChoice>

    public class StatusBean {
        private RichSelectBooleanCheckbox status;
        private RichSelectManyChoice choiceItem;
        private List<SelectItem> itemList;
        private List<SelectItem> item;

        public StatusBean() {
            super();
            itemList = new ArrayList<SelectItem>();
            itemList.add(new SelectItem("Mango","Mango"));
            itemList.add(new SelectItem("Guava","Guava"));
            itemList.add(new SelectItem("Orange","Orange"));
            itemList.add(new SelectItem("Banana","Banana"));
            itemList.add(new SelectItem("Pineapple","Pineapple"));
            itemList.add(new SelectItem("Apple","Apple"));
        }

        public void setStatus(RichSelectBooleanCheckbox status) {
            this.status = status;
        }

        public RichSelectBooleanCheckbox getStatus() {
            return status;
        }

        public void statusValueChange(ValueChangeEvent valueChangeEvent) {
            // Add event code here...
            System.out.println("****************INSIDE STATUS CHANGE**************");
            String var =this.status.getValue().toString();
            if(var.equals("true")){
           
                //set the itemList as diabled and set All.
                for(int i = 0; i<itemList.size();i++){
                     System.out.println(itemList.get(i).getValue());

    //Here I am getting all the values , but I want to mark all items here
                }
            }
            else{
                //yet to be implemented
            }
        }

        public void setChoiceItem(RichSelectManyChoice choiceItem) {
            this.choiceItem = choiceItem;
        }

        public RichSelectManyChoice getChoiceItem() {
            return choiceItem;
        }


        public void setItemList(List<SelectItem> itemList) {
            this.itemList = itemList;
        }

        public List<SelectItem> getItemList() {
            return itemList;
        }

        public void setItem(List<SelectItem> item) {
            this.item = item;
        }

        public List<SelectItem> getItem() {
            return item;
        }
    }

    Thanks,

    Rahul

  • Arunkumar Ramamoorthy-Oracle
    Arunkumar Ramamoorthy-Oracle Member Posts: 5,880 Employee

    Rahul,

    Once after the checkbox is clicked (in the valueChangeListener), you need to add the default values to the selected item list.

    Here is the modified code.

                    <af:selectBooleanCheckbox text="selectBooleanCheckbox 1" label="Label 1"
                                              valueChangeListener="#{viewScope.StatusBean.statusValueChange}"
                                              autoSubmit="true" id="sbc1"/>
                    <af:selectManyChoice label="Options" id="smc1" value="#{viewScope.StatusBean.item}"
                                         partialTriggers="sbc1">
                        <af:forEach items="#{viewScope.StatusBean.itemList}" var="item">
                            <af:selectItem value="#{item.value}" id="si4" label="#{item.label}"/>
                        </af:forEach>
                    </af:selectManyChoice>

    Bean :

    public class StatusBean {

        private List<SelectItem> itemList;
        private List item;     public StatusBean() {
            super();
            itemList = new ArrayList<SelectItem>();
            item=new ArrayList();
            itemList.add(new SelectItem("Mango", "Mango"));
            itemList.add(new SelectItem("Guava", "Guava"));
            itemList.add(new SelectItem("Orange", "Orange"));
            itemList.add(new SelectItem("Banana", "Banana"));
            itemList.add(new SelectItem("Pineapple", "Pineapple"));
            itemList.add(new SelectItem("Apple", "Apple"));
           
        }     public void statusValueChange(ValueChangeEvent valueChangeEvent) {
            // Add event code here...
            System.out.println("****************INSIDE STATUS CHANGE**************");
            String var = valueChangeEvent.getNewValue().toString();
            if (var.equals("true")) {
                //set the itemList as diabled and set All.
                for (int i = 0; i < itemList.size(); i++) {
                    System.out.println(itemList.get(i).getValue());
                    item.add(itemList.get(i).getValue());                 //Here I am getting all the values , but I want to mark all items here
                }         } else {
                item.clear();
            }
           
         
        }     public void setItemList(List<SelectItem> itemList) {
            this.itemList = itemList;
        }     public List<SelectItem> getItemList() {
            return itemList;
        }     public void setItem(List<SelectItem> item) {
            this.item = item;
        }     public List<SelectItem> getItem() {
            return item;
        } }

    -Arun

  • user8696578
    user8696578 Member Posts: 483

    Hi Arun,

    Thanks for the response . I have implemented as below. Also placed autosubmit and partial trigger inplace. But the selecteditems are not showing as selected in the UI. Instead getting below warnings.

    Details:

    package com.demo.view;

    import java.util.ArrayList;
    import java.util.List;

    import javax.faces.event.ValueChangeEvent;

    import javax.faces.model.SelectItem;

    import oracle.adf.view.rich.component.rich.input.RichSelectBooleanCheckbox;
    import oracle.adf.view.rich.component.rich.input.RichSelectManyChoice;

    public class StatusBean {
        private RichSelectBooleanCheckbox status;
        private RichSelectManyChoice choiceItem;
        private List<SelectItem> itemList;
        private List item;

        public StatusBean() {
            super();
            itemList = new ArrayList<SelectItem>();
            item = new ArrayList();
            itemList.add(new SelectItem("Mango","Mango"));
            itemList.add(new SelectItem("Guava","Guava"));
            itemList.add(new SelectItem("Orange","Orange"));
            itemList.add(new SelectItem("Banana","Banana"));
            itemList.add(new SelectItem("Pineapple","Pineapple"));
            itemList.add(new SelectItem("Apple","Apple"));
        }

        public void setStatus(RichSelectBooleanCheckbox status) {
            this.status = status;
        }

        public RichSelectBooleanCheckbox getStatus() {
            return status;
        }

        public void statusValueChange(ValueChangeEvent valueChangeEvent) {
            // Add event code here...
            System.out.println("****************INSIDE STATUS CHANGE**************");
            String var = valueChangeEvent.getNewValue().toString();   
            if(var.equals("true")){
           
                //set the itemList as diabled and set All.
                for(int i = 0; i<itemList.size();i++){
                     System.out.println(itemList.get(i).getValue());
                     item.add(itemList.get(i).getValue());
                    }
            }
            else{
                item.clear();
            }
        }

        public void setChoiceItem(RichSelectManyChoice choiceItem) {
            this.choiceItem = choiceItem;
        }

        public RichSelectManyChoice getChoiceItem() {
            return choiceItem;
        }


        public void setItemList(List<SelectItem> itemList) {
            this.itemList = itemList;
        }

        public List<SelectItem> getItemList() {
            return itemList;
        }

        public void setItem(List<SelectItem> item) { 
            this.item = item; 
            } 
       
        public List<SelectItem> getItem() {  
            return item;  
            }
    }

      <af:panelFormLayout id="pfl0">

      <af:selectBooleanCheckbox text="selectBooleanCheckbox 1" label="Label 1"

              valueChangeListener="#{viewScope.StatusBean.statusValueChange}"           autoSubmit="true"       id="sbc1" binding="#{viewScope.StatusBean.status}"/>

      <af:selectManyChoice label="Options" id="smc1"

                    binding="#{viewScope.StatusBean.choiceItem}"

                           valueChangeListener="#{viewScope.StatusBean.itemListValueChangeListener}"

                           value="#{viewScope.StatusBean.item}"

                           partialTriggers="sbc1">

          <af:forEach items="#{viewScope.StatusBean.itemList}" var="item" >

          <af:selectItem value="{item.value}" id="si4"

                       label="#{item.label}"/>

           </af:forEach>           

      </af:selectManyChoice>   

      </af:panelFormLayout>

    Warnings:

    <SimpleSelectManyRenderer> <_getSelectedItems> Could not find value:Mango of type:java.lang.String among list of SelectItems

    <SimpleSelectManyRenderer> <_getSelectedItems> Could not find value:Guava of type:java.lang.String among list of SelectItems

    <SimpleSelectManyRenderer> <_getSelectedItems> Could not find value:Orange of type:java.lang.String among list of SelectItems

    <SimpleSelectManyRenderer> <_getSelectedItems> Could not find value:Banana of type:java.lang.String among list of SelectItems

    <SimpleSelectManyRenderer> <_getSelectedItems> Could not find value:Pineapple of type:java.lang.String among list of SelectItems

    <SimpleSelectManyRenderer> <_getSelectedItems> Could not find value:Apple of type:java.lang.String among list of SelectItems

    Thanks,

    Rahul

  • Arunkumar Ramamoorthy-Oracle
    Arunkumar Ramamoorthy-Oracle Member Posts: 5,880 Employee

    Rahul,

    Any specific reason why you are binding the ui components to the bean? Try removing the bindings and see if it works fine then?

    -Arun

  • user8696578
    user8696578 Member Posts: 483

    Hi Arun,

    No specific reason for bindings. If I remove the bindings also same thing happening.

    Details:

    package com.demo.view;

    import java.util.ArrayList;
    import java.util.List;

    import javax.faces.event.ValueChangeEvent;

    import javax.faces.model.SelectItem;

    import oracle.adf.view.rich.component.rich.input.RichSelectBooleanCheckbox;
    import oracle.adf.view.rich.component.rich.input.RichSelectManyChoice;

    public class StatusBean {  
        private List<SelectItem> itemList;
        private List item;

        public StatusBean() {
            super();
            itemList = new ArrayList<SelectItem>();
            item = new ArrayList();
            itemList.add(new SelectItem("Mango","Mango"));
            itemList.add(new SelectItem("Guava","Guava"));
            itemList.add(new SelectItem("Orange","Orange"));
            itemList.add(new SelectItem("Banana","Banana"));
            itemList.add(new SelectItem("Pineapple","Pineapple"));
            itemList.add(new SelectItem("Apple","Apple"));
        }

      

        public void statusValueChange(ValueChangeEvent valueChangeEvent) {
            // Add event code here...
            System.out.println("****************INSIDE STATUS CHANGE**************");
            String var = valueChangeEvent.getNewValue().toString();   
            if(var.equals("true")){
           
                //set the itemList as diabled and set All.
                for(int i = 0; i<itemList.size();i++){
                     System.out.println(itemList.get(i).getValue());
                     item.add(itemList.get(i).getValue());
                    }
            }
            else{
                item.clear();
            }
        }

      

        public void setItemList(List<SelectItem> itemList) {
            this.itemList = itemList;
        }

        public List<SelectItem> getItemList() {
            return itemList;
        }

        public void setItem(List<SelectItem> item) { 
            this.item = item; 
            } 
       
        public List<SelectItem> getItem() {  
            return item;  
            }
    }

    <?xml version='1.0' encoding='UTF-8'?>

    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"

              xmlns:af="http://xmlns.oracle.com/adf/faces/rich">

      <af:panelFormLayout id="pfl0">

      <af:selectBooleanCheckbox text="selectBooleanCheckbox 1" label="Label 1"

              valueChangeListener="#{viewScope.StatusBean.statusValueChange}"           autoSubmit="true"       id="sbc1" />

      <af:selectManyChoice label="Options" id="smc1"

                  value="#{viewScope.StatusBean.item}"

                           partialTriggers="sbc1">

          <af:forEach items="#{viewScope.StatusBean.itemList}" var="item" >

          <af:selectItem value="{item.value}" id="si4"

                       label="#{item.label}"/>

           </af:forEach>           

      </af:selectManyChoice>   

      </af:panelFormLayout>

    </jsp:root>

    Message:

    Mango

    Guava

    Orange

    Banana

    Pineapple

    Apple

    <SimpleSelectManyRenderer> <_getSelectedItems> Could not find value:Mango of type:java.lang.String among list of SelectItems

    <SimpleSelectManyRenderer> <_getSelectedItems> Could not find value:Guava of type:java.lang.String among list of SelectItems

    <SimpleSelectManyRenderer> <_getSelectedItems> Could not find value:Orange of type:java.lang.String among list of SelectItems

    <SimpleSelectManyRenderer> <_getSelectedItems> Could not find value:Banana of type:java.lang.String among list of SelectItems

    <SimpleSelectManyRenderer> <_getSelectedItems> Could not find value:Pineapple of type:java.lang.String among list of SelectItems

    <SimpleSelectManyRenderer> <_getSelectedItems> Could not find value:Apple of type:java.lang.String among list of SelectItems

    Thanks,

    Rahul

  • Arunkumar Ramamoorthy-Oracle
    Arunkumar Ramamoorthy-Oracle Member Posts: 5,880 Employee

    Not sure what is the cause. It works fine for me.

    Have you tried changing the accessor for the item property to

    public void setItem(List item) { 
        this.item = item; 
       
    public List getItem() {  
        return item;  
       

    }

    And see if it works fine then?

    -Arun

This discussion has been closed.