Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label get Value. Show all posts
Showing posts with label get Value. 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

Tuesday 16 August 2016

Enable selection and Get selected marker value from dvt:thematicMap in ADF Faces


Hello All

Previously I have posted about using dvt:thematicMap to mark locations using latitude and longitude, In that post I have described about showing different cities as markers on a world map using a POJO based data structure

Now In this post I am going to describe that how can we enable selection in thematic map and get selected location value in managed bean so here in this post I am extending that previous application

Thursday 21 April 2016

ADF Basics: Get display and base value of POJO based SelectOneChoice


Previously I have posted about populating selectOneChoice programmatically using POJO

and this post is about getting selected value of POJO base selectOneChoice (both display value and base value)

Tuesday 5 January 2016

Get selected slice of dvt:pieChart using custom selection listener in ADF

First of all wishing a very Happy New Year to all of you, New Year is like a blank page , fill it with happiness and good memories


This post is about a simple requirement - How to get selected slice value of dvt:pieChart ?
So for this we have to create a custom selection Listener in managed bean that will be called whenever user selects any slice of pieChart
If you see documentation of pieChart it tells about two properties -

Friday 28 August 2015

ADF Basics: Using setPropertyListener to set value in memory scope variables

Soemtimes we need to set a value in memory scope variable on some event
In ADF af:setPropertyListener does this for you declaratively

The setPropertyListener tag provides a declarative syntax for assigning values when an event fires. The setPropertyListener implements the listener interface for a variety of events, to indicate which event type it should listen for set the 'type' attribute.

Read more about <af:setPropertyListener>

Wednesday 6 May 2015

Get Value from programmatically created components , Iterate over parent component to get child values in ADF Faces

Sometimes we need to create and add ADF Faces components at runtime , we can do it programmatically
I have posted about this before
Creating dynamic layout (form and UI Component) using ADF Faces

Now this post talks about getting value from programmatically created component, means when user enters value in those component then how to access that value in managed bean

Here i am using Jdev 12.1.3 , Let's see the implementation part

Created a page and added two buttons , one to create component at run time and second one to get values from those components
See page XML source code -

<af:document title="ProgComponent.jspx" id="d1">
            <af:form id="f1">
                <af:spacer width="10" height="10" id="s3"/>
                <af:button text="Create Components " id="b1"
                           actionListener="#{viewScope.GetValueProgCompBean.createComponentsAction}"/>
                <af:spacer width="10" height="10" id="s1"/>
                <af:button text="Get Value" id="b2"
                           actionListener="#{viewScope.GetValueProgCompBean.getValueOfCompAction}"/>
                <af:panelGroupLayout id="pgl1" layout="vertical"
                                     binding="#{viewScope.GetValueProgCompBean.parentGroupBind}">
                    <af:spacer width="10" height="10" id="s2"/>
                </af:panelGroupLayout>
            </af:form>
        </af:document>

To create components at run time i have used same approach described in above blog post
Check the code written on Create Components button



import javax.faces.component.UIComponent;
import javax.faces.event.ActionEvent;

import oracle.adf.view.rich.component.rich.input.RichInputText;
import oracle.adf.view.rich.component.rich.layout.RichPanelGroupLayout;
import oracle.adf.view.rich.context.AdfFacesContext;


    //Binding of panel group layout , it will be parent of prog. created components
    private RichPanelGroupLayout parentGroupBind;

    public void setParentGroupBind(RichPanelGroupLayout parentGroupBind) {
        this.parentGroupBind = parentGroupBind;
    }

    public RichPanelGroupLayout getParentGroupBind() {
        return parentGroupBind;
    }

    /**Method to add child components to parent
     * @param parentUIComponent
     * @param childUIComponent
     */
    public void addComponent(UIComponent parentUIComponent, UIComponent childUIComponent) {
        parentUIComponent.getChildren().add(childUIComponent);
        AdfFacesContext.getCurrentInstance().addPartialTarget(parentUIComponent);
    }

    /**Method to create Input text at run time
     * @param actionEvent
     */
    public void createComponentsAction(ActionEvent actionEvent) {
        //Create an Object of desired UI Component
        RichInputText ui = new RichInputText();
        //Set properties
        ui.setId("rit1");
        ui.setLabel("Input text 1");
        ui.setContentStyle("font-weight:bold;color:red");
        //Now add this component to any parent component
        addComponent(getParentGroupBind(), ui);

        RichInputText ui1 = new RichInputText();
        ui1.setId("rit2");
        ui1.setLabel("Input text 2");
        ui1.setContentStyle("font-weight:bold;color:red");
        addComponent(getParentGroupBind(), ui1);
    }

Now run application and click on button , you will see two inputText are created


Now to get value of these components follow the steps
1. Get Parent layout
2. Iterate over parent to get all child components
3. Get Value of every child

See the code written on get value button in managed bean

    /**Method to Iterate over parent and get value of all child components
     * @param actionEvent
     */
    public void getValueOfCompAction(ActionEvent actionEvent) {
        RichPanelGroupLayout PF = getParentGroupBind(); // Get Parent Layout
        List<UIComponent> listcomp = PF.getChildren(); // Get all child
        Iterator iter = listcomp.iterator(); // Create an Iteraotr to iterate over childs
        while (iter.hasNext()) {
            UIComponent comp = (UIComponent) iter.next(); // Get next Child Component
            System.out.println("Component is-" + comp + " and value is-" +
                               comp.getAttributes().get("value")); //Get Component detial and it's value
        }
    }

Again check , enter value in both inputText and click on button to get value


Output on console-

Sample ADF Application- Download
Cheers :) Happy Learning

Monday 24 March 2014

Iterating ViewObject vertically (get all attributes of ViewObject) programmatically

Hello All,
This post talks about a requirement of getting all attributes (column names) of a viewObject programmatically

  • Create a fusion web application and business component using department table

  • you can see all attributes in  Departments entity object

  • Now to get ViewObject's attributes name , there is a method written in AMImpl class , see it, i have added a facesMessage to show all names on a Message Board



  •     /**Method to get all attributes of a viewObject
         * */
        public void iterateVoVertically() {
            ViewObjectImpl vo = this.getDepartments1();
            ViewAttributeDefImpl[] attrDefs = vo.getViewAttributeDefImpls();
            int count = 0;
            StringBuilder infoMsg =
                new StringBuilder("<html><body><b><p style='color:red'> Attribute of Department ViewObject are-</p></b>");
            infoMsg.append("<ul>");
    
    
            for (ViewAttributeDefImpl attrDef : attrDefs) {
                byte attrKind =
                    attrDefs[count].getAttributeKind(); //checks attribute kind for each element in an array of AttributeDefs
                if (attrKind != AttributeDef.ATTR_ASSOCIATED_ROW && attrKind != AttributeDef.ATTR_ASSOCIATED_ROWITERATOR) {
                    String columnName = attrDef.getName();
                    infoMsg.append("<li> <b>" + attrDef.getName() + "</b></li>");
                    System.out.println("Column Name-" + columnName);
                }
            }
            infoMsg.append("</ul><br>");
            infoMsg.append("</body></html>");
            FacesMessage msg = new FacesMessage(infoMsg.toString());
            msg.setSeverity(FacesMessage.SEVERITY_INFO);
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    

  • I have called this method through page binding and AM Client on a button of page

  • now on click of button all attributes of Departments ViewObject are shown in FacesMessage, you can use it in your code
 Cheers :-)

Friday 9 August 2013

Programmatically populate values in a af:selectOneChoice component in ADF

In this tutorial you will see that how to populate selectOneChoice list from managed bean, sometimes we need to use custom list that are not model driven, this scenario can be implemented there

follow steps -

  • First of all create a fusion web application and a page in it
  • Now create a variable of type java.util.List in managed bean, and generate its accessors

  •     List<SelectItem> customList;
    
        public void setCustomList(List<SelectItem> customList) {
            this.customList = customList;
        }
    
        public List<SelectItem> getCustomList() {
            return customList;
        }
    

  • this list contains value of type javax.faces.model.SelectItem; that is supported by af:selectOneChoice
  • now time to add values in list, so to add values in this list i have written this code in getter of variable

  •     public List<SelectItem> getCustomList() {
            if (customList == null) {
                customList = new ArrayList<SelectItem>();
                customList.add(new SelectItem("i1","Item 1"));
                customList.add(new SelectItem("i2","Item 2"));
                customList.add(new SelectItem("i3","Item 3"));
                customList.add(new SelectItem("i3","Item 4"));
                customList.add(new SelectItem("i5","Item 5"));
        }
            return customList;
        }
    

  • Managed bean part is done, now add this to view layer



  • Drop choice list in page from component palette
  •  Now bind choice list to bean List


  • See the page source after whole setup-

  • <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
              xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
        <jsp:directive.page contentType="text/html;charset=UTF-8"/>
        <f:view>
            <af:document title="listPage.jspx" id="d1">
                <af:form id="f1">
                    <af:panelGroupLayout id="pgl1" layout="vertical" halign="center">
                        <af:spacer width="10" height="10" id="s1"/>
                        <af:selectOneChoice label="Custom List" id="soc1" contentStyle="font-weight:bold;color:darkgreen;">
                            <f:selectItems value="#{ListPolulatebean.customList}" id="si1"/>
                        </af:selectOneChoice>
                    </af:panelGroupLayout>
                </af:form>
            </af:document>
        </f:view>
    </jsp:root>
    

  • Run this page and see programmatic choice list-


Monday 20 May 2013

Set and Get Value from Taskflow parameter (pageFlowScope variable) from Managed Bean- ADF

Hello All

This post is about getting and setting value in taskFlow parameter using Java Code so for that we have created a application with bounded taskFlow

Let's see how to do this -

We have bounded taskflow having Input Parameter defined in it named GLBL_PARAM_TEST

Bounded Taskflow Input Parameters

and we have to set its value from managed bean.
this is very simple -see how to do that
  • Get pageFlowScope Map and put parameter 's value in it

  •         Map paramMap = RequestContext.getCurrentInstance().getPageFlowScope();
            paramMap.put("GLBL_PARAM_TEST", "Ashish"); 

  • And get Value from taskFlow parameter in managed bean



  •     public String resolvEl(String data){
                   FacesContext fc = FacesContext.getCurrentInstance();
                   Application app = fc.getApplication();
                   ExpressionFactory elFactory = app.getExpressionFactory();
                   ELContext elContext = fc.getELContext();
                   ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class);
                   String Message=valueExp.getValue(elContext).toString();
                   return Message;
                 }
    
    
    String param=resolvEl("#{pageFlowScope.GLBL_PARAM_TEST}");
    

Tuesday 14 May 2013

Using Contextual Event in Oracle ADF (Region Communication)

Contextual event ,in simple terms is a way to communicate between taskflows.
Sometimes we have taskflow open in a region and have to get some values from that taskflow .
This scenario can be achieved by contextual event.

 
Contextual Event have two parts-
  1. Publisher Event (Producer)- As button or any component that can raise event 
  2. Handler Event (Customer)- that listens and process event published by producer
This tutorial is based on example developed on default HR schema of Oracle DB 11g
I have created two application and called first one in secod application as region.
  • Create first application using Department table of HR schema and drag Department Name on page fragment, now create publisher event (follow steps) for Department Name .
  • Select Department Name field in structure window and go to property Inspector select ContextualEvent
    click on green add icon and select event type and name for publisher event

  • Select field value from Iterator Binding
  • here you are done with publisher event or producer create a jar of this application in order to use it in second application.
  • Now start Second Application that will handle and process this event, create a page and put an output text and set its value from managed bean


  • Now create a event handler class to process published event and to make it available to page binding level , we have to create DataControl for this class.





  • Right click on event class and Click on CreateDataControl.
  • Now add this method binding to page so that it can be accessible from page binding
  • Now drag and drop taskflow from jar library on page as region by this published event will also be available to page
  • Now go to page binding and goto ContextualEvents tab ,click on subscribers tab and click on add icon this will open a popup window ,click on search button , it will show available publisher event, now select event and goto handler search option and select function that you have previously added in page binding
  • Give consumer parameter name same as event handler function

Now Run your Application - Download ADF Sample Application

Monday 26 November 2012

Tree Table Component in Oracle ADF(Hierarchical Representation)


Hello All

This post is about ADF Faces Tree Table component (about designing component and get selected value from tree table)

We have a simple sample application that shows how can we use tree table component in Oracle ADF.
Tree Table component represents  Hierarchical view of Master Deatil form of data
Here we take example from HR schema using Employees and Department table
Follow these steps -

  • Create EOs,VOs of Employees and Department table in HR Schema and create association and viewlink between Department To Employees considering Department Id
  • Now go to data control and select Department table and drop it on page as Tree table 

Drop ViewObject as ADF Tree Table
  •  Now we have to edit its bindings, it means you have to select attributes that you want to display in page, and below Department table you should add Employees table using "add" button on top, and select appropriate Iterator in EL picker
Edit tree binding in pageDef
  • Now go to page and select treetable in Structure window of Jdeveloper and Go to its selection listener and copy default value
Override default selection listener
  • And change selection listener set it to bean, click on edit and create new selection listener in Bean




Create custom selection listener in managed bean for af:treeTable
  •  Now go to Selection Listener and Use this code to get Value of selected node in treetable, if you will get value of node you can perform any operation on Tree Table
    public void treeTableSelectionListener(SelectionEvent selectionEvent) {
        String adfSelectionListener = "#{bindings.Department1.treeModel.makeCurrent}";

        FacesContext fctx = FacesContext.getCurrentInstance();
        Application application = fctx.getApplication();
        ELContext elCtx = fctx.getELContext();
        ExpressionFactory exprFactory = application.getExpressionFactory();
        MethodExpression me = null;
        me =
 exprFactory.createMethodExpression(elCtx, adfSelectionListener, Object.class, new Class[] { SelectionEvent.class });
        me.invoke(elCtx, new Object[] { selectionEvent });
       
        RichTreeTable tree = (RichTreeTable)selectionEvent.getSource();
        TreeModel model = (TreeModel)tree.getValue();
        //get selected nodes
        RowKeySet rowKeySet = selectionEvent.getAddedSet();
        Iterator rksIterator = rowKeySet.iterator();
        while (rksIterator.hasNext()) {
            List key = (List)rksIterator.next();
            JUCtrlHierBinding treeBinding = null;
            treeBinding = (JUCtrlHierBinding)((CollectionModel)tree.getValue()).getWrappedData();
            JUCtrlHierNodeBinding nodeBinding = treeBinding.findNodeByKeyPath(key);
            Row rw = nodeBinding.getRow();
            System.out.println("row: " + rw.getAttribute(0)); // You can get any attribute
            System.out.println("View Object name---->" + nodeBinding.getViewObject().getName());

        }
    }
  •  Now run your page and when you will click on any node you will find its value on Console---Cheers Happy Coding!
Sample ADF Application