<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-17172384</id><updated>2011-09-19T14:32:38.023+02:00</updated><category term='dto'/><category term='uml'/><category term='design'/><category term='catalysis'/><category term='SDM'/><category term='ria'/><category term='Simple Dynamic Module'/><category term='meta-programming'/><category term='conversation'/><category term='ajax'/><category term='Extender pattern'/><title type='text'>A. Clement Website</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.aclement.eu/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://www.aclement.eu/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>alex</name><uri>http://www.blogger.com/profile/02620873488807515094</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-17172384.post-4963346953772682436</id><published>2010-12-09T12:20:00.001+01:00</published><updated>2010-12-09T12:23:23.640+01:00</updated><title type='text'>A new definition of Dependency Injection</title><content type='html'>&lt;p&gt;The concept of Dependency Injection (DI) exists for a while. It was defined by Martin Fowler from the larger concept of Inversion of control (see &lt;a href="http://martinfowler.com/articles/injection.html"&gt;here)&lt;/a&gt;. This concept was defined as a mean to "wire" components together. Buy what does the term "wire" mean precisely? I think it's time to give to this concept of DI, that is apply in a vast area of frameworks, a more formal definition.&lt;p/&gt;

&lt;h1&gt;Definition&lt;/h1&gt;
&lt;p&gt;So what is Dependency Injection? Well, DI is just a form of &lt;a href='http://en.wikipedia.org/wiki/Generic_programming'&gt;generic programming&lt;/a&gt;. Usually genericity is obtained by applying &lt;a href="http://en.wikipedia.org/wiki/Parametric_polymorphism#Parametric_polymorphism"&gt;parametric polymorphism&lt;/a&gt; to classes at the language level to get special parameterized classes or class templates. Then these class templates can be &lt;a href='http://en.wikipedia.org/wiki/Template_specialization'&gt;specialized&lt;/a&gt; to obtain regular monomorphic classes.&lt;/p&gt;

&lt;p&gt;In case of DI, Genericity is obtained using &lt;a href="http://en.wikipedia.org/wiki/Subtype_polymorphism"&gt;subtyping polymorphism&lt;/a&gt; when designing classes. Specialization is obtained by creating prototypes from these classes. The next sections will explain and give examples to this concept of genericity associated to DI.&lt;p/&gt;

&lt;h1&gt;Genericity using parameterized classes&lt;/h1&gt;
&lt;p&gt;Generic programming is usually implemented in languages (such like Java and C++) with parametric polymorphism. A class can be parameterized with one or more formal type (or value) parameters.&lt;/p&gt;

&lt;p&gt;The following simple example shows how classes can be made generic using parametric polymorphism.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://4.bp.blogspot.com/_a6L6uUfUAow/TP5p5zWkz1I/AAAAAAAAAII/Gr0KKnUeP0M/s1600/di-template.png" imageanchor="1"&gt;&lt;img src="http://4.bp.blogspot.com/_a6L6uUfUAow/TP5p5zWkz1I/AAAAAAAAAII/Gr0KKnUeP0M/s800/di-template.png"/&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Class templates&lt;/h2&gt;
The following pseudo code shows how to design generic classes using parametric polymorphism.

&lt;pre class="brush: groovy;"&gt;
// class templating using parameterized polymorphism
// template pseudo language

template &amp;lt;class BookingDAO, long MAX&amp;gt;
@Singleton
class BookingService {

    BookingDAO bookingDAO = BookingDAO.new

    long count

    void book(bookingDetails) {
        if(count++ &amp;lt; MAX) {
            // do something with bookingDAO
        }
    }   
}

template &amp;lt;class BookingService&amp;gt;
@Singleton
class BookingController

    BookingService bookingService = BookingService.new

    public void confirm() {
        bookingService.book(bookingDetails)
    }  
}

@Singleton
class JPABookingDAO {   
// use JPA entity manager...
}
&lt;/pre&gt;

&lt;p&gt;The code simply defines a generic class &lt;b&gt;BookingService&lt;/b&gt; wich is parameterized with a &lt;b&gt;BookingDAO&lt;/b&gt; type and a long value &lt;b&gt;MAX&lt;/b&gt;. The class is also tagged with the &lt;b&gt;singleton&lt;/b&gt; scope. A &lt;b&gt;BookingController&lt;/b&gt; class template is also defined on the same basis.&lt;/p&gt; 

&lt;h2&gt;Template specialization&lt;/h2&gt;
&lt;p&gt;The following code shows how class templates can be specialized with effective types and values.&lt;/p&gt;

&lt;pre class="brush: groovy;"&gt;
//class template instanciations
class BookingService&amp;lt;JPABookingDAO, 100&amp;gt; {

}

class BookingController&amp;lt;BookingService&amp;gt; {

} 
&lt;/pre&gt;

&lt;h2&gt;Object lifecycle&lt;/h2&gt;
One word about how object lifecyle is handled in the above example. To manage object lifecycles, we can use annotation based AOP. Classes can be tagged with the scope &lt;b&gt;singleton&lt;/b&gt;. Then the annotation will be used by the AOP singleton aspect to intercept any call to the class constructor and return the same instance each time.

&lt;h1&gt;Genericity using DI&lt;/h1&gt;
&lt;p&gt;Dependency injection is based on subtyping polymorphism and prototype wiring.
The following model shows the same example as above but using DI instead.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://picasaweb.google.com/lh/photo/5h-82v7U-02rkMrgNV4yG4DMRb6oFFSERWuhRrX9i-8?feat=embedwebsite"&gt;&lt;img style='width: 90%' src="http://lh4.ggpht.com/_a6L6uUfUAow/TP5uxhtz7OI/AAAAAAAAAIo/l2lBQVKiJKA/s800/di-proto.png" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Generic class design&lt;/h2&gt;
&lt;p&gt;Classes can be made generic using subtyping polymorphism. Classes must reference other classes through polymorphic references to interfaces (or abstract classes) in order to allow  the substitution by subtypes later in the prototyping phase.&lt;/p&gt;

&lt;pre class="brush: groovy;"&gt;
/**
 *
 * Spring version
 * subtyping polymorphism + prototyping 
 *
 */
interface BookingDAO {}

class JPABookingDAO implements BookingDAO {
 // JPA stuff ...
}

interface BookingService {
    void book(Map bookingDetails);
}

class BookingServiceImpl implements BookingService {

    long count;
 
    BookingDAO bookingDAO; 

    long max;   

    public void book(Map bookingDetails) {
        if(count++ &amp;lt; max) {
            // do something with bookingDAO
        }
    }
}

class BookingController {

    BookingService bookingService;

    public void confirm() {
        Map bookingDetails = new HashMap();
        // set details
        bookingService.book(bookingDetails);
    }
}
&lt;/pre&gt;

&lt;h1&gt;Prototyping phase&lt;/h1&gt;
&lt;p&gt;The prototypes are created form the generic classes. During this phase, polymorphic references are resolved by the injection of a concrete subtype.&lt;/p&gt;
&lt;p&gt;Te following code illustrates prototyping phase using the Grails BeanBuilder.&lt;/p&gt;

&lt;pre class="brush: groovy;"&gt;
// prototyping
def bb = new BeanBuilder()
bb.beans {
    bookingDAO(JPABookingDAO)   

    bookingService(BookingServiceImpl) {
        bookingDAO = ref('bookingDAO')
        max = 100
    }   

    bookingController(BookingController) {
        bookingService = ref('bookingService')      
    }
}
&lt;/pre&gt;

&lt;h2&gt;What does injection mean?&lt;/h2&gt;
&lt;p&gt;Injection (or component wiring) simply means the substitution of generic formal parameters by the effective parameters during the specialization.&lt;/p&gt;

&lt;h1&gt;Why using DI?&lt;/h1&gt;
&lt;p&gt;We have seen that DI is semantically equivalent to parameterized classes. Parameterized class-based genericity and load-time weaving AOP is a perfect combinaison to manage components. So why using DI? Simply because genericity based on parametric polymorphism is often poorly implemented in languages. In Java for example, class parameterization with primary values (String or int for ex.) doesn't exist. Other points are the use of proxy-based AOP with is more adapted to prototype-based programming and object lifecycle management.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17172384-4963346953772682436?l=www.aclement.eu' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.aclement.eu/feeds/4963346953772682436/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17172384&amp;postID=4963346953772682436' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/4963346953772682436'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/4963346953772682436'/><link rel='alternate' type='text/html' href='http://www.aclement.eu/2010/12/new-definition-of-dependency-injection.html' title='A new definition of Dependency Injection'/><author><name>alex</name><uri>http://www.blogger.com/profile/02620873488807515094</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_a6L6uUfUAow/TP5p5zWkz1I/AAAAAAAAAII/Gr0KKnUeP0M/s72-c/di-template.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17172384.post-8105512168159661585</id><published>2010-11-10T15:26:00.000+01:00</published><updated>2010-11-10T15:26:11.171+01:00</updated><title type='text'>New Web DSL in SDM O.4</title><content type='html'>&lt;p&gt;As you already probably know &lt;a href='http://code.google.com/p/simple-dm/'&gt;Simple Dynamic Modules&lt;/a&gt; has been released recently in 0.4 version. You can read the release note &lt;a href='http://code.google.com/p/simple-dm/issues/list?can=1&amp;q=Milestone%3DRelease0.4+&amp;colspec=ID+Type+Status+Priority+Milestone+Owner+Summary&amp;cells=tiles'&gt;here&lt;/a&gt;.
This release comes with a lot of bugfixes and some interesting enhancements. Let's overview one of them.&lt;/p&gt;

&lt;h1&gt;The Web DSL&lt;/h1&gt;
&lt;p&gt;To use use the SDM Web DSL to easily configure your webapp, you just have to require the 'org.sdm:http' module. The semantic of the requiring script will be extended to support the methods defined by the DSL.&lt;/p&gt;
&lt;p&gt;The following example shows how to define a filter, a listener and a servlet.&lt;/p&gt;

&lt;pre class='brush: groovy;'&gt;
require 'org.sdm:http'

web(path:'/oauthdemo', war:'eu/aclement/oauthdemo/webapp/resources/') {
 
 initParams contextConfigLocation:'classpath:eu/aclement/oauthdemo/webapp/application-context.xml'
  
 listener className:'org.springframework.web.context.ContextLoaderListener'
 
 filter name:'springSecurityFilterChain', className:'org.springframework.web.filter.DelegatingFilterProxy'
 
 servlet(name:'CXFServlet', className:'org.sdm.cxf.SdmCxfServlet', url:'/services/*') {
  bus = serviceRegistry.lookup('cxf')
 }
}
&lt;/pre&gt;

The above code is straight forward. You can pass a closure to the servlet method that is responsible to initialize the created servlet.

&lt;h1&gt;What's next?&lt;/h1&gt;
&lt;p&gt;We could imagine a higher level DSL dedicated to a particular web framework, that would be responsible to automatically create the servlet, filters and listeners required by the application. For example, for the JSF framework we could have:&lt;/p&gt;

&lt;pre class='brush: groovy;'&gt;
require 'org.sdm:jsf'

jsf()
&lt;/pre&gt;

&lt;p&gt;With the appropriates conventions, this would allow to simplify the configuration to the very minimum.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17172384-8105512168159661585?l=www.aclement.eu' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.aclement.eu/feeds/8105512168159661585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17172384&amp;postID=8105512168159661585' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/8105512168159661585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/8105512168159661585'/><link rel='alternate' type='text/html' href='http://www.aclement.eu/2010/11/new-web-dsl-in-sdm-o4.html' title='New Web DSL in SDM O.4'/><author><name>alex</name><uri>http://www.blogger.com/profile/02620873488807515094</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17172384.post-1276023794830909781</id><published>2010-08-23T12:34:00.006+02:00</published><updated>2010-09-02T12:24:31.532+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Extender pattern'/><category scheme='http://www.blogger.com/atom/ns#' term='SDM'/><category scheme='http://www.blogger.com/atom/ns#' term='meta-programming'/><title type='text'>Extender pattern in SDM</title><content type='html'>&lt;p&gt;This article introduces the Extender pattern and how it is implemented in the &lt;a href='http://code.google.com/p/simple-dm/'&gt;Simple Dynamic Modules&lt;/a&gt; framework.&lt;/p&gt; 

&lt;h1&gt;Pattern principles&lt;/h1&gt;

&lt;p&gt;The Extender pattern is one of the most powerful pattern coming from the OSGI world.
This pattern defines the concept of meta modules, that can extend the semantic of other modules&lt;/p&gt;
&lt;p&gt;A meta module usually defines one or more abstractions within a wide range of possibilities from a simple key/value configuration model to a complete language or DSL. Modules can use the models or languages provided by these meta modules.&lt;/p&gt;

&lt;h1&gt;Pattern implementation in SDM&lt;/h1&gt;
&lt;p&gt;&lt;a href='http://code.google.com/p/simple-dm/wiki/FirstSteps'&gt;Simple Dynamic Modules&lt;/a&gt; (SDM)  version 0.3, that has been released recently, contains an implementation of the Extender pattern. Combined with the powerful meta programming capabilities of Groovy, SDM becomes the perfect tool to package and use DSLs (just like the way &lt;a href='http://rubygems.org/'&gt;RubyGems&lt;/a&gt; does). Let's discover how it works.&lt;/p&gt;
&lt;h2&gt;Extender meta modules&lt;/h2&gt;
&lt;p&gt;The extender module simply has to implement the onRequire method in its main script (ModuleMain), which is called whenever the module is required by another module.&lt;/p&gt;

&lt;p&gt;For example, in the Camel meta module (a module provided by SDM, exposing the Apache Camel ESB &lt;a href='http://camel.apache.org/dsl.html'&gt;DSL&lt;/a&gt;), we can see that the main script uses meta-programing to add the Camel mixin to the requiring object.&lt;/p&gt; 

&lt;pre class="brush: groovy;"&gt;
package org.sdm.camel

require group: 'org.apache.camel', module: 'camel-spring', revision: '2.2.0'
...
def onRequire(ctx) {
   ctx.requiringObject.metaClass.mixin (org.sdm.camel.dsl.CamelMixin) 
}
&lt;/pre&gt;

&lt;h3&gt;The Camel mixin&lt;/h3&gt;
&lt;p&gt;The Camel mixin simply exposes the Camel DSL as a mixin.&lt;/p&gt;

&lt;h2&gt;Extended modules&lt;/h2&gt;
&lt;p&gt;The extended module script simply requires the extender module using the &lt;b&gt;require&lt;/b&gt; method. Because it has been automatically enhanced at runtime by the extender module, the script can use the Camel DSL.&lt;/p&gt;

&lt;pre class="brush: groovy;"&gt;
package org.sdm.testapp

require group: 'org.sdm', module: 'camel', revision: SDM_VERSION
  
routes {
   errorHandler noErrorHandler()
 
   from('cxfrs://bean://rsServer') {
      process new DebugProcessor()
      to 'bean://helloService'
   }
}
&lt;/pre&gt;

&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;Armed with the Extender pattern and combined to the powerful meta programming capabilities of Groovy, SDM becomes the perfect tool to package and use DSLs the most efficient way.&lt;/p&gt;
&lt;p&gt;SDM allows the JVM platform to compete with the best modular and dynamic platforms like Ruby and its famous RubyGems.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17172384-1276023794830909781?l=www.aclement.eu' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.aclement.eu/feeds/1276023794830909781/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17172384&amp;postID=1276023794830909781' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/1276023794830909781'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/1276023794830909781'/><link rel='alternate' type='text/html' href='http://www.aclement.eu/2010/08/extender-pattern-in-sdm.html' title='Extender pattern in SDM'/><author><name>alex</name><uri>http://www.blogger.com/profile/02620873488807515094</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17172384.post-967158465592656428</id><published>2010-07-10T11:17:00.005+02:00</published><updated>2010-08-26T14:15:10.395+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Simple Dynamic Module'/><title type='text'>Simple DM for Maven 0.2 released</title><content type='html'>&lt;p&gt;Simple Dynamic Modules for Maven 0.2 is released.&lt;/p&gt;
&lt;h1&gt;Feature list&lt;/h1&gt;
&lt;p&gt;&lt;ul&gt;
&lt;li&gt;Maven dynamic modules&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Module lifecycle management (start, stop, restart) at runtime&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Runtime dependency management&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Runtime module versioning&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Service activation&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Application server&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;&lt;/p&gt;
&lt;p&gt;
Check it out here:&lt;/br&gt;
&lt;a href='http://code.google.com/p/simple-dm'&gt;Simple Dynamic Modules for Maven&lt;/a&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17172384-967158465592656428?l=www.aclement.eu' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.aclement.eu/feeds/967158465592656428/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17172384&amp;postID=967158465592656428' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/967158465592656428'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/967158465592656428'/><link rel='alternate' type='text/html' href='http://www.aclement.eu/2010/07/simple-dm-for-maven-02-released.html' title='Simple DM for Maven 0.2 released'/><author><name>alex</name><uri>http://www.blogger.com/profile/02620873488807515094</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17172384.post-6581710400064444212</id><published>2010-03-25T16:13:00.009+01:00</published><updated>2010-07-18T10:29:27.542+02:00</updated><title type='text'>CSS fluid &amp; accessible layout</title><content type='html'>This article demonstrates how to design fluid and multi-channel (from mobile to desktop screens) applications layout with CSS that can display indifferently on a mobile device or a desktop screen.
We will use different technics such as relative positioning and dimensioning, CSS media queries and retractable panels.

&lt;h1&gt;Demo&lt;/h1&gt;
Take a look at this &lt;a href='http://fs.aclement.eu/journal/index.html'&gt;page&lt;/a&gt; to see a fluid layout demo. 
Try to resize the browser window horizontally to see how the layout reacts.
The demo will work indifferently on your desktop computer or your iphone.
Note: the demo will work on any good modern browser: firefox and webkit based browsers.

&lt;h1&gt;Fluid layout&lt;/h1&gt;
A fluid layout means a layout that can be dynamically adapted to various screen dimensions. 
To get a fluid layout the following requirements needs to be met:
&lt;h2&gt;Relative positioning and dimensioning&lt;/h2&gt;  

&lt;h4&gt;Floating blocks&lt;/h4&gt;
Floating positioning is a subcase of relative positioning.  

&lt;h2&gt;Retractable panels&lt;/h2&gt;
To display a page on small screens sometimes it is necessary to retract panels.
For example a lateral menu can be made retractable based on the device screen size using CSS 3 media queries.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17172384-6581710400064444212?l=www.aclement.eu' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.aclement.eu/feeds/6581710400064444212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17172384&amp;postID=6581710400064444212' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/6581710400064444212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/6581710400064444212'/><link rel='alternate' type='text/html' href='http://www.aclement.eu/2010/03/ccs-accessible-fluid-layout.html' title='CSS fluid &amp; accessible layout'/><author><name>alex</name><uri>http://www.blogger.com/profile/02620873488807515094</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17172384.post-1189324394644298129</id><published>2010-03-15T16:32:00.007+01:00</published><updated>2010-08-18T11:46:34.375+02:00</updated><title type='text'>About MVC pattern in JSF</title><content type='html'>&lt;h1&gt;MVC Pattern&lt;/h1&gt;
&lt;p&gt;MVC is a design pattern to develop layered applications. It is very popular especially on Web environment. There are hundreds of web frameworks that implements refinements of the MVC pattern. Most of them are implemented on top of the command pattern to be adapted to the request/response paradigm.&lt;/p&gt;
&lt;p&gt;Note: This article deals only with MVC frameworks implemented on the server side, so this is NOT about MVC in RIA frameworks such as Dojo or Flex.&lt;/p&gt;

&lt;h1&gt;Command pattern based MVC&lt;/h1&gt;
&lt;p&gt;Most of the existing frameworks found around the web are based on the command pattern. Among them there are Struts, Rails, Spring MVC, etc...&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_a6L6uUfUAow/SvgFz2lI4JI/AAAAAAAAAGo/0ct7lATkxck/s1600-h/test-model-cde.png"&gt;&lt;img src="http://2.bp.blogspot.com/_a6L6uUfUAow/SvgFz2lI4JI/AAAAAAAAAGo/0ct7lATkxck/s400/test-model-cde.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5402074141413662866" /&gt;&lt;/a&gt;

&lt;h2&gt;The Command&lt;/h2&gt;
&lt;p&gt;The command object is simply an operation of the MVC controller. It can be implemented  in different variations in the frameworks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;As an explicit object like in Struts (Action)&lt;/li&gt;
&lt;li&gt;As closure or method like in Rails&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Command parameters&lt;/h2&gt;
Command objects have parameters (or data).These data objects (DTO) can be validated and filled automatically with homonym attributes from the request.

&lt;h2&gt;Data binding&lt;/h2&gt;
Usually, in command pattern based MVC frameworks, the binding relation is a surjection from the model to the view properties. The inverse is not defined. 

&lt;h1&gt;JSF MVC&lt;/h1&gt;
&lt;p&gt;The JSF MVC is different from the former version because it has real views that lived on the server and emit events that are listen by the controllers. The server side views are connected to the DOM (in case of DOM rendering) through a &lt;a href="http://en.wikipedia.org/wiki/Bridge_pattern"&gt;bridge&lt;/a&gt; (not to be confused with the portlet bridge).&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_a6L6uUfUAow/SvgLy4orhEI/AAAAAAAAAGw/kI89v67ZqGQ/s1600-h/test-model-jsf.png"&gt;&lt;img  src="http://1.bp.blogspot.com/_a6L6uUfUAow/SvgLy4orhEI/AAAAAAAAAGw/kI89v67ZqGQ/s400/test-model-jsf.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5402080721855284290" /&gt;&lt;/a&gt;

&lt;h2&gt;The bridge&lt;/h2&gt;
&lt;p&gt;The bridge is bidirectional and serves two purposes.&lt;/p&gt;

&lt;h4&gt;Event listening&lt;/h4&gt;
&lt;p&gt;First, it bridges the gap between the HTTP request/response paradigm with the event model thats exists in JSF. When a user clicks on a DOM widget, the DOM event is propagated to the UIComponent counterpart on the server server side, converted into a JSF event emitted by the component.&lt;/p&gt;

&lt;h4&gt;View rendering&lt;/h4&gt;
The bridge triggers (render response phase) the view rendering and updates the DOM accordingly.

&lt;h2&gt;Bijective binding&lt;/h2&gt;
The JSF binding model is bijective. It means that the same binding metadata are used to bind the model to the view properties in the "render response" phase and to bind the view to the model properties in the "apply request values" phase.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17172384-1189324394644298129?l=www.aclement.eu' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.aclement.eu/feeds/1189324394644298129/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17172384&amp;postID=1189324394644298129' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/1189324394644298129'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/1189324394644298129'/><link rel='alternate' type='text/html' href='http://www.aclement.eu/2010/03/about-mvc-pattern-in-jsf.html' title='About MVC pattern in JSF'/><author><name>alex</name><uri>http://www.blogger.com/profile/02620873488807515094</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_a6L6uUfUAow/SvgFz2lI4JI/AAAAAAAAAGo/0ct7lATkxck/s72-c/test-model-cde.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17172384.post-6287409835615231513</id><published>2010-02-19T17:27:00.045+01:00</published><updated>2010-03-15T16:21:35.935+01:00</updated><title type='text'>JSF like validation plugin for Grails</title><content type='html'>&lt;h1&gt;Purposes&lt;/h1&gt;
&lt;p&gt;JSF has a nice server side component model for defining the views. The UI components (or widgets) live on the server and are composed together to form a view.&lt;/p&gt;
&lt;p&gt;JSF provides a powerful data binding (plus validation and conversion) feature between the view and the model properties. Furthermore, the binding is bijective (or bidirectional), which means that this works also between the model and the widgets properties.&lt;/p&gt;

&lt;p&gt;Grails doesn't have an equivalent server side component model, but instead is based on the Command pattern whereas the web request plays the Command role. Grails provides a binding framework that can bind request parameters to model properties but has to be invoked explicitly from the controller. Grails also provides a set of widgets (implemented as taglibs) but they are involved only in the rendering of views. Widget properties are also bound to the model with the help of Groovy scriptlets. So in Grails there is no bijective binding function.
&lt;/p&gt;

&lt;p&gt;The purpose of the autobind Grails plugin is to provide to full bijective binding (with validation and conversion) mechanism in a JSF like manner.&lt;/p&gt;

&lt;h1&gt;Requirements&lt;/h1&gt;
&lt;p&gt;The autobind plugin requires the use of the Spring Webflow plugin available by default in Grails to define the control logic.&lt;/p&gt;

&lt;h1&gt;Usage&lt;/h1&gt;
&lt;h2&gt;Autobind plugin installation&lt;/h2&gt;
&lt;p&gt;First you need to install the autobind plugin.
Download it here:
&lt;a href='http://dl.dropbox.com/u/2507604/grails-autobind-0.1.zip'&gt;Autobind Plugin&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
Plugin installation is easy. Follow the instructions here: 
&lt;a href='http://www.grails.org/plugin/home'&gt;Grails plugins&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
You can type the following command from your grails project home to install the autobind plugin in your project:

&lt;pre class="brush: groovy;"&gt;
grails install-plugin /path/to/downloaded/plugin/grails-autobind-0.1.zip
&lt;/pre&gt;
&lt;/p&gt;

&lt;h2&gt;The bind function&lt;/h2&gt;
To bind a widget property to a model bean property you have to use the bind function.
You can use the immediate attribute if you want to skip the validation.

&lt;pre class="brush: xml;"&gt;
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&amp;gt;

&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" /&amp;gt;
  &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=us-ascii" /&amp;gt;
  &amp;lt;meta name="layout" content="main" /&amp;gt;

  &amp;lt;title&amp;gt;Edit Book&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;div class="nav"&amp;gt;
    &amp;lt;span class="menuButton"&amp;gt;&amp;lt;a class="home" href=
    "${createLinkTo(dir:'')}"&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt; &amp;lt;span class="menuButton"&amp;gt;Book List&amp;lt;/span&amp;gt;
    &amp;lt;span class="menuButton"&amp;gt;New Book&amp;lt;/span&amp;gt;
  &amp;lt;/div&amp;gt;

  &amp;lt;div class="body"&amp;gt;
    &amp;lt;h1&amp;gt;Edit Book&amp;lt;/h1&amp;gt;

    &amp;lt;div class="message"&amp;gt;
      ${flash.message}
    &amp;lt;/div&amp;gt;

    &amp;lt;div class="errors"&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;input type="hidden" name="id" value="${book.id}" /&amp;gt;
    &amp;lt;input type="hidden" name="version" value="${book.version}" /&amp;gt;

    &amp;lt;div class="dialog"&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;tbody&amp;gt;
          &amp;lt;tr class="prop"&amp;gt;
            &amp;lt;td valign="top" class="name"&amp;gt;&amp;lt;label for="author"&amp;gt;Author:&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;

            &amp;lt;td valign="top" class=
            "value ${hasErrors(bean: book, field: 'author', 'errors')}"&amp;gt;&amp;lt;input type=
            "text" id="author" name="author" value=
            "${bind(bean: book, field:'author')}" /&amp;gt;&amp;lt;/td&amp;gt;
          &amp;lt;/tr&amp;gt;

          &amp;lt;tr class="prop"&amp;gt;
            &amp;lt;td valign="top" class="name"&amp;gt;&amp;lt;label for="title"&amp;gt;Title:&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;

            &amp;lt;td valign="top" class=
            "value ${hasErrors(bean: book, field: 'title', 'errors')}"&amp;gt;&amp;lt;input type="text"
            id="title" name="title" value="${bind(bean: book, field: 'title')}" /&amp;gt;&amp;lt;/td&amp;gt;
          &amp;lt;/tr&amp;gt;
        &amp;lt;/tbody&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;div class="buttons"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;h2&gt;The controller&lt;/h2&gt;
The control logic has to be implemented using a web flow. The edition flow contains no explicit calls to binding or validation logic. The book object within the conversation is implicitly updated and validated without any explicit call to the binding framework.

 
&lt;pre class="brush: groovy;"&gt;
class BookController {

 def beforeInterceptor = {
  println "Controller Interceptor Tracing action ${actionUri}"
 }

 def index = { 
  redirect(action: list, params: params)
 }
 
 // the delete, save and update actions only accept POST requests
 static allowedMethods = [delete: 'POST', save: 'POST', update: 'POST']  
 
 def editionFlow = {
  start {
   action {
    def book = Book.get(params.id) 
    [book: book]
   }
   on('success').to 'show'
  }
  
  show {
   on('edit').to 'edit'
  }
  
  edit {      
   on('update') {     
        
   }.to 'end'  

   on('cancel').to 'end'
  }  
  
  end {
   redirect(controller:"book", action:"list")
  }  
  
 } 
 
 def list = {
  params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
  [books: Book.list(), total: Book.count()]
 } 
 
 def delete = {
  def bookInstance = Book.get( params.id )
  if(bookInstance) {
   try {
    bookInstance.delete()
    flash.message = "Book ${params.id} deleted"
    redirect(action:list)
   }
   catch(org.springframework.dao.DataIntegrityViolationException e) {
    flash.message = "Book ${params.id} could not be deleted"
    redirect(action:show,id:params.id)
   }
  }
  else {
   flash.message = "Book not found with id ${params.id}"
   redirect(action:list)
  }
 }
 
 def create = {
  def book = new Book()
  book.properties = params
  return [book: book]
 } 
}

&lt;/pre&gt;

&lt;h2&gt;No binding and validation code&lt;/h2&gt;
&lt;p&gt;As you can see there is no binding and validation logic in controller actions.&lt;/p&gt;

&lt;h1&gt;Under the hood&lt;/h1&gt;
&lt;h2&gt;The bind function&lt;/h2&gt;

&lt;p&gt;The bind function of the BindingTagLib store the binding metadata in the flash (or flow) scope to be reused when the form is post back.&lt;/p&gt; 

&lt;p&gt;For example, the bind function binds the author property of the book bean to the value property of the HTML input control with id "author".&lt;/p&gt;
 
&lt;pre class="brush: xml;"&gt;
&lt;td valign="top" class="value ${hasErrors(bean: book, field: 'author', 'errors')}"&gt;
&lt;input type="text" id="author" name="author" value="${bind(bean: book, field:'author')}" /&gt;
&lt;/td&gt;
&lt;/pre&gt; 

&lt;h2&gt;The BindingTagLib&lt;/h2&gt;

&lt;pre class="brush: groovy;"&gt;
class BindingTagLib {

 private getBindings() {
  def ctx = RequestContextHolder.getRequestContext()?.flowScope ?: flash
  if (!ctx.bindings)
   ctx.bindings = []
        ctx.bindings
 }

 private getImmediates() {
  def ctx = RequestContextHolder.getRequestContext()?.flowScope ?: flash
  if (!ctx.immediateActions)
   ctx.immediateActions = []
        ctx.immediateActions
 }

 def bind = { attrs, body -&gt;
  def bindings = getBindings()  
  bindings &lt;&lt; attrs  
  out &lt;&lt; fieldValue(attrs, body)  
 }

 def actionButton = { attrs, body -&gt;
  boolean immediate = attrs['immediate']
        if (immediate) {
         def immediates = getImmediates()
         immediates &lt;&lt; attrs['name']
        }
  out &lt;&lt; submitButton(attrs, body)
 }
 
}
&lt;/pre&gt;

&lt;h2&gt;Autobinder object&lt;/h2&gt; 
&lt;p&gt;The autobinder object is responsible of validating and binding request submitted values to the model bean properties. For that, it uses binding metadata collected by the bind function when rendering the view and stored in the flow (or flash) scope .&lt;/p&gt;

&lt;pre class="brush: groovy;"&gt;
class Autobinder {

 private static LOG = LogFactory.getLog(Autobinder.class)

 def eventFactory = new EventFactorySupport()

 def exceptionHandler = new AutobindExecutionExceptionHandler()

 def autobind() {
  try {
   def ctx = RequestContextHolder.getRequestContext()
   def exeCtx = ctx.getFlowExecutionContext()
   def reqCtx = ctx.getRequestScope()
   def flowSession = exeCtx.activeSession
   def state = flowSession.state
   def params = ctx.requestParameters
  
   def scope = ctx?.flowScope   

   def handlers = exeCtx.definition.exceptionHandlerSet
   handlers.add exceptionHandler
     
   LOG.debug "calling autobind"
   def bindings = scope.bindings ?: []
   def immediates = scope.immediateActions ?: []
   //reset bindings
   scope.bindings = null
   scope.immediateActions = null
  
   def eventId = params.asMap().keySet().find { n -&gt; n =~ /_eventId_/ }
   if(!eventId) { return }         

   def m = eventId =~ /_eventId_(.*)/
   def event = m[0][1]
            
   if (immediates.find { it == event }) {
      LOG.debug "skipping binding for immediate action: $event" 
      return
   }
     
   def beans = [] as Set
     
   bindings.each { binding -&gt;
    def field = binding.field
    def bean = scope.attributes.values().find { v -&gt;
       v == binding.bean
    }
    
    assert bean
 
    def value = params[field]   
    bean."$field" = value
    LOG.debug "Assigning [$bean] $field : $value"
    beans &lt;&lt; bean
   }
 
   boolean error = false
   beans.each { 
    if(!it.validate()) {
     error = true     
    }
   } 
   if(error) {
    checkForErrors(ctx, scope.asMap())
    throw new ValidationException("edition", "edit", "validation error");
   }
  } catch(IllegalStateException e) {
   LOG.debug e
  }
  
  LOG.debug 'autobind end'
 }

 def checkForErrors(context, scope) {
  for(entry in scope) {
   try {
             if(entry.value instanceof GroovyObject) {
              LOG.debug "check errors for ${entry.value}"
                 def errors = entry.value.errors
                 if(errors?.hasErrors()) {
                     context.flashScope.put("${GrailsApplicationAttributes.ERRORS}_${entry.key}", errors )
                 }
             }
         }
         catch(MissingPropertyException) {
                 // ignore
         }
  }
 }
}
&lt;/pre&gt;

&lt;h2&gt;Spring webflow listener&lt;/h2&gt;
&lt;p&gt;The autobind is triggered when the Spring Webflow is resuming.&lt;/p&gt;


&lt;pre class="brush: groovy;"&gt;
class AutobindFlowExecutionListener extends FlowExecutionListenerAdapter {

 private static LOG = LogFactory.getLog(AutobindFlowExecutionListener.class)

 def autobinder = new Autobinder()

 @Override
 void resuming(RequestContext context) {
  LOG.debug "AutobindFlowExecutionListener resuming"
  autobinder.autobind()
 }

}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17172384-6287409835615231513?l=www.aclement.eu' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.aclement.eu/feeds/6287409835615231513/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17172384&amp;postID=6287409835615231513' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/6287409835615231513'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/6287409835615231513'/><link rel='alternate' type='text/html' href='http://www.aclement.eu/2010/02/jsf-like-validation-and-binding-pseudo.html' title='JSF like validation plugin for Grails'/><author><name>alex</name><uri>http://www.blogger.com/profile/02620873488807515094</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17172384.post-8989252974463267863</id><published>2009-08-21T10:53:00.012+02:00</published><updated>2010-08-18T11:48:19.415+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='uml'/><category scheme='http://www.blogger.com/atom/ns#' term='ria'/><category scheme='http://www.blogger.com/atom/ns#' term='dto'/><category scheme='http://www.blogger.com/atom/ns#' term='ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='conversation'/><category scheme='http://www.blogger.com/atom/ns#' term='catalysis'/><title type='text'>System design example</title><content type='html'>&lt;p&gt;This article shows how to specify and design a software system starting from a simple business use case. It will show basic refinement principles from large abstract use case to fine grained actions and conversations.&lt;/p&gt;

&lt;h1&gt;Addition Example
&lt;/h1&gt;
&lt;p&gt;The business model below shows an abstract addition activity involving a student and a laboratory. The addition action is a very simple action that takes two formal parameters and has no side effect on its participants: the student and the laboratory.&lt;p/&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_a6L6uUfUAow/SdjvYsjfnuI/AAAAAAAAAAc/4Qb1PQMQZp0/s1600-h/add.png"&gt;&lt;img src="http://4.bp.blogspot.com/_a6L6uUfUAow/SdjvYsjfnuI/AAAAAAAAAAc/4Qb1PQMQZp0/s400/add.png" alt="" id="BLOGGER_PHOTO_ID_5321266167294172898" border="0" /&gt;&lt;/a&gt;

&lt;p&gt;The addition is done by a student with the help of a laboratory.&lt;/p&gt;


&lt;h1&gt;Addition Refinement
&lt;/h1&gt;
&lt;p&gt;Now we are going to refine the addition action to show the finner actions. The addition action is composed of a start, a compute action and a editOperand conversation.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_a6L6uUfUAow/SdkZ-DPYZkI/AAAAAAAAAAk/QO1gKE2v31E/s1600-h/add3.png"&gt;&lt;img src="http://4.bp.blogspot.com/_a6L6uUfUAow/SdkZ-DPYZkI/AAAAAAAAAAk/QO1gKE2v31E/s400/add3.png" alt="" id="BLOGGER_PHOTO_ID_5321312988527355458" border="0" /&gt;&lt;/a&gt;

&lt;p&gt;The editOperand action abstracts the complete conversation of the operand edition.  It is important to mention that until now actions that we describe are pure abstract actions and thus have nothing to do with computer systems operations.&lt;/p&gt;

&lt;h1&gt; Conversation definition
&lt;/h1&gt;
&lt;p&gt;Before going further we need to define what the concept of conversation is.
A conversation is a stateful control object and is an abstraction of a set of finner actions.
The conversation state is private, and usually not persistent. Control logic objects are always associated to scope and context concepts which have to do with action refinement and reification. Action refinement and reification will be explained in more details in a later section.&lt;/p&gt;

&lt;h1&gt;Action refinement conformance: Addition workflow
&lt;/h1&gt;
&lt;p&gt;The following activity diagram shows what sequences of the constituent actions realize a valid addition action.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_a6L6uUfUAow/Sdkg0Ehk6sI/AAAAAAAAAAs/sMXrvMUOqH4/s1600-h/add4.png"&gt;&lt;img src="http://4.bp.blogspot.com/_a6L6uUfUAow/Sdkg0Ehk6sI/AAAAAAAAAAs/sMXrvMUOqH4/s400/add4.png" alt="" id="BLOGGER_PHOTO_ID_5321320513654811330" border="0" /&gt;&lt;/a&gt;

&lt;p&gt;We see that the model authorizes n occurrences of the editOperand action and that there is a precondition on the compute action that states that both addition operands are mandatory.&lt;/p&gt;

&lt;h1&gt;Action reification
&lt;/h1&gt;
&lt;p&gt;The previous models show that the addition action has been reified - thats is made real - to a Addtion object on which its finner constituents actions points to. In other words, the Addition object is a participant to its finner actions.&lt;/p&gt;

&lt;h1&gt;Scope and context
&lt;/h1&gt;
&lt;p&gt;Now we see more clearly what scope and context concepts are. The scope is simply the lifecycle of a control object and the context is the control object itself - that is the conversational state of a control object made accessible to its finner constituent actions.&lt;/p&gt;

&lt;h1&gt;The Calculator System&lt;/h1&gt;
&lt;p&gt;We can refine the Laboratory object and detail its constituent objects. The model below shows that the laboratory is composed of a Calculator System and a set of Clerks.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_a6L6uUfUAow/SgvRu7C6bOI/AAAAAAAAACg/gVY94KBCRiM/s1600-h/add5.jpg"&gt;&lt;img  src="http://3.bp.blogspot.com/_a6L6uUfUAow/SgvRu7C6bOI/AAAAAAAAACg/gVY94KBCRiM/s400/add5.jpg" alt="" id="BLOGGER_PHOTO_ID_5335588787604581602" border="0" /&gt;&lt;/a&gt;

&lt;p&gt;We can see that the actions that were realized by the Laboratory at higher level are all dispatched to the Calculator System itself at this level of refinement. In this refinement scenario the clerks don't participate to any actions. We could have imagined other scenarios where a student interacts directly with a clerk who acts as a proxy to the calculator system.&lt;/p&gt;

&lt;h2&gt;System operations&lt;/h2&gt;
&lt;p&gt;Until now we have seen only joint actions whose effects can be described in terms of all participant attributes and action parameters. These are abstract actions in the sense that they won't be implemented but instead refined down to individual operations executed by one participant.&lt;/p&gt;
&lt;p&gt;This is fine when participants  are real objects. This is not the case when they are virtual digital objects. The system has its own representation of the real world. So it is necessary to focus on the system concrete operations. Similarly we could focused on the actions effects that occur on the human brain when interacting with its environment. Human brain is comparable to an information system in the sense that both build internal models of the real world. In both cases there are implementation constraints due to the very nature of the implementation  platform.&lt;/p&gt;

&lt;h2&gt;EditOperand conversation refinement
&lt;/h2&gt;
&lt;p&gt;The editOperand conversation contains the following set of finner operations.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_a6L6uUfUAow/So0WDEGra2I/AAAAAAAAACo/JoB4tsA7nP8/s1600-h/add6.png"&gt;&lt;img  src="http://3.bp.blogspot.com/_a6L6uUfUAow/So0WDEGra2I/AAAAAAAAACo/JoB4tsA7nP8/s400/add6.png" alt="" id="BLOGGER_PHOTO_ID_5371974172420041570" border="0" /&gt;&lt;/a&gt;

&lt;h1&gt;Multi tier design
&lt;/h1&gt;
&lt;h2&gt;3 tier&lt;/h2&gt;
&lt;p&gt;The following model shows a 3 tier design proposal for the Calculator system. Note that the database tier is not shown but encapsulated in the service tier instead. In this architecture a separated service layer exposes the business methods that are consumed by the application tier. Usually in this architecture these are the service tier methods that carry the transactional aspect.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_a6L6uUfUAow/So5WkVle3TI/AAAAAAAAADI/cLSmXDpwiO4/s1600-h/add7.png"&gt;&lt;img  src="http://4.bp.blogspot.com/_a6L6uUfUAow/So5WkVle3TI/AAAAAAAAADI/cLSmXDpwiO4/s400/add7.png" alt="" id="BLOGGER_PHOTO_ID_5372326587769216306" border="0" /&gt;&lt;/a&gt;
&lt;br/&gt;

&lt;h2&gt;2 tier&lt;/h2&gt;
&lt;p&gt;A 2 tier design can be preferred when there is no need to reuse the business logic and therefore the service layer can be omitted.
In this case this is the application control layer directly that is transactional.&lt;/p&gt;

&lt;h2&gt;DTO layer&lt;/h2&gt;
&lt;p&gt;Particular attention has to be made in this case because application needs to retrieve part of the system state from the service tier. Impedance mismatch problems can occur between the domain model (object graph oriented) and the messaging model (serializable tree of objects) needed for remote communication between the two tier. Moreover even if the communication between the two tier is local, problems can occur when attempting for example to materialize a virtual proxy outside the transactional context.
An extra DTO layer may be needed in such cases to bridge the gap.&lt;/p&gt;

&lt;h2&gt;Hibernate session&lt;/h2&gt;
&lt;p&gt;One word about the hibernate session. The regular hibernate session is usually attached to an action (via the HTTP request or a thread local) for scoping and context propagation. This is annoying because conversational scoped objects need to be reattached for each action constituting the conversation. To overcome this, the extended hibernate session can be useful because its scope corresponds to the conversation scope.&lt;/p&gt;

&lt;h1&gt;Client side versus server side application
&lt;/h1&gt;
&lt;p&gt;As part of the design is the choice to deploy the application either client side or server side.&lt;/p&gt;
&lt;p&gt;When deployed on server side (in case of a web application) the browser DOM objects act as proxies for the application objects that resides on the server. Whenever an action is triggered on a DOM object, it delegates it to its server side control object counterpart with a HTTP request call. Because of this server side applications actions typically have a high latency time. AJAX technics can help to reduce the size of the DOM that is refreshed each time an action is called but it doesn't help to reduce latency. Only can it reduces its perception by doing the remote call asynchronously.&lt;/p&gt;
&lt;p&gt;When a low latency time is needed then the client side deployment of the application is the only option. Complete conversations of actions occur directly on local control objects (for example javascript objects in case of a rich internet application), so that action latency is minimal.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17172384-8989252974463267863?l=www.aclement.eu' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.aclement.eu/feeds/8989252974463267863/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17172384&amp;postID=8989252974463267863' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/8989252974463267863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/8989252974463267863'/><link rel='alternate' type='text/html' href='http://www.aclement.eu/2008/09/system-design-example.html' title='System design example'/><author><name>alex</name><uri>http://www.blogger.com/profile/02620873488807515094</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_a6L6uUfUAow/SdjvYsjfnuI/AAAAAAAAAAc/4Qb1PQMQZp0/s72-c/add.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17172384.post-7103284509568523314</id><published>2008-03-24T18:36:00.023+01:00</published><updated>2008-04-12T20:03:42.362+02:00</updated><title type='text'>JSF Ajax enabled portlets for Liferay portal</title><content type='html'>As you know having AJAX working in portlet environment is quite more difficult than in servlet mode. This is mainly due to the fact that portlets render only fragments of pages that are aggregated by a portlet container. And because of this, this is not always easy to make the container able to deal with ajax requests and partial pages rendering.&lt;br/&gt;&lt;br/&gt;

Liferay portal provides tight integration with IceFaces for having JSF AJAX capable portlets. IceFaces is a powerfull  framework providing direct DOM to JSF component model partial and asynchronous bidirectionnal synchronisation through an ajax bridge. This is great and works fine but has one major drawback when using in portal mode. Once rendered and displayed in the client browser, the interactions occur directly with the Icefaces servlet (and not through the portlet container). The consequences are that it is not possible to do a normal http request to refresh the full page. IPC becomes hard to implement and icefaces portlets cannot access portlet api (for instance, reading their preferences). This makes it almost unusable when building real world multi portlet applications.&lt;br/&gt;&lt;br/&gt;

Fortunatly, there is now another solution to have AJAX enable JSF portlets in Liferay. This solution is based on MyFaces tomahawk and its powerfull pprPanelGroup. The pprPanelGroup.is a special component that allows its child components to be rerendered using an AJAX partial page rendering triggerged by javascript events emitted by other components. This component enables easy, powerful and seamless integration of AJAX technologies in the JSF framework.&lt;br/&gt;&lt;br/&gt;

To make pprPanelGroup work in portlet mode, some modifications to the code are required. 

The following patch contains modifications that have to be applied to the tomahawk main trunk distribution: &lt;br/&gt;
&lt;a href="http://cid-52728b65c673d17b.skydrive.live.com/self.aspx/Public/tomahawk-ppr-portlet.patch"&gt;tomahawk-ppr-portlet.patch&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Once tomahawk patched, Liferay code needs to be made aware of partial page rendering. 7 source files need to be modified in the distribution main trunk (4.4.x):&lt;br/&gt;
&lt;a href="http://cid-52728b65c673d17b.skydrive.live.com/self.aspx/Public/liferay-ppr-aware.patch"&gt;liferay-ppr-aware.patch&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
A complete JSR-168 portlet sample (including patched tomahawk.jar and sandbox.jar) that should deploy in a &lt;span style="font-weight:bold;"&gt;patched&lt;/span&gt; liferay 4.4.x without any problems:
&lt;br/&gt;
&lt;a href="http://cid-52728b65c673d17b.skydrive.live.com/self.aspx/Public/sunportlet.war"&gt;sunportlet.war&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Once done you should be able to have AJAX in your JSF portlets :) Let me know if you experiment difficulties. Any feedback will be greatly appreciated.&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17172384-7103284509568523314?l=www.aclement.eu' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.aclement.eu/feeds/7103284509568523314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17172384&amp;postID=7103284509568523314' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/7103284509568523314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17172384/posts/default/7103284509568523314'/><link rel='alternate' type='text/html' href='http://www.aclement.eu/2008/03/jsf-ajax-enabled-portlets-for-liferay.html' title='JSF Ajax enabled portlets for Liferay portal'/><author><name>alex</name><uri>http://www.blogger.com/profile/02620873488807515094</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry></feed>
