Wednesday, August 25, 2010

ofbizify - Ajaxifying Apache Ofbiz, using GWT

This project aims to ajaxify Apache OFBiz, which is an open source enterprise automation software, using Google GWT

To know more about :
Apache OFBiz - http://ofbiz.apache.org/
Google Web Toolkit - http://code.google.com/webtoolkit/

To download ofbizify code :
http://code.google.com/p/ofbizify


Sometime back I had a look at the GWT project, saw the showcase and thought wouldn't it be nice to have GWT front-end for OFBiz applications, to have richer user interfaces. That's when I thought of integrating GWT with OFBiz.

Using GWT one can have richer user interfaces and also all the framework features as well as the business functionality OFBiz provides.

There are 3 ways to have communication in GWT :
1) XML
2) JSON
3) GWT-RPC

I choose to integrate OFBiz & GWT using the native GWT-RPC protocol as it was much easier to use and productive, as java objects are passed around, then instead of using XML & JSON and parsing the messages.

The best thing using ofbizify is, the ofbiz component structure stays the same, you put all your request in controller file, invoke your Java Events, Groovy scripts, Services as you use to.

To know more about how to configure ofbizify, how to call java events, groovy scripts and services, visit Developers Guide, to download the code & example, you can visit the project homepage at http://code.google.com/p/ofbizify

and guys let me know if there is anything to improve the project

comments/suggestions welcome :)

Saturday, January 16, 2010

GWT : Creating a dynamic FlexTable

For the sake of creating a dynamic FlexTable we will be considering a scenario where a user needs to enter the languages he/she knows along with other options.


Lets get started with the coding :


import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.HTMLTable.Cell;

public class DynamicTable implements EntryPoint {

    public void onModuleLoad() {
       
        final FlexTable table = new FlexTable();
        table.setCellSpacing(5);
        table.setCellPadding(3);

        //table heading columns
        table.setText(0, 0, "Language");
        table.setText(0, 1, "Proficiency Level");
        table.setText(0, 2, "Read");
        table.setText(0, 3, "Write");
        table.setText(0, 4, "Speak");
        table.setText(0, 5, "");
       
        //controls to enter languages
        final TextBox language = new TextBox();

        final ListBox proficiency = new ListBox(false);
        proficiency.addItem("Select", "select");
        proficiency.addItem("Beginner", "1");
        proficiency.addItem("Proficient", "2");
        proficiency.addItem("Expert", "3");

        final CheckBox read = new CheckBox();
        final CheckBox write = new CheckBox();
        final CheckBox speak = new CheckBox();

        Button add = new Button("Add");
               
        //adding input controls to table
        table.setWidget(1, 0, language);
        table.setWidget(1, 1, proficiency);
        table.setWidget(1, 2, read);
        table.setWidget(1, 3, write);
        table.setWidget(1, 4, speak);
        table.setWidget(1, 5, add);

        //adding handlers
  

        //table handler
        table.addClickHandler(new ClickHandler() {
              @Override
              public void onClick(ClickEvent event) {

                  FlexTable ft = (FlexTable) event.getSource();
                  Cell c = ft.getCellForEvent(event);
                  if(c != null) {

                      int cellIndex = c.getCellIndex();
                       int rowIndex = c.getRowIndex();

                       if(cellIndex == 5) {
                           if(rowIndex != 0 && rowIndex != (ft.getRowCount()-1)) {
                               ft.removeRow(rowIndex);
                           }
                       }
                   }
              }
            }
         );

        //Add button handler
        add.addClickHandler(new ClickHandler() {
                          
                public void onClick(ClickEvent event) {
                  
                    String lang = language.getText();
                    String pl = proficiency.getItemText(proficiency.getSelectedIndex());
                  
                    String r = "No";
                    if(read.getValue()) { r = "Yes"; }
                  
                    String w = "No";
                    if(write.getValue()) { w = "Yes"; }
                  
                    String s = "No";
                    if(speak.getValue()) { s = "Yes"; }
                  
                    int numRows = table.getRowCount();
                  
                    numRows = table.insertRow(numRows-1);
                  
                    table.setText(numRows, 0, lang);
                    table.setText(numRows, 1, pl);
                    table.setText(numRows, 2, r);
                    table.setText(numRows, 3, w);
                    table.setText(numRows, 4, s);

                    Anchor anchor = new Anchor("Remove");
                    table.setWidget(numRows, 5, anchor);
                  
                    language.setText("");
                    proficiency.setSelectedIndex(0);
                    read.setText("");
                    write.setText("");
                    speak.setText("");
                }
            }
        );

        RootPanel.get().add(table);
    }
}


Ofcourse many improvements coube be made here, like having a drop down for selection of languages instead of the text box to enter, validation of the input, and having checkbox with boolean value set instead of have the text Yes or No, that's left for you :)

Wednesday, January 13, 2010

!! sigh !! finally done with integration of MIGS with OFBiz

I was required to integrate MasterCard Internet Gateway Service (MIGS) which is a 3D secure solution with OFBiz,



MIGS provides server hosted services, but this was a problem in OFBiz as OFBiz requires services to be made which in turn hits the payment gateway, but this was not possible using server hosted services.

Finally after looking closely at how MIGS work, following the HTTP headers, cookies etc etc .. I was able to communicate with MIGS & the Bank server using HttpConnection and it was done :)

So finally we made the MIGS solution work the way it didn't wanted to.