12 March 2015

ADF DVT : How to get multi-selection values from a pie chart

When you want to perform some action on click and get the clicked value (one or more than one pie slice) from the pie chart, you can use ClickAction added to the page bean. Here is how you can do it:

1. Add pie chart on the page

2. Bind the pie chart with a bean UIGraph component 
[code] private UIGraph myPie;  [/code]
3. Pay close attention to dataSelection attribute in the pie properties, if you want to get value of one pie slice then select "single" or select "multiple" for more than one values from a pie (default is "none"). you page should look like the code below:
[code] [/code]
4. Add this method to your bean (myBean)
[code]public String myPieSelectionAction(){ Object value1 = null; Object value2 = null; Set selectionSet = (Set) myPie.getSelection(); if (selectionSet == null) { //Show message to select pie slice return null; } for (GraphSelection selection: selectionSet) { if (selection instanceof DataSelection) { DataSelection ds = (DataSelection) selection; value1= ds.getSeriesKey().get("myAttribute1"); value2 = ds.getSeriesKey().get("myArrribute2"); } } // Do whatever you want with collected values return null; }[/code]


11 March 2015

ADF DVT : Use of Click Listener for Pie Chart



When you want to perform some action on click and get the clicked value from the pie chart, you can use ClickListener added to the page bean. Here is the code you can use for the click listener:

1. Add it to your pie chart on the page


< dvt:pieGraph id ="graph5" value="#{bindings.yourView1.graphModel}" subType="PIE" dynamicResize="DYNAMIC_SIZE"
      clickListener="#{bean.myPieClickListener}" />



2. Add this to your bean

  public void myPieClickListener(ClickEvent evt)
  {
    ComponentHandle handle = evt.getComponentHandle();
    String myCode = null;
    if (handle instanceof DataComponentHandle)
    {
      DataComponentHandle dhandle = (DataComponentHandle) handle;
      Attributes[] seriesInfo = dhandle.getSeriesAttributes();
      if (seriesInfo != null)
      {
        for (Attributes attrs: seriesInfo)
        {
          myCode = (String) attrs.getValue(Attributes.ID_VALUE);
        }
      }
      //do whatever you want with your code
    }
  }

06 March 2015

ADF : Use Database Sequence in Entity Object

ADF Entity Object : How to use database sequence to populate EO attribute


If there is a requirement to use database sequence to populate an attribute of  ADF entity object, do the following:

1. Select the attribute where you want to use a sequence from attributes tab of an entity object
2. In details pane below, go to default value section
3. select "expression" radio button (one of three radio buttons - Literal, Expression and SQL)
4. add following groovy expression in the box provided below radio button

(new oracle.jbo.server.SequenceImpl("YOUR_SEQUENCE_NAME", adf.object.getDBTransaction())).getSequenceNumber()

5. Make sure that the sequence is available in the database you are connecting.
6. Save details and you are done, test your EO from Application Module tester or from the page.

Use Logger in ADF application

How to use ADF Logger in ADF Application


If you want to use Logger in your ADF application, add following to any Java class in your ADF application

First declare it

ADFLogger log = ADFLogger.createADFLogger(this.getClass());

or

private static final ADFLogger log =                ADFLogger.createADFLogger(MyClassName.class);

and the use it as

log.info("Logger output"); 

11 July 2009

How to submit InputText value with Enter Key in ADF Faces

My requirement was to have a input text box value submitted with enter key - without clicking any

button, invoke business logic and stay on the same page.
This is how it can be achieved


Firstly, I added valueChangeListener to the input box and associated it with a method in a managed

bean

Page XML:

add these

attributes to inputText tag

valueChangeListener="#{myBean.myMethod}"
onkeypress="return submitme()"

Secondly, I added JavaScript to the page, for submitting the form on click of enter key,
I have to name the form as myform in order to make this script work.

JavaScript

function submitme() {
if (window.event.keyCode == 13)
{
document.myform.submit();
} else {
return false;
}
}


And finally, this is the backing bean code. Here I am calling gobutton_action method, which will take

care of the business logic that needed to be invoked on submit. I can bind it with the a method of

the Application Module. You can write a code that invokes an AppModule method.


myBean.java

public void myMethod(ValueChangeEvent valueChangeEvent)
{
System.out.println("I am in Bean");
gobutton_action();
}



Now I can enter value in the textbox and hit enter key to submit the value.

22 June 2009

Access DBTransaction from ManagedBean in Oracle ADF

Oracle ADF - How to access DBTransaction from ManagedBean



While working on ADF project , there may be situation when we have to depend on plain old SQL query - for doing a specific job , and need to execute that SQL query right from the managed bean.


For executing the query we need to create a statement, and we have to access DBTransaction from within a managed bean.

Following code snippets will access DBTransaction in ManagedBean



There are two ways to access the DBTransaction from managed bean


situation one is, You have ADFUtils classes

You can Borrow ADFUtils classes from SRDemo application, which you can freely download,
ADFUtils and JSFUtils are extremely useful.


ApplicationModuleImpl am = (ApplicationModuleImpl)ADFUtils.getApplicationModuleForDataControl("myServiceDataControl");
Statement stmt = am.getDBTransaction().createStatement(0);



The second situation is, If you don't have ADFUtils Classes


FacesContext ctx = FacesContext.getCurrentInstance();

ValueBinding vb = ctx.getCurrentInstance().getApplication().createValueBinding("#{data}");

BindingContext bc = BindingContext)vb.getValue(ctx.getCurrentInstance());

DataControl dc = bc.findDataControl("myServiceDataControl");

ApplicationModuleImpl am = ((ApplicationModuleImpl)(ApplicationModule)dc.getDataProvider());

Statement stmt = am.getDBTransaction().createStatement(0);

How to find out DataControl name :


Open the DataBindings.cpx file and see the id attribute of the BC4JDataControl tag


Use your data control name when creating the DataControl object
here in this code I am using - BC4JDataControl id="myServiceDataControl"

10 November 2008

How to create db connection in JDeveloper

This video will show you how you can create a Database Connection using JDeveloper