Tuesday, August 15, 2017

Hide Query By Example of PanelCollection on page load

Hi All,

If there is a table with filterable is true. If you want to display QueryByExample then surround this table with panelCollection. Then Automatically QBE will be displayed in open mode(with filters are visible). If you need to hide the default open qbe then just make the table filterable property to false.


If you dont want to show the complete QBE it self then panelCollection dont have any property. We can achieve this by using skinning.

af|panelCollection.customPanelCollection div[id$='_qbeTbr'] {
    display: none;
}

with this we can hide QBE.


Generic method to execute a procedure in ADF Applications

In most of the ADF applications we have a requirement to execute a procedure from manged bean adn get the result. For this we need to follow the following steps.

Step1. Create a method in Application Module Impl class. like executeProcedure(......)


    public HashMap CallProcedure(String procedureName, int noOfIPParameters, int noOfOPParameters,
                                      ArrayList inputValues) {
        HashMap<Integer,Object> hm = new HashMap<Integer,Object>();    
        CallableStatement cst = null;      
        try {
            String proc = "begin ";
            if (noOfIPParameters > 0) {
                proc = proc + procedureName + "(";
                int totalParams = noOfIPParameters + noOfOPParameters;
                for (int params = 1; params <= totalParams; params++) {
                    if (params == totalParams) {
                        proc = proc + "?";
                    } else {
                        proc = proc + "?,";
                    }
                }


            }else if(noOfIPParameters==0){
                proc = proc + procedureName + "(";
                int totalParams =  noOfOPParameters;
                for (int params = 1; params <= totalParams; params++) {                  
                    if (params == totalParams) {
                        proc = proc + "?";
                    } else {
                        proc = proc + "?,";
                    }
                }
            }
           
           
            else {
                proc = proc + procedureName;
            }
            proc = proc + ")";
            proc = proc + "; end;";
            System.out.println("proc::::" + proc);
            cst = getDBTransaction().createCallableStatement(proc, 0);

            if (noOfOPParameters > 0) {
                int outputStartVar = noOfIPParameters + 1;

                for (int outputParam = outputStartVar; outputParam <= (noOfIPParameters + noOfOPParameters);
                     outputParam++) {
                 
                    cst.registerOutParameter(outputParam, Types.VARCHAR);
                }

            }

            if (noOfIPParameters > 0) {

                for (int inputParam = 1; inputParam <= noOfIPParameters; inputParam++) {
                 
                    int tempVar = inputParam - 1;
                    cst.setObject(inputParam, inputValues.get(tempVar));
                }
            }


            //            cst.registerOutParameter(2, Types.INTEGER);
            //            cst.registerOutParameter(3, Types.VARCHAR);
            //            cst.setInt(1, 2);
            cst.execute();
         
           // System.out.println(".............2.:::" + cst.getObject(2));
           
            if(noOfOPParameters > 0){
                int outputStartVar = noOfIPParameters + 1;
                for (int outputParam = outputStartVar; outputParam <= (noOfIPParameters + noOfOPParameters);
                     outputParam++) {
                 
                   hm.put(outputParam, cst.getObject(outputParam));
                }
               
            }
           

            //Finally get returned value
            return hm;
        } catch (SQLException e) {
            System.out.println("error::" + e.getMessage());
        } finally {
            if (cst != null) {
                try {
                    cst.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

        return hm;

    }

Step2. Expose this method to the client interface.

For this go to java tab of application module  and add in client interface like this.





Step3. Add this method as Method Action on page bindings.



Step4. By using get Operation Binding get the method action.

  OperationBinding operationBinding = bindings.getOperationBinding("CallProcedure");

Step5. Execute this operation Binding and get the result.
  String procedureName = "Procrdure_Package_Name.Procedure_Name";
if input parameters 0 and out parameters 1 then. ArrayList inputValues = new ArrayList();

if input paramets 2 and out parameters 2 then ArrayList inputValues = new ArrayList();
inputValues.add("in parameter1");
inputValues.add("in parameter2");

                operationBinding.getParamsMap().put("procedureName", procedureName);
                operationBinding.getParamsMap().put("noOfIPParameters", 0);
                operationBinding.getParamsMap().put("noOfOPParameters", 1);
                operationBinding.getParamsMap().put("inputValues", inputValues);
                operationBinding.execute();
              Object  result = operationBinding.getResult();
if(result!=null){
HashMap returnValues = (HashMap) result;
}


Step6. Process the result(like to store in table or to set to some view attribute).

Generic method implementation in Application Module Impl.


Redirect to a page in ADF 12C

There were couple of situations to redirect to a page in adf applications like from adf filter we need to redirect or on button click we need to redirect . Frank has posted a blog post in which he has mentioned how efficiently we can redirect to page. But the solution is working only in weblogic but not in glassfish.
You can find Frank's post here.
https://blogs.oracle.com/jdeveloperpm/how-to-efficiently-redirect-to-an-adf-faces-view-using-adf-controller



Case1. Redirect to a page from ADF Filter.

By using the request dispatcher we can redirect by using the following piece of code.

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
                         FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
           HttpServletResponse res = (HttpServletResponse) servletResponse;
if(username==null){
 ((HttpServletRequest)req).getRequestDispatcher("/faces/Pages/Login.jspx").forward(req, res);
}
}

Case2. Redirect to page on button click.

By using the ExtendedRenderKitService we can redirect to a page on button click.

 String serverPath ="http://"+request.getServerName()+":"+request.getServerPort()+"/ApplicationName/faces/Pages/Home.jspx";

                String url = "window.open('"+serverPath+"','_self');";
                erks.addScript(FacesContext.getCurrentInstance(), url);

It will redirect to the page specified.



Hide Query By Example of PanelCollection on page load

Hi All, If there is a table with filterable is true. If you want to display QueryByExample then surround this table with panelCollection....