Thursday, May 15, 2014

Refresh Page in ADF

The following code refreshes the whole page

  1. FacesContext fctx = FacesContext.getCurrentInstance();
    String refreshpage = fctx.getViewRoot().getViewId();ViewHandler ViewH = fctx.getApplication().getViewHandler();
    UIViewRoot UIV = ViewH.createView(fctx, refreshpage);
    UIV.setViewId(refreshpage);
    fctx.setViewRoot(UIV);

To refresh a specific component :

  1. AdfFacesContext.getCurrentInstance().addPartialTarget(UIComponent);

Friday, May 9, 2014

Web Service Proxy in adf

Requirement : Create a web service proxy and use that to invoke the web service and get the response.

As per my understanding web service proxy created java classes that can be used to invoke the web service from the application.

Creating a web service proxy is pretty simple, we just need to have the wsdl url.

On 11.1.1.5.0 the options would be something like this:


select web service proxy

On 11.1.2.0


Now we need to select the different options in the wizard:

NOTE :  The Client style is usually JAX-WS Style but sometimes when invoking a .net service or any other legacy services we might encounter an error whil creating the web service. 

That case we might want to create a JAX-RPC weblogic style. 

In my case i had a .net service which i wasnt even able to test it in SOAPUI. This case go for JAX-RPC which will serve the purpose.

Please be informed that you can see these style selections only when we create a generic application with the web services shuffled in the project technologies, then you would see this option 

This new application can be used as a jar in the working application/project where you want to use the service.

For a regular SOA service we dont have to worry about all this. 

After successfully creating a Web Service Proxy we can see various .java files created. We have to search for class ending in *client.java class where you have the comments 

// add your code here 

Once we are aware of the input types pass the request and get the response here. 

If the request has to be sent from a different application, we need to add this application in the dependencies and class paths as a .jar file



Wednesday, May 7, 2014

Usage Of Servlets in ADF To Show Af:Image Based On a Parameter

Requirement : Show a Picture based on an Id which is coming from a service.

Solution : Create a Servlet in ViewController


Select appropriate methods to implement from doGet(), doPost(), service(), doPut(), doDelete().

In my case i had to implement the doGet() method to get the response from the servlet and show that on the jsff page.

The URL pattern will let you point to the appropriate Servlet from the page.

A java class something like this will get generated:

package client;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.*;
import javax.servlet.http.*;

public class Servlet1
  extends HttpServlet
{
  private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

  public void init(ServletConfig config)
    throws ServletException
  {
    super.init(config);
  }

  public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
  {
    response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head><title>Servlet1</title></head>");
    out.println("<body>");
    out.println("<p>The servlet has received a GET. This is the reply.</p>");
    out.println("</body></html>");
    out.close();
  }
}

Override the doGet() method as per the requirement :
In my case i pass an Id to a service and get the byte[] in response to it.
I need to convert it to a jpg file, so set the content type to "image/jpg".
Write that to the out response of the doGet() and we are done defining and implementing the Servlet.

For Ex :

  public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
  {
    if (request.getParameter("dsId") != null)
    {
      OutputStream out = null;
      try
      {
        /*
          Code to get the Id from the service, added a jar file to the ViewController which has the webservice proxy client
          */
               }
        if (imageByte != null)
        {
          response.setContentType("image/jpg");
          out = response.getOutputStream();
          out.write(imageByte);
          out.flush();
        }
      }
      catch (Exception ex)
      {
        ex.printStackTrace();
      }
      finally
      {
        if (out != null)
          out.close();
      }
    }
  }
}

On the page where the image has to be showed on the run time give the appropriate Servlet URL

For Ex:

<af:image source="/dsimageservlet?dsId=#{bindings.DistributorId.inputValue}" id="i12"
                            inlineStyle="height:150px; width:150px;"/>

The newly added servlet can be view in web.xml file in my case the name is DSImageServlet.


Thats it, run the page and view the servlet response on the page.



Tuesday, April 29, 2014

Make, Rebuild and Make all option in JDeveloper

Make : Make operation compiles only the source files that have been changed since they were last compiled, or have dependencies that have been changed.

Rebuild : It compiles the source files unconditionally.

Make is done on individual source files, on working sets or on containers such as packages, projects, and workspaces.

Clean All: Cleans all the projects

Make all : Compiles not only the working project but all the projects.

Monday, April 28, 2014

Groovy Expression Usage in ADF, JDeveloper

Different points where Goovy code can be dropped:
1. Values for View and Entity objects attributes.
2. Validation rules on Entity object attributes.
3. Expressions for error messages.
4. Values for view object bind variables.
5. View object transient attribute validations.
Some of the properties of groovy scripting language

- Groovy is a scripting language having java like syntax
- Groovy is executed at run time
-  
Can be used in Entity and View objects in attribute validators(Entity Objects),attribute default values( Entity and View),bind variable default values ( View) place holder for error messages (EO validation rules)
- Define script expression validator or Compare validator 
- Error message tokens can be defined for handling validation failures 
- Conditional execution of validatiors are possible 
- Default value of bind variable in view object can be defined using groovy expression 
- Default value of view criteria 
- Default value and optional re-calculation condition for EO
- Value of transient for EO and VO 

Referencing Buisiness components objects in Groovy expression
Top level object is "adf" . Accessible ADF objects throgh groovy are 
- adf.context - Reference to ADFContext 
- adf.object - Equivalent to this operator in java.
- Entity Objects attributes - Reference methods and attributes of EntityImpl class.
- Entity Objects script validator rules - Attributes and method of ViewImpl class.
- View Object attributes 
- Bind Variable in view Object 
- Bind variable in view accessors 
- Transient attributes 
- adf.error 
- adf.userSession 
- adf.currentDate 
- adf.currentDateTime 
- Referencing custom buisiness components methods and attributes 
eg. Sal*12 - annualsalary .
PromotionDate>HireDate 

Method of entity class in validation rule.For validators use source keyword
eg. source.getDefaultSalaryForGrade()

- newValue - Attribute value being set 
-oldValue - current value of attribute being set 

if(Job=’SALESMAN’)
{
 return newValue<source.getMaxSalaryForGrade(Job)
}

Manipulating business component attribute values in a groovy expression
RowSet Objects
-          rowSetAttr.sum(GroovyExpr)
-          rowSetAttr.count(GroovyExpr)
-          rowSetAttr.avg(GroovyExpr)
-          rowSetAttr.min(GroovyExpr)
-          rowSetAttr.max(GroovyExpr)
EmployeesInDept.sum(“Sal+adf.object.getBenefitsValue(Job)”)


Thursday, April 10, 2014

Increase log level in ADF

In the ViewController -> Project Properties

set this value in the Run/Debug/Profile

-Dmock=true -Djbo.debugoutput=console


Sample expression in Instyle ADF :

Example 1 : color a column conditionally in a table
#{(row.TotalWeighed!=null)? (row.GreenOrRed=='Green'? 'background-color:Green;color:White;' : 'background-color:Red;color:White'):''}

Example 2: Load an image based on the logged in user:
#{sessionScope.loggedInUser=='InternalUser'? 'background-image:url("Image/internalfacing.png")' : 'background-image:url("Image/ds_facing.png")'}