martes, 4 de diciembre de 2012

GWT and PHP

This time I will describe a CRUD application using GXT Grid and HttpProxy on the client side and on the server side I use PHP and PDO to access a PostgreSQL database.
The communication between client and server side is using JSON then you can use whatever language on the server side that produce a JSON output.
The source code is on github https://github.com/poseidonjm/GXT3-PHP is structured using GWTP and GWT Editor for binding.



Database table

GXT and HttpProxy
First of all the next interfaz and class are required

MyAutoBeanFactory.java

MyHttpProxy.java

GWT AutoBean
With GWT AutoBean is easy to serialize/deserialize GWT Objects to json and vice versa,
on the client side there is the UserProxy interface that represents the model

UserListProxy represent a set of users

With AutoBean the objects are created from a factory


GXT Reader
GXT Grid use a reader to parse the output of the server.

GXT Grid

UserView.ui.xml

Run the proyect
You have to start your Apache Server and enable the following extensions for PostgreSQL and PDO:
php_pdo_pgsql
php_pgsql
You have to set the root of your web server to the war of the project
for example I use XAMPP and change the httpd.conf
restart Apache Server.
Set the parameters of connection to database PostgreSQL in war/config/connect.php
I usually work on Firefox for GWT DevMode




Compile GWT code to JS
I compile GWT with Google Plugin for Eclipse GPE

By default the compiled JS code is compressed.

Then enter the url http://localhost/phpcrud.html#users

The Server Side PHP
I use simple PHP and PDO
connect.php
users.php
paginate.php
Sorry if I am missing explain PHP code.

I hope you can use GWT with any backend and AutoBean is a nice feature of  GWT.

2 comentarios:

  1. Hi,

    I tried to run your example but I have an exception in "createRequestFilterConfig", "original" is null.

    Do you have an idea ?

    Thks,

    JB

    ResponderEliminar
  2. Could you be more specific.
    I use Eclipse Juno
    I downloaded and imported the eclipse project using Egit.
    I have the GPE(Google plugin for eclipse) only for GWT
    I have a GWT 2.5 as SDK.
    And tested with firefox in dev mode with the Google Developer Plugin and is OK.
    Maybe you need configure the eclipse project.

    ResponderEliminar