Monday 28 December 2015

ADF | Fetching Multiple selected Rows from a Table populated from POJO in ADF

Hi,

This is again an Extension to my previous post on how we can perform edit on a table populated from POJO. http://adfjavacodes.blogspot.com/2015/12/adf-performing-edit-in-table-from-pojo.html

Everything is same from my previous post.
There are certain changes in the application. They are :

Here I have enabled Multiple row selection for the table from the property inspectior to
 <af:table var="row" rowBandingInterval="0" id="t1" value="#{viewScope.BookBean.bookInfo}"
                                  rowSelection="multiple" binding="#{viewScope.BookBean.tableBinding}">

I have also created a binding of the table for getting the  Multiple selected rows from the table.
Here is the code of the of the Bean where I have created a method that will fetch the selected rows from the table.


package edittableonpojo.view.bean;

import edittableonpojo.view.dc.BookInfo;

import java.util.ArrayList;

import java.util.Iterator;

import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

import oracle.adf.view.rich.component.rich.data.RichTable;

import org.apache.myfaces.trinidad.model.RowKeySet;

public class BookBean {
    private ArrayList<BookInfo> bookDtls = new ArrayList<BookInfo>();
    private RichTable tableBinding;

    public BookBean() {
        bookDtls.add(new BookInfo("1A", "The Alchemist", "Paulo Cohelo"));
        bookDtls.add(new BookInfo("2A", "Game Of Thrones", "George R. R. Martin"));
        bookDtls.add(new BookInfo("3A", "Five Point Someone", "Chetan Bhagat"));
        bookDtls.add(new BookInfo("4A", "Harry Potter", "J.K.Rowling"));
        bookDtls.add(new BookInfo("5A", "Wings of Fire", "A.P.J Abdul Kalam"));
    }

    public ArrayList<BookInfo> getBookInfo() {
        return bookDtls;
    }
    
    public void printValues(ActionEvent ace){
        for(BookInfo row : bookDtls){
            System.out.println("Row : "+row.toString());
        }
    }

    public void fetchSelectedValuesAL(ActionEvent actionEvent) {
        ArrayList<BookInfo> selectedRows = new ArrayList<BookInfo>();
        RowKeySet keySet = getTableBinding().getSelectedRowKeys();
        Iterator<Object> itr = keySet.iterator();
        while(itr.hasNext()){
            // next gives the index of the selected row
            Object next = itr.next();
            // here we have fetched the row on index from the bookDtls list
            selectedRows.add(bookDtls.get((Integer)next));
        }
        System.out.println("Selected Rows are : "+selectedRows.toString());
    }

    public void setTableBinding(RichTable tableBinding) {
        this.tableBinding = tableBinding;
    }

    public RichTable getTableBinding() {
        return tableBinding;
    }
}

On running the application ,  I have selected Two rows from the table.

On clicking "Get Selected Values" button.



Here is the Sample Application : EditableTableOnPOJO.rar

Performing Edit in a table from POJO in Oracle ADF

Hi,

This post is about Editing the values of the Table. You can learn how to populate table from the arrayList from my previous blog.http://adfjavacodes.blogspot.com/2013/04/adf-populating-adf-table-from-bean.html


Every step is same as in my previous post.
There only one thing needs to be changed. Suppose here we have to edit the BookDesc from the front End.
For doing this, We just need to provide the editable property in an inputText and that’s it. The editing in automatically handled.

We have to edit the Book Description Column, So I have just replaced the output text component with an input text. Here is the code for the same.

Here is the code of the jspx page. I have also added a button to print the updated Values of the List.

On running the page .

Now I have changed the Description of one Book to 
On clicking Show Current Values in the List  values are being printed in the console like


SO as we can see the row have been updated.

Here is the Sample Application : EditableTableOnPOJO.rar

Friday 25 December 2015

JAVA : Creating a Webservice using JAX-WS in java

Hi,

Today I am going to demonstrate how we can publish and consume a JAX-WS based webservice.

For this I have created a Simple Java Application that contains webservice that can perform simple calculation
  1. First we need to define what resource or class that we are going to publish.
  2. For that we have to create an Interface named Calculator.java on the basis of which we will publish the webservice. The interface is not exactly needed but this help in maintaining and using the web service from other Java clients far easier.
     
    package calcws.inter;
     
    import javax.jws.WebMethod;
    import javax.jws.WebService;
    import javax.jws.soap.SOAPBinding;
    import javax.jws.soap.SOAPBinding.Style;
     
    //Service Endpoint Interface
    @WebService
    @SOAPBinding(style = Style.RPC)
    public interface Calculator {
        @WebMethod
        Integer addTwoNumbers(Integer firstNum, Integer secondNum);
    }
    
  1. So now we need to create a implementation of the Calculator interface.

    package calcws.impl;
    
    import calcws.inter.Calculator;
    
    import javax.jws.WebService;
    //Service Implementation
    @WebService(serviceName = "CalculatorService", // This is the name of the webservice
                endpointInterface = "calcws.inter.Calculator")
    public class CalculatorImpl implements Calculator {
    
        @Override
        public Integer addTwoNumbers(Integer firstNum, Integer secondNum) {
            // TODO Implement this method
            return firstNum + secondNum;
        }
    }
    
  1. So now we have created the implementation class and now need to publish the class and for this i have created a  Class Publisher.java
    package calcws.publ;
    
    import calcws.impl.CalculatorImpl;
    
    import javax.xml.ws.Endpoint;
    
    public class Publisher {
        public Publisher() {
            super();
        }
    
        public static void main(String[] args) {
            // 1 : Url for the webservice
            // 2 : The the implementation class to be Published
            Endpoint.publish("http://localhost:9999/ws/calc", new CalculatorImpl());
        }
    }
    
  1. Now we have to create a class that will consume the published webservice.
     
    package calcws.client;
    
    import java.net.URL;
    
    import calcws.inter.Calculator;
    
    import javax.xml.namespace.QName;
    import javax.xml.ws.Service;
    
    public class Consumer {
        public Consumer() {
            super();
        }
    
        public static void main(String[] args) throws Exception {
            URL url = new URL("http://localhost:9999/ws/calc?wsdl");
            //1st argument service URI, refer to wsdl document above
            //2nd argument is service name, refer to wsdl document above
            QName qname = new QName("http://impl.calcws/", "CalculatorService");
            Service service = Service.create(url, qname);
            Calculator calc = service.getPort(Calculator.class);
            Integer addTwoNumbers = calc.addTwoNumbers(20, 40);
            System.out.println("The sum is  : " + addTwoNumbers);
        }
    }
    
  1. After this first run the Publisher class and  after that Run the Client to call the service.
    Here is the output.


Reference : http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/
You can download sampleapplication at :  CalcWS

Thursday 17 December 2015

How to programmatically set Bind Variable in an LOV in ADF

Hello,

This is again a post about ADF Basics.

Today I am going to demonstrate a  how we can set bindVariable in an Lov programatically without using viewAccessor of the viewObject.

For the demonstration I have created a temporary viewObject and a department ViewObject through which Lov will be made.

I have created a TempVo with a Transient attribute EmployeeIdTrans on which lov of EmployeesVO will be created .
In the EmployeeVo I have created a viewCriteria as follows.



Then apply the Lov on the basis of this EmployeeVO in the TempVO.



In the viewAccessor of the lov Select the ViewCritera



Drag the EmployeeIdTrans on the Jspx page and create a single selection lov.
Then add a new Input text box from which we will fetch the value of the department on which the lov needs to be filtered.
Here is the code of the jspx page

 <af:panelBox text="Set BindVariable in an Lov Programmatically" id="pb1">
                    <f:facet name="toolbar"/>
                    <af:panelGroupLayout id="pgl1" layout="horizontal">
                        <af:inputText label="Department Id" id="it1"
                                      autoSubmit="true" value="#{viewScope.TestBean.deptId}"/>
                        <af:button text="Set Department Id" id="b1"
                                   actionListener="#{viewScope.TestBean.setLovBindVarAL}"/>
                    </af:panelGroupLayout>
                    <af:spacer width="10" height="10" id="s1"/>
                    <af:selectOneChoice value="#{bindings.EmployeeIdTrans.inputValue}"
                                        label="Employees"
                                        required="#{bindings.EmployeeIdTrans.hints.mandatory}"
                                        shortDesc="#{bindings.EmployeeIdTrans.hints.tooltip}" id="soc1"
                                        partialTriggers="b1">
                        <f:selectItems value="#{bindings.EmployeeIdTrans.items}" id="si1"/>
                        <f:validator binding="#{bindings.EmployeeIdTrans.validator}"/>
                    </af:selectOneChoice>
                </af:panelBox>

Then create a method in ApplicaitonModuleImpl that will set the value bindVariable and execute the lov and then call it in the bean.

 /**
     * Method to execute Lov with bind variables
     * @param deptId
     */
    public void setBindVarAndExceuteLov(Integer deptId){
        Row currentRow = getTemp1().getCurrentRow();
        RowSet lovVO = (RowSet)currentRow.getAttribute("EmployeesVO1");
        lovVO.setNamedWhereClauseParam("DeptIdBind", deptId);
        lovVO.executeQuery();
    }

You can refer this if you want to know how to call a method to ApplicationModuleImpl in Bean http://adfjavacodes.blogspot.com/2013/09/calling-method-defined-in-impl-class-of.html

Here is the code used in the Bean.



package bindvariableinlovapp.view;

import javax.faces.event.ActionEvent;

import oracle.adf.model.BindingContext;
import oracle.adf.view.rich.component.rich.input.RichInputText;

import oracle.binding.OperationBinding;

public class TestBean {
    private Integer deptId;

    public void setDeptId(Integer deptId) {
        this.deptId = deptId;
    }

    public Integer getDeptId() {
        return deptId;
    }

    public TestBean() {
    }

    public OperationBinding getBindings(String binding){
        return BindingContext.getCurrent().getCurrentBindingsEntry().getOperationBinding(binding);
    }
    public void setLovBindVarAL(ActionEvent actionEvent) {
        OperationBinding binding = getBindings("setBindVarAndExceuteLov");
        binding.getParamsMap().put("deptId", deptId);
        binding.execute();
    }

}

On running the application it shows all the departments.

On filtering with department Id 1.


Here is the sample application : ProgramaticValueOfBindVarInLovApp

Tuesday 15 December 2015

ADF: Disabling Input Field for Date Component af:inputDate

Hello all,

This post is a basic post regarding a scenario in which we had to provide a date component and disable the inputField in af:inputDate component.

There are many ways to implement this scenario, this is one of those.
For the the demonstration, I have created a TemporaryVO and create a transient attribute with Timestamp dataType.

For the an implementation just drag the attribute and drop it as ADF input Date.


Surround the component with a af:panelLableWithMessage and then put an af:inputText component from the components section.

Then set the disable property of the inputText to true.
And then copy the value of the inputDate and paste it in the value of the input field.
Here is the xml code .

<af:panelLabelAndMessage label="New Date" id="plam1">
                        <af:panelGroupLayout id="pgl1" layout="horizontal">
                            <af:inputText label="Label 1" id="it1" simple="true" disabled="true"
                                          value="#{bindings.NewDateTrans.inputValue}"/>
                            <af:inputDate value="#{bindings.NewDateTrans.inputValue}"
                                          required="#{bindings.NewDateTrans.hints.mandatory}"
                                          columns="#{bindings.NewDateTrans.hints.displayWidth}"
                                          shortDesc="#{bindings.NewDateTrans.hints.tooltip}" id="id1" autoSubmit="true" simple="true"
                                          contentStyle="display:none;">
                                <f:validator binding="#{bindings.NewDateTrans.validator}"/>
                                <af:convertDateTime pattern="#{bindings.NewDateTrans.format}"/>
                            </af:inputDate>
                        </af:panelGroupLayout>
                    </af:panelLabelAndMessage>



That's it. Now run the application.

Here is the Sample Application for Reference : DateFieldTestApp

Saturday 5 December 2015

ADF : Creating an MultiLevel Tree i.e. af:tree Programatically | Populating TreeTable from Bean

Hi,

Here I am going to demonstrate how we can create a n-level Tree table by populating data from the bean.
Here are the steps that need to be followed.
  1. For creating this we need to create a datatype for storing the values of the  row or we call it node in TreeTable. Here is the code for the datatype or POJO class named TreeNodeDS.
    package testtabledemoapp.view.treeds;
    
    import java.util.ArrayList;
    
    public class TreeNodeDS {
        private String id;
        private String description;
        private ArrayList<TreeNodeDS> child = new ArrayList<TreeNodeDS>();
    
        public void setId(String id) {
            this.id = id;
        }
    
        public String getId() {
            return id;
        }
    
        public void setDescription(String description) {
            this.description = description;
        }
    
        public String getDescription() {
            return description;
        }
    
        public void setChild(ArrayList<TreeNodeDS> child) {
            this.child = child;
        }
    
        public ArrayList<TreeNodeDS> getChild() {
            return child;
        }
    
        public TreeNodeDS(String id,String description) {
            super();
            this.id = id;
            this.description = description;
        }
        
        public void addNewChild(TreeNodeDS treeNodeDS){
            child.add(treeNodeDS);
            
        }
    }
  2. Here is the code in the bean the bean.

    package testtabledemoapp.view.bean;
    
    import java.util.ArrayList;
    
    import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel;
    
    import testtabledemoapp.view.treeds.TreeNodeDS;
    
    public class TreeNodeBean {
        private ArrayList<TreeNodeDS> list = new ArrayList<TreeNodeDS>();
        ChildPropertyTreeModel charatcerVal = null;
    
        public ChildPropertyTreeModel getCharatcerVal() {
            return charatcerVal;
        }
    
        public TreeNodeBean() {
            super();
            TreeNodeDS firstNode = new TreeNodeDS("F001","First Level");
            TreeNodeDS secondNode = new TreeNodeDS("F002","Second Level");
            TreeNodeDS thirdNode = new TreeNodeDS("F003","Third Level");
            TreeNodeDS fourthNode = new TreeNodeDS("F004","Fourth Level");
            firstNode.addNewChild(secondNode);
            secondNode.addNewChild(thirdNode);
            thirdNode.addNewChild(fourthNode);
            list.add(firstNode);
            list.add(secondNode);
            list.add(thirdNode);
            list.add(fourthNode);
            list.add(secondNode);
          //Initialising the character val with the data
            charatcerVal = new ChildPropertyTreeModel(list,"child");
        }
    }
    
  3. Now create a treeTable on the page. Here is the code of the page.

    <af:link text="#{node.id}" id="l1"
                                             inlineStyle="#{node.description == '' ? 'font-weight:500;color:navy' : ''}"
                                             rendered="true"/>
                                    <af:outputText value="#{node.id} | #{node.description}" id="ot1" rendered="false"/>
                                    <af:link text="#{node.description}" id="l2" rendered="true"/>
    
  4. Now run the application. Here is the screen shot.
    Here is the same Application : TreeTableDemoApp

Monday 30 November 2015

how to populate Single or Multiple Selection Lov(List of Values) from Bean in ADF

Hello all,

This shows how we can populate the values of Single or Multiple Selection List of values from Bean.
For this simply create a simple ADF Application.

  1. Then create a Bean with a method public ArrayList<SelectionList> getSelectionListItems();
    package singleselectionlovfrombean.view.bean;
    
    import java.util.ArrayList;
    
    import javax.faces.event.ActionEvent;
    import javax.faces.model.SelectItem;
    
    import oracle.adf.view.rich.component.rich.input.RichSelectManyChoice;
    
    public class TestBean {
        private ArrayList<String> list = new ArrayList<String>();
        private RichSelectManyChoice multSelctBind;
    
        public TestBean() {
            list.add("Second Option");
            list.add("Third Option");
            list.add("Fourth Option");
            list.add("Fifth Option");
        }
    
        public void showSelectedValuesAL(ActionEvent actionEvent) {
            Object object = multSelctBind.getValue();
            System.out.println("Selected Values are : "+object);
        }
    
        public ArrayList<SelectItem> getSelectionListItems() {
            ArrayList<SelectItem> sslist = new ArrayList<SelectItem>();
            for (String s : list) {
                sslist.add(new SelectItem(s, s, s, false));
            }
            return sslist;
        }
    
        public void setMultSelctBind(RichSelectManyChoice multSelctBind) {
            this.multSelctBind = multSelctBind;
        }
    
        public RichSelectManyChoice getMultSelctBind() {
            return multSelctBind;
        }
    }
    
  2. Create a .jspx page and the drag a multiple selection list of Values form component pallet.
  3. This method returns an ArrayList of SelectionList type which we will use for the purpose of showing the values in the list box.

  4. Then select the method returning items by clicking on the Bind


Then press okey.


And Here I also have created a ActionEvent in a button that shows the selected values.

Then run the application.

The pages opens are follows


After the selection click on  Show Selected Values button.



Am attaching the sample application for reference : SingleSelectionLovFromBeanAPP
Please comment for any query or Confusion.

Friday 20 November 2015

ADF : Another User Have changed the Row with Primary Key in ADF | oracle.jbo.RowInconsistentException: JBO-25014

This post is relating to the error that often comes on ADF Applications.

Error : oracle.jbo.RowInconsistentException: JBO-25014: Another user has changed the row with a primary key

Main Cause
This comes up when the user commits the data on ADF page, the framework checks whether if the row which is being modified and being committed by the current user is still in the same state as it was when the framework fetched the row from the database.

Scenario :
  1. Suppose a user A wants to modify the Salary of an Employee with Employee_id 10.
  2. He picks the row and started editing the record and sets the Salary to 3500.
  3. Meanwhile, a new user B who also wanted to update the Salary of Employee_id 10 picks the record and edits the record and sets the Salary to 3000, and commits the record.


  • Now if the user A commits the record then this the error will appear.

    • This will appear as when the user A started editing the record, at that time framework made a copy of same record and kept with it.
    •  When the user A completed its entry and try to commit the record, then the framework compares the record saved with it and the same record currently in the database.
    • This is to ensure that while the user A was editing the data then the same record was not modified by any other user. This done to maintain the consistency of the database.
    • As if the A is allowed to commit the data then the changes made by B will be lost.
    • This is the scenario in case of Optimistic Locking Mechanism. If you want to know more about Locking mechanism http://adfjavacodes.blogspot.in/2014/04/adf-alternate-of-current-row-selection.html

    Normally this is case. But in ADF Applications this comes up even if the Another User is not modifying the record.
    Here are some of the causes :
    1. Formatting in case of Date Columns.
      • Problem : Suppose the Date saved as timestamp in database as '12-11-2015 11:10:55.001' and in the ADF Application it is '12-11-2015 11:10:55'. Ideally, they are the same but for the framework, this is a mismatch.
      • Solution :  The trick to avoiding this error is to send the data in the database after the formatting i.e.  '12-11-2015 11:10:55' so that on comparison it compares '12-11-2015 11:10:55.000'  and '12-11-2015 11:10:55'
    2. Formatting in case of Number Columns.
    3. PostChanges() being called in the application.
      1. Problem : Data is posted to the database in the case of PostChanges(). And if after that the data is modified then again this comes as there is difference between database and framework. Suppose the value of a column is 'A' before postChanges and afterward it is changed to 'B'. Then on commit, this comes up, not always but often in case of PostChanges.
      1. Solution :  This is no particular sure solution to this, but we have certain options
        1. Executing the VO before commit.
        2. We can use Refresh on Insert, Refresh on Modifiy attributes of Entity. Set it to true to avoid this error.

    Now as we have done the homework :) regarding this, now It’s a task to identify that on which attribute this error is coming.  Here are the steps.
    1. Start the server.
    2. Go To we logic server console | Actions-> Configure Oracle Diagnostic Logging

    1. Now go set the log to finest for oracle.jbo to finest


    2. Now go to preference in Jdeveloper and increase the log lines to 30000 as too many log rows will be generated.
    3. Now clear the log before the event on which this error occurs then  perform the event.
    4. Then in the log search for text 'Entity Compare failed' and it will show you the attribute name for which this error is appearing and Value.