Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label pagedef. Show all posts
Showing posts with label pagedef. Show all posts

Friday 12 May 2017

Understanding Nested Application Modules in Oracle ADF


Application Module acts as a container for view Object and view Link business components that are used in a specific task. It provides data model and data control to show required information and perform action for the client
An application module represents a single transaction and owns one database connection that's why commit and rollback works for all view Objects inside an application module

Monday 17 April 2017

Show saved file (pdf/text/html/xml/image) content on page from database (BLOB) in ADF Application


Hello All

Previously I have posted about uploading and saving files in database blob column now this post is about showing saved file content on page using ADF Faces inline frame component

In this post I am extending same previous application, Now see how we can implement this
There are few more steps to go , See the additional steps to show file content on page-


Tuesday 15 December 2015

Checkbox ValueChangeListener problem in af:table - ADF 12.1.3


Recently i faced a problem while working on one of my application, it has an editable table having one check box column and a valueChangeListener is defined on that check box.

Problem is that whenever user selects any row of table , valueChangeListener of check box is called every time for all editable rows, this is weird because VCL should execute only when user selects or deselects check box

Friday 28 August 2015

ADF Basics: Using setPropertyListener to set value in memory scope variables

Soemtimes we need to set a value in memory scope variable on some event
In ADF af:setPropertyListener does this for you declaratively

The setPropertyListener tag provides a declarative syntax for assigning values when an event fires. The setPropertyListener implements the listener interface for a variety of events, to indicate which event type it should listen for set the 'type' attribute.

Read more about <af:setPropertyListener>

Saturday 4 July 2015

ADF Basics: How to invoke model layer methods from managed bean (Best Practice to write business logic in ADF)

Again a post about ADF Basics for those who are starting with ADF
This topic is posted multiple times and one of the most asked question on OTN

How to access AM method in bean ?
How to pass parameters to model from managed bean (viewController) ?
How to pass taskFlow parameter to model ?

Or sometimes I have to tell user that you should not access ApplicationModule or not update model from managed bean and then i post a link about this
I often post a link of Frank's blog
Best practice invoking business services methods from JSF beans
It is well explained but still user not able to do because he/she doesn't know about clientInterface, pageDef etc

So i thought to write a step by step implementation of this and if you want to know why it is best to call method through binding layer ?
Then please refer Frank's blog :)

What i am going to explain is How to call a method defined in ApplicationModule Impl class in managed bean ?
So for this first i need to define a method in ApplicationModule Impl class




Here i am using Departments table of HR Schema and i have created a method to create new row in Departments viewObject
See implementation part -

  • To create AMImpl class--> Open ApplicationModule in editor--> Goto Java tab--> Click on edit (pencil) icon and check the checkbox to generate class



  • Now write your logic and create method here so i have created a method to create department record and this method takes a parameter i;e DepartmentId

  •     /**
         *Custom Method to create row in departments viewObject
         */
        public void createDepartmentRecord(Integer deptId) {
            ViewObject deptVo = this.getDepartmentsVO1();
            Row newRow=deptVo.createRow();
            newRow.setAttribute("DepartmentId", deptId);
            deptVo.insertRow(newRow);
        }
    

  • Next step is to add this method to client interface so that we can access this , Again open AM in editor -->Go to Java tab--> Click on edit icon of clientInterface--> Shuttle method to selected side


  • Now to add this method in pageDef , Open page in editor--> Click on Bindings tab (bottom of editor)--> Click on green plus icon of bindings section--> Select methodAction and click on ok



  • Now select method name here and click ok


    Now you can see this method is added in pageDef


  • Now time to call this method in managed bean so for that added a button in page and created actionListener in bean . See the code 

  •     /**Method to get Binding Container of page
         * @return
         */
        public BindingContainer getBindings(){
            return BindingContext.getCurrent().getCurrentBindingsEntry();
        }
    
        /**Calling method defined in AMImpl class to create new Department
         * @param actionEvent
         */
        public void callAMMethodToCreateDepartmentAction(ActionEvent actionEvent) {
            //Get OperationBinding of method
            OperationBinding ob=getBindings().getOperationBinding("createDepartmentRecord");
            //Passing parameter to method -Get parameter map and use paramater name as key
            ob.getParamsMap().put("deptId", 9999);
            //Execute this method
            ob.execute();
            //Check for errors
            if(ob.getErrors().isEmpty()){
                // Successfully Executed
            }
        }
    

  • Now run application and check , is it working ? ;)

On click a new row is inserted in table with DepartmentId 9999


All done :)
In same way you can call method defined in any model implementation class, remember don't access ApplicationModule or viewObject directly , make use binding layer
and again why it is best practice ?? to know this read Frank's blog :)

Cheers :) Happy Learning 

Thursday 22 January 2015

Show uploaded file (pdf/text/html/xml/image) content on page -Oracle ADF

Hello all
In previous post
Uploading and downloading files from absolute server path in Oracle ADF (12.1.3)
we saw that how can we upload any file to absolute server path and download same from there.
Uploading part is done using simple java code to write file to specified folder and downloading part is done using <af:fileDownloadActionListener>

Now in this post i am going to show that how can we display a file on page directly without downloading it.
So for this i am using same sample application that i have used in previous post , you can download it from here



See the additional steps to show file content on page-
  • Create a servlet to parse file into output stream , this output stream will be used to show file content further.
    To create servlet right click on viewController project select New--->From Gallery-->Web Tier-->Servlet




  • See servlet source code to parse file into outputStream

  • import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.PrintWriter;
    
    import javax.servlet.*;
    import javax.servlet.http.*;
    
    public class PreviewFileServlet extends HttpServlet {
        private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
    
        public void init(ServletConfig config) throws ServletException {
            super.init(config);
        }
    
        /**
         * @param request
         * @param response
         * @throws ServletException
         * @throws IOException
         */
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String path = (request.getParameter("path"));
    
            OutputStream os = response.getOutputStream();
            //If path is null
            if (path.equalsIgnoreCase("No")) {
                path = "D:\\Document\\ItemImage\\Item.jpg";
            }
            if (request.getParameter("path") == "") {
                path = "D:\\Document\\ItemImage\\Item.jpg";
            }
            InputStream inputStream = null;
    
            try {
                File outputFile = new File(path);
                inputStream = new FileInputStream(outputFile);
                BufferedInputStream in = new BufferedInputStream(inputStream);
                int b;
                byte[] buffer = new byte[10240];
                while ((b = in.read(buffer, 0, 10240)) != -1) {
                    os.write(buffer, 0, b);
                }
    
            } catch (Exception e) {
    
                System.out.println(e);
            } finally {
                if (os != null) {
                    os.close();
                }
                if (inputStream != null) {
                    inputStream.close();
                }
    
            }
        }
    }
    

  • Now open page in editor and drop an af:inlineFrame from component palette . inlineFrame is used to create a frame to show any external page or document just like as HTML iframe , it is loaded from source attribute
    So here i am using servlet as source attribute for this inlineFrame

  • <af:inlineFrame id="if2"
                                                        source="/previewfileservlet?path=#{bindings.Path.inputValue == null ? 'No' : bindings.Path.inputValue}"
                                                        inlineStyle="height:350px;width:800px;" sizing="preferred"/>
    

    here path of document is added to pageDef bindings that is passed to servelt as parameter

  • Now run this application and check it

    View Text File-
          View PDF File-


Thanks, Happy Learning :)

Post Related to file handling in Oracle ADF- 

Show saved file (pdf/text/html/xml/image) content on page from database (BLOB) in ADF Application
Uploading and showing image file from absolute server path -Orace ADF
Exporting viewObject data in text file using af:fileDownloadActionListener in Oracle ADF (12.1.3)
Creating pdf file using Apache PDFBox API in ADF Faces and opening it in new window -Oracle ADF
Download file from url using Oracle ADF & Java- Download Manager
Reading html source of a webpage (url) using Oracle ADF (af:richTextEditor) & Java

Saturday 23 August 2014

Access BindingContainer (Page Bindings) of another page using DataBindings.cpx in Oracle ADF

Hello all
this post is about a requirement of getting page binding of another page that is not active currently
we use BindingContainer to access bindings of current page, region in managed bean

Oracle Docs says-
The BindingContainer contains the Control Bindings for a reusable unit of View technology. For example, each individual Page, Region, or Panel refers to a unique BindingContainer with a set of Control Bindings that refer to the Model elements used by that Page. The BindingContainer interface is implemented by the data binding framework provider. 

So to access operations, methods exposed in client, listBinding, IteratorBinding we need to get BindingContainer of current viewPort (a page or a page fragment)
this method is used to get BindingContainer -


import oracle.adf.model.BindingContext;
import oracle.binding.BindingContainer;

    /*****Generic Method to get BindingContainer of current page, fragment or region**/
    public BindingContainer getBindingsCont() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }

as previously mentioned that BindingContainer contains bindings of current page but sometimes we need to access BindingContainer of any other page in order to access it's operations , iterators



So how to do this ?

for this i have created a 2 page fragments inside a bounded taskFlow



firstPage is very simple , it has only one button and secodPage has Departments (HR Schema ) viewObject as form

First Page Second Page

then i added createInsert operation in secodPage binidng, so here is the pageDef of secondPage
as there is no bindings on firstPage so there is no pageDef file is generated for that



now what i want to do is to call createInsert operation of Departments viewObject from firstPage, but there is no binding of operation in firstPage so if i use
BindingContext.getCurrent().getCurrentBindingsEntry()
to get BindingContainer then it will throw NullPointerException on calling createInsert

Now i have to get BindingContainer of secondPage -
Go to DataBindings.cpx file and see usageId for second page



Copy page usageId from there


pass this usageId in this method to get BindingContainer of secondPage


    /**
     * @param data
     * @return
     */
    public Object resolvEl(String data) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class);
        Object Message = valueExp.getValue(elContext);
        return Message;
    }
    
    /**Method to get BindingContainer of Another page ,pageUsageId is the usageId of page defined in DataBindings.cpx file
     * @param pageUsageId
     * @return
     */
    public BindingContainer getBindingsContOfOtherPage(String pageUsageId) {
        return (BindingContainer) resolvEl("#{data." + pageUsageId + "}");
    }

then call createInsert operation using this BindingContainer


 getBindingsContOfOtherPage("binidngs_view_secondPagePageDef").getOperationBinding("CreateInsert").execute();

Happy Learning Cheers :)