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