Tuesday, October 27, 2015

Using GWT BaseModelData object for infinitive flexibility



We have implemented a project with GXT( a GWT framework) and Hibernate.

It has a class like this.
com.extjs.gxt.ui.client.data.BaseModelData

Idea is put fields into Hashmap and read them by key. This object goes between
server and browser.

public User (

 protected Organization organization;
 protected String name;
 protected String surname;
 
 }
 
 //will be 

public UserDao extends  BaseModelData( 
 
    //Utility methods for explicit access
    public Organization getOrganization( ) 
    {
        return this.< Organization >get( "organization" ) ;
    }

    public String getName( ) 
    {
        return this.< String >get( "name" ) ;
    }
    
    public String getSurname( ) 
    {
        return this.< String >get( "surname" ) ;
    }
    
    


So what is so flexible about this?

We found this very useful when creating a sample bean.
We have everything in map. So for organization field we can even put
an organization or List.

If you check Database querying by Object notation article you will understand this is for.

User sample = new User();
user.set( "organization",new Organization[]{org1,org2,org3});
user.set( "name",new Organization[]{"John","Jack"});

I can send this sample Object and interpret this into a query where
Bring users in any of organizations (org1,org2,org3) having name either John or Jack.

Object obj = sample.get("organization");

if( obj instanceof Organization )
{

}else if( obj instanceof List)
{

}

Think, how will you make this without this model?

No comments:

Post a Comment