For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!
Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.
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
Rahul,
Always mention your JDev version. Your usecase is unclear. Can you elaborate with an example?
-Arun
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,
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.
Thanks for the response. Yes thats what I doing. I will post the answer once done.
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; }}
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; } }
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 List<SelectItem> getItem() { return item; }
}
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 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 setItem(List<SelectItem> item) { this.item = item; } public List<SelectItem> getItem() { return item; } }
<af:panelFormLayout id="pfl0">
binding="#{viewScope.StatusBean.choiceItem}"
valueChangeListener="#{viewScope.StatusBean.itemListValueChangeListener}"
value="#{viewScope.StatusBean.item}"
partialTriggers="sbc1">
<af:selectItem value="{item.value}" id="si4"
label="#{item.label}"/>
</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
Any specific reason why you are binding the ui components to the bean? Try removing the bindings and see if it works fine then?
No specific reason for bindings. If I remove the bindings also same thing happening.
<?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">
valueChangeListener="#{viewScope.StatusBean.statusValueChange}" autoSubmit="true" id="sbc1" />
</jsp:root>
Message:
Mango
Guava
Orange
Banana
Pineapple
Apple
Not sure what is the cause. It works fine for me.
Have you tried changing the accessor for the item property to
And see if it works fine then?
Yes I tried that aswell. I wanted to check whether in ui all the items showing ticked once u select the check box.
It should be problem with your code.
Check out the jspx source and the # is missing for the value of the selectManyChoice items.
Change
to
<af:selectItem value="#{item.value}" id="si4"
What I would say is Many many thanks to you Arun.