Monday, July 30, 2012

How to configure a specific browser in Jdeveloper

Greetings,


There is a cool feature in Jdeveloper, you can configure any type of browser that you want to launch when your web application starts up,


How to get a UI component in Backing bean without binding to a backing bean

Hello,

I thought of sharing useful tip, how to get a UI component ( SelectOneChoice, InputText, etc..) instance in a backing bean without exactly binding a UI component to a backing bean. This is very useful especially building complex UI screens and avoid binding too many UI components to a backing bean

Follow the below code in your backing bean


    UIComponent comp = null;
    FacesContext facesCtx = FacesContext.getCurrentInstance();
    if (facesCtx != null)
    {
      UIComponent root = facesContext.getViewRoot();
      comp = findUIComponent(root, pComponentId);
}


    public UIComponent findUIComponent(UIComponent pBase, String pID) {
        if (pID.equals(pBase.getId()))
            return pBase;


        UIComponent child = null;
        UIComponent result = null;
        Iterator childrens = pBase.getFacetsAndChildren();
        while (childrens.hasNext() && (result == null)) {
            child = (UIComponent)childrens.next();
            if (pID.equals(child.getId())) {
                result = child;
                break;
            }
            result = findUIComponent(child, pID);
            if (result != null) {
                break;
            }
        }
        return result;
    }

Thursday, July 26, 2012

How to Display Error/Warning/Information Messages

This blog explains about printing error/waring/information messages from backing bean & application module impl class

Step1: Displaying error message from backing bean


       

import javax.faces.context.FacesContext;
import javax.faces.application.FacesMessage
FacesContext facesContext = FacesContext.getCurrentInstance();
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error while Saving","Error while saving")
facesContext.addMessage(null,msg);




Step2: Displaying Information message from backing bean



       
FacesContext facesContext = FacesContext.getCurrentInstance();
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Saved Successfully",
                                    "Saved Successfully")
facesContext.addMessage(null,msg);





Step3: Displaying Warning message from backing bean


       
FacesContext facesContext = FacesContext.getCurrentInstance();
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Saved Successfully",
                                    "Saved Successfully")
facesContext.addMessage(null,msg);
Step4: Displaying Error Messages from Application Module
throw new JboException("Error");
Step5: Displaying Warning message from Application Module
getDBTransaction().addWarning(new JboWarning("Warning"));










Wednesday, July 25, 2012

How to invoke Application Module method from backing bean

It would be common requirement to invoke a application module method from the backing bean. Unless if it is really required then only advisable to write a separate method in backing bean to invoke application module method. Follow the below steps to achieve this

Step1 :  Define the application module method in respective page definition as shown in below screen shot
 - Expose the method that you invoke in client interface, Goto Page Definition bindings and add the method bindings as shown below


Step2:  Write the below code in backing bean to invoke application module method

       

import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.binding.BindingContainer;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import oracle.binding.OperationBinding;

  FacesContext facesContext = FacesContext.getCurrentInstance();
  Application app = facesContext.getApplication();
  ExpressionFactory elFactory = app.getExpressionFactory();
  ELContext elContext = facesContext.getELContext();
  ValueExpression valueExp =
    elFactory.createValueExpression(elContext, "#{bindings}", Object.class);
  BindingContainer binding= (BindingContainer)valueExp.getValue(elContext);
  OperationBinding operationBinding=binding.getOperationBinding("createCurrentCustomerRow");
  // Set the Input parameters to the operation bindings as below
     operationBinding.getParamsMap().put("pCustomerID", "100");  
  // Invoke the Application module method
  operationBinding.execute();
  // Get the result from operation bindings
  Object obj =operationBinding.getResult();
       
 


Alternative approach
import oracle.binding.OperationBinding;
   /**
    * This method returns the Operation Bindings based on given input opeation name
    */
    public static OperationBinding getOperationBinding(String pOperationName) {
        BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
        return bc.getOperationBinding(pOperationName);
    }

// Below is the code snippet to invoke above method

                OperationBinding oBindings =
                    getOperationBinding("getEmployeeDetails");
// Pass Input parameters
                oBindings.getParamsMap().put("empID", locRow.getDealerId());
                oBindings.getParamsMap().put("empLocID",
                                             locRow.getDealerLocationId());
                oBindings.execute();



How to get RowImpl class in backing bean

It would be common requirement in ADF to get an instance for a RowImpl class in backing bean, Backing bean is associated to a page fragment, Page fragment page definition binds to a respective VOIterator.

Below are the steps to get get Row Instance in backing bean.

Step1:  Bind the view object to page definition as shown in below screen shot


Step2:   Follow the below code in Backing bean


import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.binding.BindingContainer;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;


private Row getRowFromBinding(){
FacesContext facesContext = FacesContext.getCurrentInstance();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExp =
 elFactory.createValueExpression(elContext, "#{bindings}", Object.class);
DCBindingContainer binding= (DCBindingContainer)valueExp.getValue(elContext);

 // Here you have to pass the VOIterator name and get the corresponding Iteratorbinding

DCIteratorBinding itrBinding=binding.findIteratorBinding("LoactionPoolViewIterator")
Row row =itrBinding.getCurrentRow();
}

How to progrmatically List of Values in SelectOneChoice

This blog explains about how to programatically populate list of values dynamically in a <af:SelectOneChoice> component


Step1 : Drag <af:selectOneChoice> component from component pallet to page

Step2 : JSFF - Bind <f:selectItems> to a backing bean method as shown below.

 <af:selectOneChoice value="#{bindings.CustomerID.inputValue}"
             label=""
             required="#{bindings.CustomerID.hints.mandatory}"
             shortDesc="#{bindings.CustomerID.hints.tooltip}"
             id="cusID" autoSubmit="true"
             valuePassThru="true">
       <f:selectItems 
                value="#{pageFlowScope.EquipmentPoolBean.customerList}"
                id="si2"/>
       </af:selectOneChoice>
           
 Step2:  Implement corresponding backing bean method to return List<SelectItem> as shown below
   

       

   public List getCustomerList()
  {
// Prepare list of values based on your requirement
    List customerList = new ArrayList();
    customerList.add(new SelectItem("CUST1","Customer1");
    customerList.add(new SelectItem("CUST2","Customer2");
    customerList.add(new SelectItem("CUST3","Customer3");
    return customerList;
  }
       
 




Monday, July 23, 2012

How to get a selected row from af:table component in backing bean

Hello,
  This might be very common requirement for any ADF developer , to get a selected row(s) from <af:table> component in a backing bean.

// Table Binding
<af:table value="#{bindings.EmpVO.collectionModel}" var="row"
          rows="#{bindings. EmpVO .rangeSize}"
          emptyText="#{bindings. EmpVO .viewable ? 'No data to display.' : 'Access Denied.'}"
          fetchSize="#{bindings. EmpVO .rangeSize}"
          rowBandingInterval="0"
          rowSelection="multiple" id="t1"
          styleClass="AFStretchWidth" columnSelection="multiple"
          first="0" contentDelivery="immediate" autoHeightRows="10"
          binding="#{pageFlowScope.ExampleBean.employeeTable}">

Below approach is advisable, If multiple selection rows required 

       

// Get the instance for table component in backing bean
UIXTable table = getEmployeeTable();
// Get the Selected Row key set iterator
Iterator selectionIt = table.getSelectedRowKeys().iterator();
while(selectionIt.hasNext()){
Object  rowKey = selectionIt.next();
 table.setRowKey(rowKey);
 int index = table.getRowIndex(); 
      FacesCtrlHierNodeBinding row =
        (FacesCtrlHierNodeBinding) table.getRowData(index);
Row selectedRow = row.getRow();
}
       
 


-- Below approach is advisable if there is only single row selection is enabled.


       

// Get the instance for table component in backing bean
UIXTable table = getEmployeeTable();
// Get the Selected Row key set iterator
Iterator selectionIt = table.getSelectedRowKeys().iterator();
while(selectionIt.hasNext()){
Object  rowKey = selectionIt.next();
table.setRowKey(rowKey); int index = table.getRowIndex();
FacesCtrlHierNodeBinding row = (FacesCtrlHierNodeBinding) table.getRowData(index);
Row selectedRow = row.getRow();
}
       
 




Tuesday, July 10, 2012

How to get Selected Value or Selected Index from SelectManyChoice ADF Component



af:selectManyChoice : This component is very useful especially if you have a requirement to display a list values and provide the option to select more than one value from the drop down. For each item displayed as part of List will have a Check box, so that user can select more than one check box from the drop down list.






How to make this component on Page fragment ?  Create a View Object on model layer, and drag it as selectManyChoice on to the page fragment.








Write a java method in backing bean as below to fetch selected values or indices.

    BindingContext bc = BindingContext.getCurrent();
    DCBindingContainer binding =
      (DCBindingContainer) bc.getCurrentBindingsEntry();
    JUCtrlListBinding splHandlBinding =
      (JUCtrlListBinding) binding.get("SpecialHndlgLOVVA");
    Object[] splHandling = splHandlBinding.getSelectedValues();


Here is the code to get selected indices values



    BindingContext bc = BindingContext.getCurrent();
    DCBindingContainer binding =
      (DCBindingContainer) bc.getCurrentBindingsEntry();
    JUCtrlListBinding splHandlBinding =
      (JUCtrlListBinding) binding.get("SpecialHndlgLOVVA");
    Object[] splHandling = splHandlBinding.getSelectedIndices();