Showing posts with label spring. Show all posts
Showing posts with label spring. Show all posts

Saturday, October 1, 2011

ExtJs with Spring

ExtJs is an popular java script framework. To develop rich and interactive user interface, extjs is used. It is a basically library of java script component which are ready to use in webpage.
ExtJs components work very well with JSON data. If in server side we decide to Spring as framework. Its very easy to integrate ExtJs with Spring. In Spring MVC we can easily configure FTL (free marker technology)
for specific to ExtJs Component. FTL is something which is responsible to convert java objects to desired JSON object. So there can be a generic controller in Spring, Which can be derived by other controller as per application design. 
ExtJS component will talk to Spring controller which will return JSON objects.
Next thing I will try to put some code which will give a descent idea.

Monday, March 21, 2011

Spring king of all season

Most of the developer worked in Java is aware of spring frame work. And who doesn't know anything about Spring framework can think about experienced spring season. Like many other frame works available Spring also serve as container. It creates the java object/component run time and manage them. The application developer can concentrate on business logic and really forget about managing objects. When people talk about Spring two terms dependency injection and inversion of controller always comes. Let me also write about these... When there is a situation a object use another object (association).
Lets have an example:
Class Orchestra                  
{
     Dancer  dancer = new Dancer();
     Singer   singer = new Singer();
     perform()
       {
           dancer.dance();
           singer.sing();
       }
}

Here Orchestra class use Dancer and Singer to perform the job.  Well tomorrow we need some modern dancing and some different kind of Song we have to change the Orchestra class.
In Spring way we can re write some thing like below.

Class Orchestra                   
{
     IDancer  dancer;
     ISinger   singer;
     perform()
       {
           dancer.dance();
       singer.sing();
       }
}

Interface IDancer
{
   dance();
}

Interface ISinger
{
   sing();
}

BreakDancer implements IDancer
{
  dance()
   {
     ----
     ----
   }
}
RockSinger implements ISinger
{
  sing()
   {
     ----
     ----
   }
}

In Runtime we can inject the dancer and Singer to Orchestra using Spring. Well here with singer and dancer we are injecting the dependency to Orchestra. And Orchestra gave the control which kind of dancer and singer is going to perform. This is something called inversion of control.  We can do both xml based or annotation based configuration in Spring. Here is the xml version
<bean id="orchestra" class="com.action.Orchestra">
     <property name="singer"><ref bean="rockSinger"/></property>
    <property name="dancer"><ref bean="breakDancer"/></property>
</bean>
<bean id="rockSinger">
    <property name="target">
            <bean class="com.action.RockSinger" />
        </property>
</bean>
<bean id="breakDancer">
    <property name="target">
            <bean class="com.action.BreakDancer" />
        </property>
</bean>         


So spring gives such a environment where  we have all the freedom to configure anything up to any level.
Have a nice time in Spring :)