Monday, 25 February 2013

Code to find an UI Component in an Oracle ADF Application

## Find an UI Component in the page

Hello all,
There are cases where you have to find a component on Page by id in the bean. Here is the method.


private UIComponent findComponentOnPage(String id){    
    String comp = id;
   //see ADF Code Corner sample #58 to read about the code
//used in the search below
FacesContext fctx = FacesContext.getCurrentInstance();
UIViewRoot root = fctx.getViewRoot();            
   root.invokeOnComponent(fctx,comp,
new ContextCallback(){
      public void invokeContextCallback(FacesContext facesContext,UIComponent uiComponent) {
       lookupComponent = uiComponent;
     }         
  });
return lookupComponent;
}

ADF: Decimal Number validator



## Decimal Number validator


public void Number_validatorDecimal(FacesContext facesContext, UIComponent uIComponent, Object object)
{
       BigDecimal value =(BigDecimal)object;
       if (value == null) {
           return;
       }
       if(value.floatValue()<0.00){
           String error = "Value should be greater than zero.";
           throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, error, null));
       }

   }