Please disable your adblock and script blockers to view this page

Search this blog

Monday, 16 December 2013

Checking Transaction Status of DataControl for Dirty/Modified transaction in ADF


Sometimes we need to check status of data control's transaction, when we have any form or table on page ,initially transaction is not dirty (it means there is no pending changes in binding layer)

If user changes any data set on page that is populated from ADF binding layer, status of transaction is modified as now there is pending changes on page .


When user perform commit or rollback operation then again transaction status changes.

So it is necessary to have basic understanding of Transaction Status and using this we can write some better piece of codes.
Example- suppose we have a save button in our Application that performs commit operation, when user clicks on that button, every time commit gets executed but logically if there is no change in binding layer then commit must not be executed.
So we can check transaction status on this button and if there is any pending changes in ADFm binding layer or transaction is dirty only then commit will be executed

  • I have created a sample application to check this , there is departments and location ViewObjects are on page and a button to check transaction status
  • Code to check transaction status-

  • public BindingContainer getBindings(){
            return BindingContext.getCurrent().getCurrentBindingsEntry();
        }
    
    DCBindingContainer dcbind =(DCBindingContainer)getBindings();
    dcbind.getDataControl().isTransactionModified()
    

    OR



    amObject.getDBTransaction().isDirty()
    

  • Initially see page status there is no pending changes so transaction is not dirty


  • Now i have changed DepartmentName attribute , then clicked on Check Transaction button


  • Now when data is committed again status got changed

Friday, 6 December 2013

Show current Date and Time on Page in Oracle ADF (refresh Date/time Programmatically)

Hello All,
in this tutorial i am going to explain that how to show current date and time on your ADF application page
Follow Steps-
  • Create a fusion web application and a page in it (i have used .jspx page)
  • Now drag an output text from component palette and drop it on page

  • Now select the output text and go to its property inspector then select value from Expression Builder as shown in image
  • Now in Expression Builder ,create a Managed Bean of type java.util.Date and assign its value to output text




  •  Now run your page and see current date is there
  • Now to format Date and Time , drag and drop af:convertDateTime  under output text from component palette



  •  Select convertDateTime and go to property inspector and change its pattern and run your page


  •  Now you have done basic configuration for Date/Time, if you want to refresh time (second and minute part) on page periodically then drop a poll component in page and create a poll listener in managed bean
  • Now write this simple code in your managed bean to invoke poll listener

  •     /**Binding of Output text*/
        private RichOutputText dateBind;
    
        public void setDateBind(RichOutputText dateBind) {
            this.dateBind = dateBind;
        }
    
        public RichOutputText getDateBind() {
            return dateBind;
        }
    
    
        /**Poll Listener Method ,handles Poll Event
         * @param pollEvent
         */
        public void refreshTime(PollEvent pollEvent) {
            AdfFacesContext.getCurrentInstance().addPartialTarget(dateBind);
    
        }
    

    And don't forget to set clientComponent property of outputText to true
  • Now Run your application , see in this video clip how your page get refreshed... Cheers ..!

Cheers :) Happy Learning

Tuesday, 26 November 2013

Apply Filter on af:table column programmatically ,Invoke 'FilterableQueryDescriptor' through managed bean

Hello All
This tutorial is about a requirement of filtering af:table column through code,
to achieve this we can invoke FilterableQueryDescriptor (FilterableQueryDescriptor is an abstract subclass of QueryDescriptor. It adds support for filtering of data and is typically used by the table component to filter data from a query )

Suppose i have department table and i have to filter on department column-
  • Create a Fusion Web Application and business components for Departments (HR Schema) table
  • now drag table on page and bind it to bean
  • Now drop a input text and button on page to enter Department Name
  • bind input text to bean and create ActionListener on button to filter Department Table
See XML source of Page-




<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="filterPage.jspx" id="d1">
            <af:messages id="m1"/>
            <af:form id="f1">
                <af:inputText label="Department Name" id="it5"
                              binding="#{pageFlowScope.FilterProgrammaticBean.deptNmBind}"/>
                <af:commandButton text="Filter" id="cb1"
                                  actionListener="#{pageFlowScope.FilterProgrammaticBean.filterTableAction}"/>
                <af:table value="#{bindings.DepartmentsView1.collectionModel}" var="row"
                          rows="#{bindings.DepartmentsView1.rangeSize}"
                          emptyText="#{bindings.DepartmentsView1.viewable ? 'No data to display.' : 'Access Denied.'}"
                          fetchSize="#{bindings.DepartmentsView1.rangeSize}" rowBandingInterval="1"
                          selectedRowKeys="#{bindings.DepartmentsView1.collectionModel.selectedRow}"
                          selectionListener="#{bindings.DepartmentsView1.collectionModel.makeCurrent}"
                          rowSelection="single" id="t1" styleClass="AFStretchWidth"
                          binding="#{pageFlowScope.FilterProgrammaticBean.deptTabBind}"
                          filterModel="#{bindings.DepartmentsView1Query.queryDescriptor}"
                          queryListener="#{bindings.DepartmentsView1Query.processQuery}" filterVisible="true"
                          varStatus="vs">
                    <af:column sortProperty="#{bindings.DepartmentsView1.hints.DepartmentId.name}" sortable="true"
                               headerText="#{bindings.DepartmentsView1.hints.DepartmentId.label}" id="c1"
                               filterable="true">
                        <af:inputText value="#{row.bindings.DepartmentId.inputValue}"
                                      label="#{bindings.DepartmentsView1.hints.DepartmentId.label}"
                                      required="#{bindings.DepartmentsView1.hints.DepartmentId.mandatory}"
                                      columns="#{bindings.DepartmentsView1.hints.DepartmentId.displayWidth}"
                                      maximumLength="#{bindings.DepartmentsView1.hints.DepartmentId.precision}"
                                      shortDesc="#{bindings.DepartmentsView1.hints.DepartmentId.tooltip}" id="it1"
                                      readOnly="true">
                            <f:validator binding="#{row.bindings.DepartmentId.validator}"/>
                            <af:convertNumber groupingUsed="false"
                                              pattern="#{bindings.DepartmentsView1.hints.DepartmentId.format}"/>
                        </af:inputText>
                    </af:column>
                    <af:column sortProperty="#{bindings.DepartmentsView1.hints.DepartmentName.name}" sortable="true"
                               headerText="#{bindings.DepartmentsView1.hints.DepartmentName.label}" id="c2"
                               filterable="true">
                        <af:inputText value="#{row.bindings.DepartmentName.inputValue}"
                                      label="#{bindings.DepartmentsView1.hints.DepartmentName.label}"
                                      required="#{bindings.DepartmentsView1.hints.DepartmentName.mandatory}"
                                      columns="#{bindings.DepartmentsView1.hints.DepartmentName.displayWidth}"
                                      maximumLength="#{bindings.DepartmentsView1.hints.DepartmentName.precision}"
                                      shortDesc="#{bindings.DepartmentsView1.hints.DepartmentName.tooltip}" id="it2"
                                      readOnly="true">
                            <f:validator binding="#{row.bindings.DepartmentName.validator}"/>
                        </af:inputText>
                    </af:column>
                    <af:column sortProperty="#{bindings.DepartmentsView1.hints.ManagerId.name}" sortable="true"
                               headerText="#{bindings.DepartmentsView1.hints.ManagerId.label}" id="c3"
                               filterable="true">
                        <af:inputText value="#{row.bindings.ManagerId.inputValue}"
                                      label="#{bindings.DepartmentsView1.hints.ManagerId.label}"
                                      required="#{bindings.DepartmentsView1.hints.ManagerId.mandatory}"
                                      columns="#{bindings.DepartmentsView1.hints.ManagerId.displayWidth}"
                                      maximumLength="#{bindings.DepartmentsView1.hints.ManagerId.precision}"
                                      shortDesc="#{bindings.DepartmentsView1.hints.ManagerId.tooltip}" id="it3"
                                      readOnly="true">
                            <f:validator binding="#{row.bindings.ManagerId.validator}"/>
                            <af:convertNumber groupingUsed="false"
                                              pattern="#{bindings.DepartmentsView1.hints.ManagerId.format}"/>
                        </af:inputText>
                    </af:column>
                    <af:column sortProperty="#{bindings.DepartmentsView1.hints.LocationId.name}" sortable="true"
                               headerText="#{bindings.DepartmentsView1.hints.LocationId.label}" id="c4"
                               filterable="true">
                        <af:inputText value="#{row.bindings.LocationId.inputValue}"
                                      label="#{bindings.DepartmentsView1.hints.LocationId.label}"
                                      required="#{bindings.DepartmentsView1.hints.LocationId.mandatory}"
                                      columns="#{bindings.DepartmentsView1.hints.LocationId.displayWidth}"
                                      maximumLength="#{bindings.DepartmentsView1.hints.LocationId.precision}"
                                      shortDesc="#{bindings.DepartmentsView1.hints.LocationId.tooltip}" id="it4"
                                      readOnly="true">
                            <f:validator binding="#{row.bindings.LocationId.validator}"/>
                            <af:convertNumber groupingUsed="false"
                                              pattern="#{bindings.DepartmentsView1.hints.LocationId.format}"/>
                        </af:inputText>
                    </af:column>
                </af:table>
            </af:form>
        </af:document>
    </f:view>
</jsp:root>

Managed Bean Code-


package filter.view;

import java.util.Map;

import javax.faces.event.ActionEvent;

import oracle.adf.view.rich.component.rich.data.RichTable;
import oracle.adf.view.rich.component.rich.input.RichInputText;
import oracle.adf.view.rich.context.AdfFacesContext;
import oracle.adf.view.rich.event.QueryEvent;
import oracle.adf.view.rich.model.FilterableQueryDescriptor;


public class FilterProgrammaticBean {
    private RichInputText deptNmBind;
    private RichTable deptTabBind;

    public FilterProgrammaticBean() {
    }

    public void setDeptNmBind(RichInputText deptNmBind) {
        this.deptNmBind = deptNmBind;
    }

    public RichInputText getDeptNmBind() {
        return deptNmBind;
    }

    public void setDeptTabBind(RichTable deptTabBind) {
        this.deptTabBind = deptTabBind;
    }

    public RichTable getDeptTabBind() {
        return deptTabBind;
    }

    /**Method to invoke FilterableQueryDescriptor and Filter Department table
     * @param actionEvent
     */
    public void filterTableAction(ActionEvent actionEvent) {
        RichTable tbl = this.getDeptTabBind();
        FilterableQueryDescriptor filterQD = (FilterableQueryDescriptor)tbl.getFilterModel();
        Map filterCriteria = filterQD.getFilterCriteria();
        filterCriteria.put("DepartmentName", deptNmBind.getValue());
        getDeptTabBind().queueEvent(new QueryEvent(getDeptTabBind(), filterQD));
        AdfFacesContext.getCurrentInstance().addPartialTarget(this.getDeptTabBind());
    }
}

Run your Application-





Cheers- Download Sample App