Hello All ,
This tutorial is based on use of selectManyListbox & selectManyCheckbox component in ADF to enable multiple selection.
Both component are same in functionality only somewhat different in look-feel.
Follow steps to use these component -
Select All-
Complete code written on 'Get Selected Values' button-
Cheers- Download Sample
This tutorial is based on use of selectManyListbox & selectManyCheckbox component in ADF to enable multiple selection.
Both component are same in functionality only somewhat different in look-feel.
Follow steps to use these 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 page as multiple selection (checkbox or listbox)
- Now binding for this component is created in page-bindings, add a button on page to get total selected values
- See how to get selected values in managed bean, JUCtrlListBinding is used to get selected values
- this method works for both listbox and checkbox, i have added all selected departments in a FacesMessage and displayed on page
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]); } }
Select All-
Complete code 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); }
Cheers- Download Sample
dear Ashish
ReplyDeletei 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
thanks Ashish
ReplyDeleteit was my mistake
now everything is Ok
thanks again
I think you was using string type of attribute in base attribute
DeleteHi Ashish, how we can select base attribute to String?
DeleteKushal
DeleteLook at this blog post for complete code oracle.jbo.domain.DataCreationException: JBO-25009 while using multiple selection component in ADF Faces
Ashish
Hi Ashish,
ReplyDeleteI 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.
Have you checked sample application ?
Deleteand this error is due to wrong type , once check your import statements
Hi Ashish,
ReplyDeleteI 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.
Hi Ashish,
ReplyDeleteIf 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.
Yes you need to use integer value as base attribute , In some Jdev version string is not accepted
DeleteWhich 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
Hi Manish
DeleteLook at this blog post for complete code oracle.jbo.domain.DataCreationException: JBO-25009 while using multiple selection component in ADF Faces
Ashish