Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label af:selectManyChoice. Show all posts
Showing posts with label af:selectManyChoice. Show all posts

Saturday 3 June 2017

oracle.jbo.domain.DataCreationException: JBO-25009 while using multiple selection component in ADF Faces

Previously I have posted about using multi-selection components (af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle) of ADF Faces. These components make use of list binding and work on base attribute and display attribute concept

Friday 5 June 2015

Programmatically Select all values in ADF BC based selectMany (af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle) component

Hello All,
Previously i have posted a lot about component that supports multiple selection in ADF Faces (af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle)
- Multiple Selection in ADF Faces

This post is about selecting all values in a component programmatically on a event like button click, value change event etc.
Note that this post is designed for ADF BC (viewObject) based components , to set values in bean based component check this-
Programmatically populate values in ADF Faces multiSelect component (af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle)

So for this i have just dropped Departments viewObject as multiSelect component on page
(af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle)

 Page bindings section looks like this-

Now see code of Set all values as selected button-

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

    /**Method to set all values as selected in SelectMany Components.
     * @param actionEvent
    public void setAllValuesToSelected(ActionEvent actionEvent) {

        int arrIndex[];
        //Get the iterator binding of component
        DCIteratorBinding deptIter = (DCIteratorBinding) getBindings().get("DepartmentsView1Iterator");
        //Get viewObject from Iterator
        ViewObject deptVo = deptIter.getViewObject();
        //Get component list binding , component is directly based on this
        JUCtrlListBinding list = (JUCtrlListBinding) getBindings().get("DepartmentsView1");
        DCIteratorBinding iterList = list.getDCIteratorBinding();
        RowSetIterator rsi = deptVo.createRowSetIterator(null);
        int i = 0;
        int rowCount = (int) deptVo.getEstimatedRowCount();
        //Initialize array and set it's size (equal to number of rows in List)
        arrIndex = new int[rowCount];
        while (rsi.hasNext()) {
            //Get viewObject next row from RowSetIterator
            Row nextRow =;
            //Set this row as page iterator's current row
            //Now get index of this row
            int indx = iterList.getCurrentRowIndexInRange();
            //Add it to array
            arrIndex[i] = indx;
        // Set as selected indices

All done, now run and check application , click on button and see what happens ?

Great, it's working :)
I have explained one more approach to set values in multi select component that makes use of component binding
check it - Set values in af:selectManyChoice programmatically - Oracle ADF

Sample ADF Application-Download
Cheers :) Happy Learning

Wednesday 7 January 2015

Programmatically populate values in ADF Faces multiSelect component (af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle)

ADF Faces provides some component to support multiple selection as af:selectManyListbox, af:selectManyCheckbox, af:selectManyChoice, af:selectManyShuttle
In this post we will see how to populate values in these component from managed bean using POJO
You can read my previous post on multiple selection that was about populating multiselect component using ADF BC and binding layer
Using Multiple Selection (selectManyListbox & selectManyCheckbox component) in ADF
Shuttle Component in Oracle ADF (Allow Multiple Selection)

See the step by step implementation-

  • Create a Fusion Web Application and a managed bean in viewController

  • Create a variable of type java.util.List in managed bean, and generate its accessors

  •     //List to show records in selectMany components
        List<SelectItem> allValuesList;
        public void setAllValuesList(List<SelectItem> allValuesList) {
            this.allValuesList = allValuesList;
        public List<SelectItem> getAllValuesList() {
            return allValuesList;

  • This list contains value of type javax.faces.model.SelectItem; that is supported by af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox compoent

  •     //List to show records in selectMany components
        List<SelectItem> allValuesList;
        public void setAllValuesList(List<SelectItem> allValuesList) {
            this.allValuesList = allValuesList;
        public List<SelectItem> getAllValuesList() {
            if (allValuesList == null) {
                allValuesList = new ArrayList<SelectItem>();
                allValuesList.add(new SelectItem(1, "India"));
                allValuesList.add(new SelectItem(2, "Australia"));
                allValuesList.add(new SelectItem(3, "America"));
                allValuesList.add(new SelectItem(4, "United Kingdom"));
            return allValuesList;

  • See how to add this list reference to  af:selectManyCheckbox component, just drag n drop component on page

  • Set managed bean list reference to selectManyCheckbox component, records stored in this list will be populated in component

  • Suppose I have to show some record as selected by default on page load so for this requirement created another List in managed bean and added it to value property of selectManyCheckbox component
    Value property of component refers only selected records but selectItems component refers all records of component

  •     //List to show selected values in selectMany Component
        List selectedValues;
        public void setSelectedValues(List selectedValues) {
            this.selectedValues = selectedValues;
        public List getSelectedValues() {
            if (selectedValues == null) {
                selectedValues = new ArrayList();
                System.out.println("List is-" + selectedValues);
            return selectedValues;

    See af:selectManyCheckbox source -

    <af:selectManyCheckbox id="smc1" value="#{viewScope.ProgSelectManyComp.selectedValues}">
                                        <f:selectItems value="#{viewScope.ProgSelectManyComp.allValuesList}" id="si1"/>

  • Now run this application and see component on page

  • Following same steps i have three more component on page , all 3 adf faces component support multiple selection

    <af:selectManyChoice label="Label 1" id="smc2"
                                        <f:selectItems value="#{viewScope.ProgSelectManyComp.allValuesList}" id="si2"/>


    <af:selectManyListbox label="Label 1" id="sml1"
                                        <f:selectItems value="#{viewScope.ProgSelectManyComp.allValuesList}" id="si3"/>


     <af:selectManyShuttle label="Label 1" id="sos1" simple="true"
                                        <f:selectItems value="#{viewScope.ProgSelectManyComp.allValuesList}" id="si4"/>

  • All 4 components on page are populated using same List, this is just an example to show that all 4 components share same strucutre, run this application and see 

  • Thanks, Happy Learning :)
    Download- Sample ADF Application

Monday 13 October 2014

Set values in af:selectManyChoice programmatically - Oracle ADF

This post is about a very common question
How to set selected values in af:selectManyChoice component ?
Sometimes we need to set some values in selectManyChoice component on some action

In this post i am using Departments table of HR Schema to create selectManyChoice (Multiple Selection)
Just drag and drop Departments viewObject as ADF Select Many Choice
see- Using Multiple Selection (selectManyListbox & selectManyCheckbox component) in ADF

(Jdev Version- 12.1.3)
dropped a button on page and on this button action ,  setting values in component
See this simple managed bean code -

import java.util.ArrayList;

import javax.faces.event.ActionEvent;


public class SetValueSmcBean {
    private RichSelectManyChoice selectMcBind;

    public SetValueSmcBean() {

    /**Methos to set selected values in SelectManyChoice
     * @param actionEvent
    public void setSelectedValuesAction(ActionEvent actionEvent) {
        ArrayList listVal = new ArrayList(20);
        //Add DepartmentId to list that you want to set as selected
        // Set this List as value using component binding
        //Refresh Component on page (partial target)

    public void setSelectMcBind(RichSelectManyChoice selectMcBind) {
        this.selectMcBind = selectMcBind;

    public RichSelectManyChoice getSelectMcBind() {
        return selectMcBind;

run application and check-

Downoad Sample Application
Thanks , Happy Learning :)

Monday 15 September 2014

Showing all values instead of 'All' text in selectManyChoice using JavaScript -Oracle ADF

Happy Engineer's Day :)
This post is about overriding default text for select all feature in af:selectManyChoice
af:selectManyChoice supports multiple selection in ADF Faces and framework provides a default feature to select all values of list but after selecting all value it doesn't show values ,only show a String 'All'.
Like this-
but sometimes it is not clear that what are the values by just seeing this 'All' text or it is a requirement to show all values (if there is not much data) instead of this default text

So in this post i am going to override this default text using JavaScript and this is a quick overview that how we can play with JavaScript and try it in ADF Faces
see previous posts on JavaScript in Oracle ADF-

Show message (Invoke FacesMessage) using JavaScript in ADF Faces
Launching browser print dialog using simple javascript function in ADF
Using JQuery in Oracle ADF

So in this implementation i am using Departments table (HR Schema -Oracle) and Jdeveloper 12C (12.1.3)
  • Prepare model using Departments table and drop viewObject on page as af:selectManyChoice

  • Now  see when we select one -two values , it appears on component but in case of all only that 'All' string appears

  • Here i am changing this text on valueChange event of selectManyChoice , so created a valueChangeListener in managed bean. 

  • See what i am going to do in this listener is -
    1. Get all selected values means DepartmentId
    2. Next is to get corresponding DepartmentName for DepartmentId 
    3. Add all DepartmentName into an String
    4. Call JavaScript method to set this String as value of selectManyChoice instead of 'All'

  • See code written in valueChangeListener , i have used enough comments to understand each line

  •     /**ValueChangeListener for SelectManyChoice (Executes Javascript to replace 'All' text)
         * @param vce
        public void selectManyVCE(ValueChangeEvent vce) {
            //String to store all selected Departments Name
            String displayVal = "";
            //Get BindingContainer of current page
            BindingContext bctx = BindingContext.getCurrent();
            BindingContainer bindings = bctx.getCurrentBindingsEntry();
            //Get Iterator of SelectManyChoice
            DCIteratorBinding iter = (DCIteratorBinding) bindings.get("Departments1Iterator");
            if (vce.getNewValue() != null) {
                //Get all selected values in an Object array
                Object[] selectedVals = (Object[]) vce.getNewValue();
                //Iterate over array to get all selected DepartmentId
                for (int i = 0; i < selectedVals.length; i++) {
                    Integer val = (Integer) selectedVals[i];
                    //Create Key using DepartmentId to use furhter
                    Key key = new Key(new Object[] { val });
                    //Get ViewObject row using Key vlaue
                    Row row = iter.getViewObject().getRow(key);
                    // Get DepartmentName from row and add it to String
                    if (displayVal != "") {
                        displayVal = displayVal.concat(", ").concat(row.getAttribute("DepartmentName").toString());
                    } else {
                        displayVal = displayVal.concat(row.getAttribute("DepartmentName").toString());
                //Write JavaScript code to change text of selectManyChoice as a StingBuilder Object
                StringBuilder jsString = new StringBuilder();
                //First Step-get clientID of component
                jsString.append("var elementId = '" + vce.getComponent().getClientId());
                //Second- add ::content to access it's value
                //Third- Check that current value is 'All' or not
                jsString.append("\n if (document.getElementById(elementId).value == 'All') {");
                //Forth- if yes then assign Department Name's string as value of selectManyChoice
                jsString.append("\n document.getElementById(elementId).value ='" + displayVal + "' \n};");
                System.out.println("JS File-" + jsString);
                //Call this JavaScript code using this Helper method

    Method to call JavaScript from managed bean-

        /**Helper Method to call Javascript
         * @param javascriptCode
        public static void writeJavaScriptToClient(String javascriptCode) {
            FacesContext facesCtx = FacesContext.getCurrentInstance();
            ExtendedRenderKitService service = Service.getRenderKitService(facesCtx, ExtendedRenderKitService.class);
            service.addScript(facesCtx, javascriptCode);

    Import packages-

    import javax.faces.context.FacesContext;
    import javax.faces.event.ValueChangeEvent;
    import oracle.adf.model.BindingContext;
    import oracle.adf.model.binding.DCIteratorBinding;
    import oracle.binding.BindingContainer;
    import oracle.jbo.Key;
    import oracle.jbo.Row;
    import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
    import org.apache.myfaces.trinidad.util.Service;

  • Run application and check, on selecting all values it shows -

  • but this will happen only on value change event of selectManyChoice , you can call this JavaScript any time as per your requirement like on page load
Thanks , Happy Learning :-)