Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label Dynamic. Show all posts
Showing posts with label Dynamic. Show all posts

Tuesday, 19 April 2016

Define WHERE Clause on dynamic ViewObject created on the fly

Wednesday, 19 November 2014

Populate Dynamic table and form using af:dynamicComponent and dynamic viewObject - Oracle ADF

This post is about a common development requirement- Can we increase or decrease number of fields , type of fields (columns in case of table), data in fields at run time?

Suppose i have to show data of Departments and Employees table on page using only one af:table component. It means columns should be generated dynamically at run time depending on any defined condition
So for this requirement i am using dynamic viewObject in model layer and af:dynamicComponent in view layer
See previous post about creating dynamic viewObject-
Creating Dynamic View Object at Runtime programmatically - Oracle ADF

See step by step implementation-
  • Create Fusion Web Application and follow the link posted above to create dynamic viewObject, in short create a viewObject using dual and a method in AMImpl to create dynamic viewObject from sql query


  •     /**Method to create viewObject using SQL query
         * @param query
    
    
    
    
    
    
    
         */
        public void createNewViewObject(String query) {
            ViewObject dynVo = this.getdynamic1();
            dynVo.remove();
            this.createViewObjectFromQueryStmt("dynamic1", query);
            this.getdynamic1().executeQuery();
        }
    

  • Created a page and added an inputText to enter SQL query and a button to process that query and create dynamic viewObject at run time


  • See Managed Bean code to process query, value of inputText is passed using component binding

  •     private RichInputText sqlQueryBind;
    
        public DynamicTableBean() {
        }
    
        /*****Generic Method to call operation binding**/
        public BindingContainer getBindingsCont() {
            return BindingContext.getCurrent().getCurrentBindingsEntry();
        }
    
        /**
         * Generic Method to execute operation Binding
         * */
        public OperationBinding executeOperation(String operation) {
            OperationBinding createParam = getBindingsCont().getOperationBinding(operation);
            return createParam;
    
        }
    
        /**Method to create viewObject
         * @param actionEvent
         */
        public void createViewObjectAction(ActionEvent actionEvent) {
            if (sqlQueryBind.getValue() != null) {
                OperationBinding ob = executeOperation("createNewViewObject");
                ob.getParamsMap().put("query", sqlQueryBind.getValue().toString());
                ob.execute();
            }
        }
    
        public void setSqlQueryBind(RichInputText sqlQueryBind) {
            this.sqlQueryBind = sqlQueryBind;
        }
    
        public RichInputText getSqlQueryBind() {
            return sqlQueryBind;
        }
    

  • Now dropped this dual viewObject on page as dynamic form and dynamic table from Data Control (this snap is about creating form)



  • Next is to change pageDef entry for this dynamic component , open pageDef and goto treeBinding. there is an entry for nodeDefinition, there will be separate treeBinding for form and table both (you should change both)

  •  <tree IterBinding="dynamic1Iterator" id="dynamic1">
                <nodeDefinition DefName="dynamictableapp.model.view.dynamicVO" Name="dynamic10"/>
            </tree>
    

    Change this entry like this-

     <tree IterBinding="dynamic1Iterator" id="dynamic1">
                <nodeDefinition Name="dynamic10"/>
            </tree>
    

  • Now run this application and enter SQL query in box and press process button


 Thanks, Happy Learning :)
Download -Sample ADF Application

Wednesday, 10 September 2014

Dynamic (parameterize) model level validation using message token -Oracle ADF

Hello all
This post falls under ADF Basics category (about a little trick in model layer) but about a common development requirement
How can we create dynamic ADF BC validation ? means it takes a parameter at run time and append it to validation message

Read previous post on model level validation-
Conditional Execution of Model (EO) level Validation- Oracle ADF
ViewObject Validation rules for transient attributes (Model level validation in ADF)

In this post I am using Departments table of oracle HR Schema



  • First step is same , prepare model (EO,VO and AM) using Departments table



  • Creating a business rule that DepartmentName can not be duplicate, for this created a alternate key in EntityObject 



  • Nnow creating unique key business rule for this alternate key and message that appears on validation failure (this is how we apply EO level validations)




  • Run AM and check in BC4J tester, create a new row and on entering duplicate DepartmentName this validation message appears -"Duplicate Department Name"


  • now my requirement is this message should be like - Duplicate Department Name <Administration> , so for this i have to pass parameter in message that shows entered DepartmentName on run-time. ADF provides built in feature to pass tokens in message and on run time it is replace with groovy expression value

  •  On running see desired output



  • to pass more than one parameter just add another token and set groovy for it, see the screens
 Output-


Thanks - Happy Learning :)

Wednesday, 18 September 2013

Using af:switcher in ADF Faces to dynamically render page components

Hello all,,
Sometimes we need to display page components on a condition basis , this can be achieved in adf using af:switcher component
Normally switcher component is a collection of multiple facets and on a given condition it decides that which facet should be rendered.

How to use af:switcher- see the steps

  • Create a Fusion web application and create business components using Departments and Employees table (HR Schema)
  •  Now create a page in view Controller and drop a switcher component from component palette
  • Switcher is pure server side component so it doesn't have any client representation, so next move is to add facets in af:switcher, to add facets in switcher,
    just right click--insert inside af:switcher-- facet



  • As in this tutorial i am going to show 2 tables(Departments U& Employees) so added 2 facets in af:switcher

  • Now time to drop tables in corresponding facets, Employees Table in Emp, Departments Table in Dept
  •  Now i have created a static List that has values D for Departments and E for Employees, when user selects D the Departments table will be shown and for E Employees table will be shown

  • to do this select af:switcher and go to FacetName property and open expression builder to write conditional expression
  •  Now run this page and select values in list to see- how switcher works

  Download Sample App Cheers :-)

Monday, 5 August 2013

Creating dynamic layout (form and UI Component) using ADF Faces

hello all,
today i had a scenario to create UI Components at run time and i tried to do that on my ADF page.
searched lot in Google and finally all summary is in post.

Suppose you have to create UI Components (input text, buttons, check-boxes etc ) or form (set of multiple UI Components) at runtime - follow these steps

  • Find a parent component to create child under it as any layout (panel form, panel group, af:form etc)
  • Suppose you have a page with a panel form layout, now you have to create child components in this form layout at runtime
  • Bind this form layout to managed bean

  • <af:panelFormLayout id="pfl1" rows="2" binding="#{DynamicCompBean.panelFormLay}"/>
    

  • Now thanks to Mahmoud A. Elsayed for this method, that adds child component to parent component

  •     public void addComponent(UIComponent parentUIComponent, UIComponent childUIComponent) {
            parentUIComponent.getChildren().add(childUIComponent);
            AdfFacesContext.getCurrentInstance().addPartialTarget(parentUIComponent);
        }
    

  • you can call this method , wherever you want to create UI Component and add it to page .



  • Now i have created a button on page and a radio box to select which component should be created
  • Now on button click , i have generated components conditionally based on selection
  • To generate any component - see managed bean code to create input text

  •             RichInputText ui = new RichInputText();
                ui.setId("rit1");
                ui.setLabel("Input text");
                ui.setValue("Hello ADF");
                ui.setContentStyle("font-weight:bold;color:red");
    

  • same as this ,for other component i have written code and set their properties in managed bean
  • look at managed bean code-

  • package dynamic.view.bean;
    
    import java.io.Serializable;
    
    import javax.faces.component.UIComponent;
    import javax.faces.event.ActionEvent;
    
    import oracle.adf.view.rich.component.rich.RichForm;
    import oracle.adf.view.rich.component.rich.input.RichInputText;
    import oracle.adf.view.rich.component.rich.input.RichSelectBooleanCheckbox;
    import oracle.adf.view.rich.component.rich.input.RichSelectOneRadio;
    import oracle.adf.view.rich.component.rich.layout.RichPanelFormLayout;
    import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
    import oracle.adf.view.rich.component.rich.output.RichOutputText;
    import oracle.adf.view.rich.context.AdfFacesContext;
    
    public class DynamicCompBean implements Serializable {
    
        /**Parent component to add childs in it*/
        private RichPanelFormLayout panelFormLay;
    
        /**Binding to select which component should be created*/
        private RichSelectOneRadio compTypeBind;
    
        public DynamicCompBean() {
        }
    
        /**Method to add child to parent component*/
        public void addComponent(UIComponent parentUIComponent, UIComponent childUIComponent) {
            parentUIComponent.getChildren().add(childUIComponent);
            AdfFacesContext.getCurrentInstance().addPartialTarget(parentUIComponent);
        }
    
        /**Button code to generate and add components conditionally*/
        public void createComptext(ActionEvent actionEvent) {
    
            if (compTypeBind.getValue().toString().equalsIgnoreCase("I")) {
                RichInputText ui = new RichInputText();
                ui.setId("rit1");
                ui.setLabel("Input text");
                ui.setValue("Hello ADF");
                ui.setContentStyle("font-weight:bold;color:red");
                addComponent(getPanelFormLay(), ui);
            } else if (compTypeBind.getValue().toString().equalsIgnoreCase("O")) {
                RichOutputText ui = new RichOutputText();
                ui.setId("rot1");
                ui.setValue("I am output text");
                ui.setInlineStyle("font-weight:bold;color:green");
                addComponent(getPanelFormLay(), ui);
            } else if (compTypeBind.getValue().toString().equalsIgnoreCase("C")) {
                RichSelectBooleanCheckbox ui = new RichSelectBooleanCheckbox();
                ui.setId("ch1");
                ui.setValue(true);
                ui.setLabel("CheckBox");
                addComponent(getPanelFormLay(), ui);
            } else if (compTypeBind.getValue().toString().equalsIgnoreCase("B")) {
                RichCommandButton ui = new RichCommandButton();
                ui.setId("ch1");
                ui.setText("Button");
                ui.setInlineStyle("font-weight:bold;");
                addComponent(getPanelFormLay(), ui);
            }
    
        }
    
    
        public void setPanelFormLay(RichPanelFormLayout panelFormLay) {
            this.panelFormLay = panelFormLay;
        }
    
        public RichPanelFormLayout getPanelFormLay() {
            return panelFormLay;
        }
    
        public void setCompTypeBind(RichSelectOneRadio compTypeBind) {
            this.compTypeBind = compTypeBind;
        }
    
        public RichSelectOneRadio getCompTypeBind() {
            return compTypeBind;
        }
    }
    

  • Now run this application and select input text to create-

  • Select others also and create a form

  • You can create complex forms using this

         Download Sample workspace-Download Sample

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