Tuesday, July 6, 2010

Using Defne Framework with Java Server Faces

Using Defne Service Framework with Java Server Faces is very easy. Defne provides "JSFEjbServiceExecutorProxy" managed bean instance to invoke the Defne services. We will see an example just in a moment.

Writing Defne Service

Writing a defne service without dependent on any technology is very very easy. Just annotate your class and  its methods. For example, we create a new Defne service, Calculator.

public class Calculator{
     public static Message add(Message input) throws DefneException
           int x = input.getMessageParameter(Integer.class,"X");
             int y = input.getMessageParameter(Integer.class,"Y");
             input.put("Z", x+y);
             return input;

That is it! We have written our service with named (default class name) "Calculator" and operation name (default method name) "add".

Call Service From JSF Managed Bean

Now, we will call our service using JSF managed bean. Lets say that we have a JSF CalculatorBean,

@ManagedBean  --> JSF 2.0 fashion
public class CalculatorBean{
       private JSFEjbServiceExecutorProxy executor; --> Injected by the Defne

       private String  x;
       private String y;

       public String addNumbers(){

           Message input = new Message("Calculator","add");

           Message output =  executor.execute(input);

            return null;

That is it!

Get more information on Defne Service Framework,
click http://code.google.com/p/defne/

No comments: