ADF: Using UI Categories with Dynamic form

JDev 11g R2 has new interesting feature “UI Categories”. It allows us to group VO’s attributes declaratively at the view object definition level. For example, “UI Categories” tab for my VEmployees view object looks like this:

By default every view object has one predefined category “Default”. I created three new categories “Name”, Contact, Other and assigned attributes to them. At this tab we can also define Label and Tooltip for our categories. In the Application Module Tester window it looks like this:

According to the documentation UI Categories should be utilized by Dynamic forms and Search forms. ADF Faces Dynamic Form component really has new attribute Category. The form filters VO’s attributes and shows only attributes of the specified category. For example, if I wanted to show attributes of the Name category, I would use the following construction:

          <dynamic:form value="#{bindings.VEmployeesIterator}" id="f3" 
                        category="Name"/>

So, if we want to show different categories separately, we have to use <dynamic:form tag for each category. But the documentation provide very interesting sentence “In the case of dynamic forms, the attributes from each category will appear in a separate tab“. I guess that we are expected to implement this feature by ourselves :). In this post I’m going to show how we can do it

In the implementation class of my view object I defined some API method to get all UI Categoties of the view object except default one:

    public List<Category> getAttrCategries() {
        return getOrderedCategories(false, //except Default
                                    CategoryType.ATTRIBUTE, null); 
    }

In order to draw tabs on the page for each UI Categogry I used the following jspx code:

So, in this simple construction I use forEach tag within navgationPane to draw commandNavigationItem for each category. The Java code of the MainDynamicBean managed bean looks like this:

    //Currently selected tab
    private String selectedItem;

    //Getting categories list
    public List<Category> getCategoryList() {
        return (List<Category>) resolveExpression("#{bindings.VEmployeesIterator.viewObject.attrCategries}");
    }
    
    //Just a setter
    public void setSelectedItem(String selectedItem) {
        this.selectedItem = selectedItem;
    }

    //Getting selected item
    public String getSelectedItem() {
        //If nothing is selected, then select the first one
        if (selectedItem == null) {
            List<Category> l = getCategoryList();
            if (l.size()>0) selectedItem =  l.get(0).getName();                
        }        
        
        return selectedItem;
    }

    //Resolving EL expressions
    public static Object resolveExpression(String expression) {
           FacesContext facesContext =  FacesContext.getCurrentInstance();
           Application app = facesContext.getApplication();
           ExpressionFactory elFactory = app.getExpressionFactory();
           ELContext elContext = facesContext.getELContext();
           ValueExpression valueExp = 
               elFactory.createValueExpression(elContext, expression, 
                                               Object.class);
           return valueExp.getValue(elContext);
       }

And finally, I use the following construction to draw Dynamic form with attributes of the selected category:

   <dynamic:form value="#{bindings.VEmployeesIterator}" id="f2"
                  binding="#{MainDynamicBean.dynform}"
    forceRefresh="#{MainDynamicBean.needRefresh}"/>

And appropriate piece of Java code:

    private DynamicForm dynform;
    
    //Setter
    public void setDynform(DynamicForm dynform) {
        this.dynform = dynform;
    }

    //Getter
    public DynamicForm getDynform() {
        return dynform;
    }
        
    public Boolean getNeedRefresh() {
        //If selected category is not equal to dynform's category
        //then set needed category and refresh the dynamic form
        if (dynform.getCategory()!=getSelectedItem()) {
           this.dynform.setCategory(getSelectedItem()); 
           return true;
        }
        else return false;              
    }

As the result of our work we get the following screens:

That’s all!
You can download sample application for this post.

Reference: Using UI Categories with Dynamic form from our JCG partner Eugene Fedorenko at the ADF Practice blog.

Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

Leave a Reply


six × 2 =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books