Please disable your adblock and script blockers to view this page

Search this blog

Friday, 5 July 2013

Changing af:convertNumber Format according to Locale- Oracle ADF

Simple post with very simple application-
we can covert a Numeric field format according to standard locale in ADF Faces.
when we have a numeric field on page there is a converter inside it, called af:convertNumber is extension of the standard JSF javax.faces.convert.NumberConverter.

 user can change it for Integer digits , fraction digits etc. but here i am talking about format of Number(Amount), to do this follow these steps.
  • Change GroupingUsed to true, by default it is true
  • Now set Locale, you can do this using managed bean or simply write it here
  • Managed Bean code to create Locale-  private Locale format=Locale.ENGLISH;
  • Now see various formats of Amount using Locale-



Using en-US-
 Using fr-
 Using hi-IN-for Hindi fonts
 Using de-DE -




so this is the thing how you can change formatting , this can also be done by managed bean.

  • Create a variable of type Locale and its getter -setter
  • Use it in Locale field of af:convertNumber  

  •     public void chinaButton(ActionEvent actionEvent) {
            this.setFormat(Locale.CHINA);
        }
        public void frenchButton(ActionEvent actionEvent) {
            this.setFormat(Locale.FRENCH);
        }
    
        public void italianButton(ActionEvent actionEvent) {
            this.setFormat(Locale.ITALIAN);
        }
    

  • You can also set Max and Min fraction digits in af:convertNumber

Wednesday, 3 July 2013

Creating Dynamic View Object at Runtime programmatically - Oracle ADF

Dynamic ViewObject refers to creating ViewObject at Runtime using SQL statement,
ApplicationModuleImpl has a method to create ViewObject using Sql statement i;e createViewObjectFromQueryStmt .

this method creates a readonly viewObject at runtime when query is processed in the method

Follow these simple steps-

  • First create a dummy ViewObject using dual  


  • Now add this ViewObject to Application Module

  • I am doing this in managed bean, get application module and call method to create dynamic ViewObject
  •          get Application Module-




        public Object resolvElDC(String data) {
            FacesContext fc = FacesContext.getCurrentInstance();
            Application app = fc.getApplication();
            ExpressionFactory elFactory = app.getExpressionFactory();
            ELContext elContext = fc.getELContext();
            ValueExpression valueExp =
                elFactory.createValueExpression(elContext, "#{data." + data + ".dataProvider}", Object.class);
            return valueExp.getValue(elContext);
        }
    
        public dynamicAMImpl getAm() {
            dynamicAMImpl am = (dynamicAMImpl)resolvElDC("dynamicAMDataControl");
            return am;
        }
    

            create dynamic ViewObject-


            ViewObject dynVo = getAm().getdynamic1();
            dynVo.remove();
            getAm().createViewObjectFromQueryStmt("dynamic1", query);
    

  • Now Run your application and see-


Download -Sample ADF Application

Monday, 1 July 2013

Update Model Values while Validation (Exception) occurs on page on Value Change event- Oracle ADF (processUpdates)

In ADF when we have some validation on page and we try to submit any value, but normally after validation (Exception) values are not updated in Model until exception is handled.
This tutorial is about how to update values in Model while exception on page.
For a scenario, i have used department (default HR Schema) table and form in a JSP XML fragment inside bounded taskflow.
In form Department Id and Department Name is mandatory field, ManagerId and Location Id has auto submit true.
  • I have dropped createInsert,Execute,Commit and Rollback as buttons on page




  • Click on create button and first enter manager id, as this field has autosubmit true so on submission of value page is validated and then Required Fields throw exception, and after exception you can see that manager id & location id is not updated in Model, and not reflected in af:table also.


  •  Normally what we do, set immediate true to skip validations, but in this case i have witten ValueChangeListener on manager Id and Location Id to process values in Model.- see code

  •     public void mangrIdVCE(ValueChangeEvent vce) {
            vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
        }
    

  • processUpdates() method of UIComponent class perform the coponent tree processing for all facet of this component by Update Model Values phase of request processing, and pushes data to Model

  • Now after calling this method, run application- Now values are populated in af:table and validation is still there on page


  • this approach can be used while using validators on page and want to process some values after validation (as conditional validation of some fields etc)
  • Download sample application -Sample App