Tuesday 30 April 2013

How to Stretch an ADF Table to occupy maximum width

ADF Table can be stretched to occupy the maximum width available by using AFStretchWidth Style Class.
Table can be embedded inside PanelStretchLayout or PanelCollection component

For PanelStretchLayout component the Table must be embedded inside the center facet, and the Style Class of both the Table and Layout component must be set to AFStretchWidth.
        <af:panelStretchLayout id="psl1">
          <f:facet name="bottom"/>
          <f:facet name="center">
            <af:table inlineStyle="AFStretchWidth" ...>
               ....
           </af:table>
          </f:facet>
          <f:facet name="start"/>
          <f:facet name="end"/>
          <f:facet name="top"/>
        </af:panelStretchLayout>

instead of using AFStretchWidth, you can decide which column will get stretched using the attribute columnStretching for example:
columnStretching="last"

  
 <af:table ... columnStretching="columnId_that_you_want_to_stretch" ...>

Friday 19 April 2013

Problem with the taskflow invocation


If you face the following below error when rending the page, then the issue with the region with the task-flow:

java.lang.IllegalStateException: Attempt to validate an already invalid RegionSite

Solution is here:
Just set the following properties to the task-flow binding

go to bindings tab, select task-flow, then go to properties widow set
          activation: immediate,   Refresh: ifneeded

How to get Selected graph point details in ADF Graphs

To get the selected graph point information u need to set the click listener for the graph:

dvt:barGraph should have the clickListener
< dvt:barGraph id="Graph1"
value="#{bindings.View1.graphModel}"
subType="BAR_VERT_CLUST"
clickListener="#{MyBeab.clickAction}" ...>

In bean the clickListener should be implemented as follows:
 void processClick(ClickEvent event)
{
     ComponentHandle handle = event.getComponentHandle();
     if (handle instanceof DataComponentHandle)
     {
         DataComponentHandle dhandle = (DataComponentHandle)handle;
         // Get the value displayed in the series
         System.out.println("Value: " + dhandle.getValue(DataComponentHandle.UNFORMATTED_VALUE));
 
         // Get the series attributes
         Attributes [] seriesInfo = dhandle.getSeriesAttributes();
         if(seriesInfo != null)
         {
             for(Attributes attrs: seriesInfo)
             {
                 System.out.println("Series value: " + attrs.getValue(Attributes.LABEL_VALUE));
                 System.out.println("Series name: " + attrs.getValue(Attributes.LABEL_ATTRIBUTE));
                 System.out.println("Series value id: " + attrs.getValue(Attributes.ID_VALUE));
                 System.out.println("Series name id: " + attrs.getValue(Attributes.ID_ATTRIBUTE));
             }
         }
         // Get the group attributes
         Attributes [] groupInfo = dhandle.getGroupAttributes();
         if(groupInfo != null)
         {
             for(Attributes attrs: groupInfo)
             {
                 System.out.println("Group value: " + attrs.getValue(Attributes.LABEL_VALUE));
                 System.out.println("Group name: " + attrs.getValue(Attributes.LABEL_ATTRIBUTE)); 
             }
         }
     }
 }

How to populate an ADF table rows programatically?


Pass list of beans to the ListDataModel and bind it to ADF table 'Value' property

Each col will be populated with corresponding row.property.

Thursday 18 April 2013

How to get the value of the selected item in SelectOneChoice?

First way: set valuePasstrhu attribute to true. By default it will be false so it will return index of the selected item

Second way use the following code:

 public Row getLovRowAtIndex(String lovAttrName, Integer index) {
        Row row = null;
        try {
            DCBindingContainer binding = ADFUtils.getDCBindingContainer();
            JUCtrlListBinding list =
                (JUCtrlListBinding)binding.get(lovAttrName);
            String selectedValue = (String)list.getAttributeValue();
            list.getListIterBinding().setCurrentRowWithKeyValue(selectedValue);
            row = list.getListIterBinding().getRowAtRangeIndex(index);
        } catch (Exception e) {
           System.err.println("Error while getting row from LOV : " + e);
        }
        return row;
    }

Third way: Bind the Value attribute to the binding, when user selects an item then the corresponding value will be stored in to the binding.

How to define view criteria programmatically

The following code snippet will help you how to create a View Criteria programmatic:
  ViewObjectImpl empVOImpl = getEmployeeView1();           
   ViewCriteria vc = empVOImpl.createViewCriteria();
   ViewCriteriaRow vcr = vc.createViewCriteriaRow();           

   //criteria for employee id
   ViewCriteriaItem vci1 = vcr.ensureCriteriaItem("JobId");
   vci1.setValue("SH_CLERK");

   //criteria for showing employees whose salary are more than 10000
   ViewCriteriaItem vci2 = vcr.ensureCriteriaItem("Salary");
   vci2.setOperator(">");
   vci2.setValue(new Number(10000));

   //criteria for department
   int[] ids = {50,100};
   ViewCriteriaItem vci3 = vcr.ensureCriteriaItem("DepartmentId");
   vci3.setOperator("IN");
   int i = 0;
   for(int deptId: ids){
     vci3.setValue(i++, new Number(deptId));
   }
   vc.addElement(vcr);
   empVOImpl.applyViewCriteria(vc);
   System.out.println("Query: " + empVOImpl.getQuery());
   empVOImpl.executeQuery();