Using Multiple Selection (selectManyListbox & selectManyCheckbox component) in ADF

Sharing is Caring

Hello All,
This tutorial is based on use of selectManyListbox & selectManyCheckbox component in ADF to enable multiple selection.
Both components are same in functionality only somewhat different in look-feel.

Follow steps to use this component

  • Create a fusion web application and create business components for Departments table of HR Schema

 

  • Now create a page and drop Departments Vo from data control on the page as multiple selections (checkbox or list box)

 

 

  • Now binding for this component is created in page-bindings, add a button on the page to get total selected values

     

     

  • See how to get selected values in the managed bean, JUCtrlListBinding is used to get selected values

import javax.faces.event.ActionEvent;

import oracle.adf.model.BindingContext;

import oracle.binding.BindingContainer;

import oracle.jbo.uicli.binding.JUCtrlListBinding;

public BindingContainer getBindings() {
return BindingContext.getCurrent().getCurrentBindingsEntry();
}

public void getSelectedValue(ActionEvent actionEvent) {

JUCtrlListBinding listBindings = (JUCtrlListBinding)getBindings().get("DepartmentsView1");
Object str[] = listBindings.getSelectedValues();
for (int i = 0; i < str.length; i++) {
System.out.println(str[i]);
}
}

 

  • This method works for both list box and checkbox, I have added all selected departments in a FacesMessage and displayed on the page

 

Multiple Selection

Select All-

 

And Check-box component looks like this-

The complete code is written on ‘Get Selected Values‘ button-

/**Method to get BindingContainer of page
 * @return
 */
 public BindingContainer getBindings() {
    return BindingContext.getCurrent().getCurrentBindingsEntry();
 }

/**Method to get Selected Values
 * @param actionEvent
 */
public void getSelectedValue(ActionEvent actionEvent) {

JUCtrlListBinding listBindings = (JUCtrlListBinding)getBindings().get("DepartmentsView1");
Object str[] = listBindings.getSelectedValues();
StringBuilder saveMsg =
new StringBuilder("<html><body><b><p style='color:red'>Selected Departments are-</p></b>");

saveMsg.append("<ul>");
for (int i = 0; i < str.length; i++) {
System.out.println(str[i]);
saveMsg.append("<li> <b>" + str[i].toString() + "</b></li>");
}

saveMsg.append("</ul><br>");
saveMsg.append("</body></html>");
FacesMessage msg = new FacesMessage(saveMsg.toString());
FacesContext.getCurrentInstance().addMessage(null, msg);

}

Sample ADF Application- Download

Cheers 🙂 Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

0 thoughts on “Using Multiple Selection (selectManyListbox & selectManyCheckbox component) in ADF”

  1. dear Ashish
    i get this error when i try to run the App
    oracle.jbo.domain.DataCreationException: JBO-25009: Cannot create an object of type:java.lang.Integer from type:java.lang.String with value:KHALED MONTASER

    Caused by: java.lang.NumberFormatException: For input string: "KHALED MONTASER"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:492)
    at java.lang.Integer.valueOf(Integer.java:582)
    at oracle.jbo.common.JboTypeMapEntries$1.convert(JboTypeMapEntries.java:103)
    … 96 more

  2. Hi Ashish,

    I am using Jdev version 12.1.3.0.0.

    I am getting follwing error:-

    <java.lang.ClassCastException: oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding cannot be cast to oracle.jbo.uicli.binding.JUCtrlListBinding
    at oal.oracle.apps.intg.cdqworkbench.ui.bean.OscCraBean.onSearch(OscCraBean.java:1078)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:254)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:148)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at org.apache.myfaces.trinidad.component.UIXComponentBase.broadcast(UIXComponentBase.java:1113)
    at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:179)
    at org.apache.myfaces.trinidad.component.UIXComponent.broadcastInContext(UIXComponent.java:364)
    at org.apache.myfaces.trinidad.component.WrapperEvent.broadcastWrappedEvent(WrapperEvent.java:82)
    at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent$1.run(ContextSwitchingComponent.java:168)

    Can you please help me here.

  3. Hi Ashish,

    I am also getting same error.

    oracle.jbo.domain.DataCreationException: JBO-25009: Cannot create an object of type:java.lang.Integer from type:java.lang.String with value:EXCESS
    at oracle.jbo.common.JboTypeMapEntries$1.convert(JboTypeMapEntries.java:124)
    at oracle.jbo.domain.TypeFactory.get(TypeFactory.java:892)
    at oracle.jbo.domain.TypeFactory.getInstance(TypeFactory.java:120)
    at oracle.jbo.domain.TypeFactory.convertToPrimitiveArray(TypeFactory.java:977)
    at oracle.jbo.domain.TypeFactory.get(TypeFactory.java:904)
    at oracle.jbo.domain.TypeFactory.getInstance(TypeFactory.java:120)

    i checked your sample app. You are also using string type for base attribute.

    could you please help me how to overcome this exception.

  4. Hi Ashish,

    If i change the base attribute to int type attribute then it works but in my managed bean i get the selected values as 1,2 etc like this but i want the original values.

    In your sample app you are using the base attribute as string type attribute (DepartName) but there is no error don't what i am doing wrong.

  5. Yes you need to use integer value as base attribute , In some Jdev version string is not accepted
    Which Jdev version you are using ?
    Alternate way is to use filter viewObject with departmentId and get Department Name
    Like this

    deptVo.getFilteredRows("DepartmentId",value);

    Ashish

Leave a Reply

Your email address will not be published. Required fields are marked *