<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>XaaB - Anything as a Blog</title>
	<atom:link href="http://myxaab.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://myxaab.wordpress.com</link>
	<description>Code4Fun - My Development Notes</description>
	<lastBuildDate>Tue, 13 Dec 2011 21:59:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='myxaab.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>XaaB - Anything as a Blog</title>
		<link>http://myxaab.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://myxaab.wordpress.com/osd.xml" title="XaaB - Anything as a Blog" />
	<atom:link rel='hub' href='http://myxaab.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Deploying Grails Application to CloudFoundry</title>
		<link>http://myxaab.wordpress.com/2011/07/24/deploying-grails-application-to-cloudfoundry/</link>
		<comments>http://myxaab.wordpress.com/2011/07/24/deploying-grails-application-to-cloudfoundry/#comments</comments>
		<pubDate>Sun, 24 Jul 2011 01:35:53 +0000</pubDate>
		<dc:creator>wowi</dc:creator>
				<category><![CDATA[Groovy & Grails]]></category>
		<category><![CDATA[CloudFoundry]]></category>
		<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://myxaab.wordpress.com/?p=591</guid>
		<description><![CDATA[Here I am sharing the steps to deploy Grails Application to CloudFoundry. Step 1: Install CloudFoundry Plugin Step 2: Configure Credential Create $HOME/.grails/settings.groovy and configure your CloudFoundry credential there. Putting your credential in settings.groovy makes it available to all your Grails projects. The alternative is to configure in BuildConfig.groovy or Config.groovy which makes it available [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=591&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here I am sharing the steps to deploy Grails Application to <a href="http://www.cloudfoundry.com/">CloudFoundry</a>.</p>
<p><strong>Step 1: Install CloudFoundry Plugin</strong></p>
<p><pre class="brush: bash;">
install-plugin cloud-foundry
</pre></p>
<p><strong>Step 2: Configure Credential</strong><br />
Create $HOME/.grails/settings.groovy and configure your CloudFoundry credential there. Putting your credential in settings.groovy makes it available to all your Grails projects. The alternative is to configure in BuildConfig.groovy or Config.groovy which makes it available to that specific project only. Using settings.groovy is better as it keep the credential out of source control. In Windows, $HOME= C:\Users\&lt;username&gt;.</p>
<p><pre class="brush: groovy;">
grails.plugin.cloudfoundry.username = ''
grails.plugin.cloudfoundry.password = ''
</pre></p>
<p><strong>Step 3: Verify Credential</strong><br />
Check whether the credential is working by executing the following command:</p>
<p><pre class="brush: bash;">
cf-info
</pre></p>
<p>You will see a similar print out as shown below<br />
<code><br />
VMware's Cloud Application Platform<br />
For support visit support@cloudfoundry.com<br />
Target: http://api.cloudfoundry.com (v0.999)<br />
User:     &lt;your_username&gt;<br />
Usage:    Memory   (128.0M of 2.0G total)<br />
Services (0 of 16 total)<br />
Apps     (1 of 20 total)<br />
</code><br />
<strong>Step 4: Deploy Grails Application</strong><br />
Now, deploy your Grails application by executing the following command:</p>
<p><pre class="brush: bash;">
cf-push
</pre></p>
<p>If you decided to deploy your application with a different name, use the option &#8211;appname</p>
<p><pre class="brush: bash;">
cf-push --appname=other-name
</pre></p>
<p>During deployment you will be prompted with the following questions. The mysql service can be provisioned at later stage using the cf-create-service.<br />
<code><br />
You're running in the development environment but haven't specified a war file, so one will be built with development settings. Are you sure you want to do proceed? ([y], n)<br />
Application Deployed URL: 'grails-qotd-extjs.cloudfoundry.com'?<br />
Would you like to create and bind a mysql service? ([y], n)<br />
</code></p>
<p><strong>Step 5: Verify Application Deployment</strong><br />
To check your deployment, execute the command below:</p>
<p><pre class="brush: bash;">
cf-apps
</pre></p>
<p>You will see a similar print out as shown below<br />
<code><br />
+-----------------+----+---------+----------------------------------+----------+<br />
| Application     | #  | Health  | URLs                             | Services |<br />
+-----------------+----+---------+----------------------------------+----------+<br />
| &lt;app-name&gt;      | 1  | RUNNING | &lt;app-name&gt;.cloudfoundry.com      |          |<br />
+-----------------+----+---------+----------------------------------+----------+<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myxaab.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myxaab.wordpress.com/591/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myxaab.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myxaab.wordpress.com/591/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/myxaab.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/myxaab.wordpress.com/591/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/myxaab.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/myxaab.wordpress.com/591/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myxaab.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myxaab.wordpress.com/591/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myxaab.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myxaab.wordpress.com/591/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myxaab.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myxaab.wordpress.com/591/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=591&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://myxaab.wordpress.com/2011/07/24/deploying-grails-application-to-cloudfoundry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f623b52e3d6e71e1599b86e0c5f512?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">wsw1jaya</media:title>
		</media:content>
	</item>
		<item>
		<title>Customizing Spring Security Login using ExtJS in Grails Apps</title>
		<link>http://myxaab.wordpress.com/2011/07/20/customizing-spring-security-login-using-extjs-in-grails-apps/</link>
		<comments>http://myxaab.wordpress.com/2011/07/20/customizing-spring-security-login-using-extjs-in-grails-apps/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 15:48:19 +0000</pubDate>
		<dc:creator>wowi</dc:creator>
				<category><![CDATA[Groovy & Grails]]></category>
		<category><![CDATA[Sencha ExtJS]]></category>
		<category><![CDATA[Spring Security]]></category>
		<category><![CDATA[ExtJS 4]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Spring Security 3]]></category>

		<guid isPermaLink="false">http://myxaab.wordpress.com/?p=576</guid>
		<description><![CDATA[I&#8217;ve been wanting to learn Grails for sometime and finally had the time to try out this web application framework. Grails is a very impressive framework, it is really about productivity and simplicity. Some of the benefits are scaffolding, testing framework, easy to create plugin and seamless integration with Spring and Hibernate. As part of my first [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=576&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been wanting to learn <a href="http://www.grails.org">Grails</a> for sometime and finally had the time to try out this web application framework. Grails is a very impressive framework, it is really about productivity and simplicity. Some of the benefits are scaffolding, testing framework, easy to create plugin and seamless integration with Spring and Hibernate. As part of my first attempt, I am customizing the Spring Security Login using ExtJS in a simple Grails application. The focus here is on the integration with Spring Security and ExtJS rather than Grails. <a href="http://myxaab.files.wordpress.com/2011/07/login.png"><img class="aligncenter size-full wp-image-578" title="ExtJS Login Form" src="http://myxaab.files.wordpress.com/2011/07/login.png?w=600" alt=""   /></a> I am using SpringSource Tool Suite (STS 2.7.1) to develop the demo application. The application is to display Quotes randomly and ability to maintain them. Let&#8217;s begin the integration and customization steps.</p>
<p><strong>Step 1: Install the Spring Security Plugin</strong></p>
<p><strong></strong>Spring Security is not built-in Grails, to begin the integration execute the following Grails command.</p>
<p><pre class="brush: bash;">
install-plugin spring-security-core
</pre></p>
<p><strong>Step 2: Generate Domain Classes</strong></p>
<p><strong> </strong>This step will create basic domain classes needed to store user information and the controller that handle the authentication. After executing the command below you will see several files being added to your project, such as LoginController, auth.gsp, denied.gsp, User, Role, UserRole, RequestMap. The domain class name for user and role is up to you to define and if you have an existing user domain, you must decide to integrate it (possibly by extending your domain class to the generated user class). Just a note that the RequestMap is an option and will look into it at later step.</p>
<p><pre class="brush: bash;">
s2-quickstart org.xaab.qotd User Role RequestMap
</pre></p>
<p><strong>Step 3: Define URL mapping for login and logout</strong></p>
<p><strong></strong>In order the make the login and logout controller reachable, the URL mappings must be added into UrlMapping.groovy</p>
<p><pre class="brush: groovy;">
class UrlMappings {
	static mappings = {
		...
		&quot;/login/$action?&quot;(controller: &quot;login&quot;)
		&quot;/logout/$action?&quot;(controller: &quot;logout&quot;)
	}
}
</pre></p>
<p><strong>Step 4: Add Access Control to the Controller</strong></p>
<p><strong></strong>The need for this step depends on how you wants to control the access. You can use @Secured annotation to limit access to certain part of the application. In this example, I am not using annotation to limit the access, instead I define dynamics request maps which is shown in the Step 5. The following code is just an example of how @Secured can be used in the controller.</p>
<p><pre class="brush: groovy;">
package org.example
import grails.plugins.springsecurity.Secured

class PostController {
    ...
    @Secured(['ROLE_USER'])
    def followAjax = { ... }

    @Secured(['ROLE_USER', 'IS_AUTHENTICATED_FULLY'])
    def addPostAjax = { ... }

    def global = { ... }

    @Secured(['ROLE_USER'])
    def timeline = { ... }

    @Secured(['IS_AUTHENTICATED_REMEMBERED'])
    def personal = { ... }
}
</pre></p>
<p><strong>Step 5: Add Dynamic Request Maps</strong></p>
<p><strong></strong>The request maps class was generated in Step 2 and used to limit access by defining the access control at the URL. Here I create the request map in BootStrap.groovy for demo purpose, in your actual application this may be defined in configuration file or database. I don&#8217;t think you should choose between using annotation and request map. You can strike balance by implementing both to handle general and fine-grain access control.</p>
<p><pre class="brush: groovy;">
import org.xaab.qotd.*

class BootStrap {
    def springSecurityService

    def init = { servletContext -&gt;
		...
		new Requestmap(url: '/**', configAttribute: 'IS_AUTHENTICATED_FULLY').save()
		new Requestmap(url: '/quote/**', configAttribute: 'ROLE_ADMIN,IS_AUTHENTICATED_FULLY').save()

		new Requestmap(url: '/js/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
		new Requestmap(url: '/css/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
		new Requestmap(url: '/images/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
		new Requestmap(url: '/ext-4.0.2/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
		new Requestmap(url: '/quote/random', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
		new Requestmap(url: '/login/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
		new Requestmap(url: '/logout/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
		...
    }
    def destroy = {
    }
}
</pre></p>
<p><strong>Step 6: Amend related GSP to add login and logout link</strong></p>
<p><strong></strong>Amend related GSP (random.gsp) to ensure you have the login and logout link. Since I used scaffolding, I must install the templates and ensure the GSP templates are modified.  Once scaffolding templates are installed, you will see the folders /src/templates/scaffolding/**. The files I modified in this sample application are create.gsp, edit.gsp, list.gsp &amp; show.gsp.</p>
<p><pre class="brush: bash;">
install-templates
</pre><br />
<pre class="brush: jscript;">...&lt;/pre&gt;
&lt;div class=&quot;nav&quot;&gt;&lt;span class=&quot;menuButton&quot;&gt;Next Quote&lt;/span&gt; &lt;span class=&quot;menuButton&quot;&gt;Admin&lt;/span&gt; &lt;span class=&quot;menuButton&quot;&gt;Login&lt;/span&gt; &lt;span class=&quot;menuButton&quot;&gt; (Logout)&lt;/span&gt;&lt;/div&gt;
&lt;pre&gt;...

</pre></p>
<p><strong>Step 7: Customize the auth.gsp to Add ExtJs Login Form</strong></p>
<p><strong></strong>By now the integration is completed and if you used the test data in Step 10, you will be able to see the default login page. In order to customize it, copy the ExtJS source into /web-app and in this sample application I am using ExtJS 4.0.2. Start the customization by modifying the auth.gsp as shown below. Do take note on the naming of the fields as it is the convention used in Spring Security.</p>
<p><pre class="brush: jscript;">Login&lt;script type=&quot;text/javascript&quot; src=&quot;${resource(dir:'ext-4.0.2',file:'ext-all.js')}&quot;&gt;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
		var defLoginUrl = '${postUrl}';
		var homeUrl = '${createLink(uri: &quot;/quote/random&quot;)}';

// ]]&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
Ext.onReady(function(){
	Ext.QuickTips.init();

	var loginForm = Ext.create('Ext.form.Panel',{
			url: defLoginUrl,
			title: 'Login',
			renderTo: 'login',
			frame: true,
			cls: 'my-form-class',
			width: 350,
			items: [{
					xtype: 'textfield',
					fieldLabel: 'Login',
					name: 'j_username'
			},{
					xtype: 'textfield',
					inputType: 'password',
					fieldLabel: 'Password',
					name: 'j_password'
			}, {
				xtype: 'checkbox',
				fieldLabel: 'Remember Me?',
				name: '_spring_security_remember_me',
				checked: false
			}],
			buttons: [{
					id: 'lf.btn.login',
					text: 'Login',
					handler: function() {
						fnLoginForm(loginForm);
					}
				},{
					id: 'lf.btn.reset',
					text: 'Reset',
					handler: function() {
						fnResetForm(loginForm);
					}
			}]
	});

});

function fnLoginForm(theForm)
{
	theForm.getForm().submit({
		success: function(form, action) {
			Ext.Msg.alert('Success', 'Login Successful!', function(btn, text) {
				if (btn == 'ok') {
					window.location = homeUrl; //optionally this can be part of the data return by the server.
				}
			});
		},
		failure: function(form, action) {
			Ext.Msg.alert('Warning', action.result.error);
		}
	});
} //end fnLoginForm

function fnResetForm(theForm)
{
	theForm.getForm().reset();
} //end fnResetForm
// ]]&gt;&lt;/script&gt;
</pre></p>
<p><strong>Step 8: Configure Authentication Success and Failure Handler</strong></p>
<p><strong></strong>The ExtJS login form will perform HTTP post to submit the login data however it expects JSON data as response. The default method in the LoginController will not be able to handle this, thus you must define your own handler. Add your handler into Config.groovy as shown below. The handlers are implemented in LoginController in the next step.</p>
<p><pre class="brush: groovy;">
grails.plugins.springsecurity.successHandler.defaultTargetUrl = '/login/authSucccessExtJs'
grails.plugins.springsecurity.successHandler.alwaysUseDefault = true
grails.plugins.springsecurity.failureHandler.defaultFailureUrl = '/login/authFailExtJs?login_error=1'
</pre></p>
<p><strong>Step 9: Implement the Handler in LoginController</strong></p>
<p><strong></strong>After adding the handler, I suggest you remove or comment out the other methods to ensure they are not accessible.</p>
<p><pre class="brush: groovy;">
import grails.converters.JSON

import javax.servlet.http.HttpServletResponse

import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils

import org.springframework.security.authentication.AccountExpiredException
import org.springframework.security.authentication.CredentialsExpiredException
import org.springframework.security.authentication.DisabledException
import org.springframework.security.authentication.LockedException
import org.springframework.security.core.context.SecurityContextHolder as SCH
import org.springframework.security.web.WebAttributes
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter

class LoginController {

	/**
	 * Dependency injection for the authenticationTrustResolver.
	 */
	def authenticationTrustResolver

	/**
	 * Dependency injection for the springSecurityService.
	 */
	def springSecurityService
	...
		/**
	 * The ExtJS Authentication success handler
	 */
	def authSucccessExtJs = {
		render([success: true, username: springSecurityService.authentication.name] as JSON)
	}

	/**
	 * The ExtJS Authentication failure handler
	 */
	def authFailExtJs = {
			def username = session[UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY]
			String msg = ''
			def exception = session[WebAttributes.AUTHENTICATION_EXCEPTION]
			if (exception) {
				if (exception instanceof AccountExpiredException) {
					msg = SpringSecurityUtils.securityConfig.errors.login.expired
				}
				else if (exception instanceof CredentialsExpiredException) {
					msg = SpringSecurityUtils.securityConfig.errors.login.passwordExpired
				}
				else if (exception instanceof DisabledException) {
					msg = SpringSecurityUtils.securityConfig.errors.login.disabled
				}
				else if (exception instanceof LockedException) {
					msg = SpringSecurityUtils.securityConfig.errors.login.locked
				}
				else {
					msg = SpringSecurityUtils.securityConfig.errors.login.fail
				}
			}

			render([success: false, error: msg] as JSON)
	}
}
</pre></p>
<p><strong>Step 10: Setup Test Data</strong></p>
<p><strong></strong>So, you have integrated your Grails application, customized the login form using ExtJS. Now, setup the test data in BootStrap.groovy and launch the application (http://localhost:8080/grails-qotd-extjs).</p>
<p><pre class="brush: groovy;">
import org.xaab.qotd.*

class BootStrap {
    def springSecurityService

    def init = { servletContext -&gt;
		new Quote(author: &quot;Unknown&quot;, content: &quot;If you think sunshine brings you happiness, then you haven’t danced in the rain.&quot;).save()
		new Quote(author: &quot;Lao Tzu&quot;, content: &quot;An ant on the move does more than a dozing ox.&quot;).save()
		new Quote(author: &quot;Tony Robbins&quot;, content: &quot;It not knowing what to do, it’s doing what you know.&quot;).save()
		new Quote(author: &quot;Bruce Lee&quot;, content: &quot;Simplicity is the key to brilliance.&quot;).save()

		...

		def userRole = Role.findByAuthority('ROLE_USER') ?: new Role(authority: 'ROLE_USER').save(failOnError: true)
		def adminRole = Role.findByAuthority('ROLE_ADMIN') ?: new Role(authority: 'ROLE_ADMIN').save(failOnError: true)

		def adminUser = User.findByUsername('admin') ?: new User(
			username: 'admin',
			password: springSecurityService.encodePassword('admin'),
			enabled: true).save(failOnError: true)

		if (!adminUser.authorities.contains(adminRole)) {
			UserRole.create(adminUser, adminRole)
		}
    }
    def destroy = {
    }
}
</pre></p>
<p>Hope this tutorial helps and happy coding!</p>
<p style="text-align:center;"><a title="Grails QOTD ExtJS Source" href="https://github.com/wswijaya/grails-qotd-extjs">download source</a></p>
<p>References:</p>
<ul>
<li><a href="http://burtbeckwith.github.com/grails-spring-security-core/docs/manual/index.html">Spring Security Core Plugin &#8211; Reference Documentation</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myxaab.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myxaab.wordpress.com/576/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myxaab.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myxaab.wordpress.com/576/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/myxaab.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/myxaab.wordpress.com/576/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/myxaab.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/myxaab.wordpress.com/576/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myxaab.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myxaab.wordpress.com/576/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myxaab.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myxaab.wordpress.com/576/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myxaab.wordpress.com/576/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myxaab.wordpress.com/576/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=576&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://myxaab.wordpress.com/2011/07/20/customizing-spring-security-login-using-extjs-in-grails-apps/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f623b52e3d6e71e1599b86e0c5f512?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">wsw1jaya</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/07/login.png" medium="image">
			<media:title type="html">ExtJS Login Form</media:title>
		</media:content>
	</item>
		<item>
		<title>Integrating Sencha Touch Login Form with Spring Security</title>
		<link>http://myxaab.wordpress.com/2011/07/16/integrating-sencha-touch-login-form-with-spring-security/</link>
		<comments>http://myxaab.wordpress.com/2011/07/16/integrating-sencha-touch-login-form-with-spring-security/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 03:33:26 +0000</pubDate>
		<dc:creator>wowi</dc:creator>
				<category><![CDATA[Sencha Touch]]></category>
		<category><![CDATA[Spring Security]]></category>
		<category><![CDATA[Login]]></category>

		<guid isPermaLink="false">http://myxaab.wordpress.com/?p=564</guid>
		<description><![CDATA[Previously, I wrote a tutorial on integrating Spring Security and ExtJS login form. Now I am integrating the same Spring Security code with the Sencha Touch login form. Here I will cover the implementation of the form only and 2 use cases; login &#38; logout. The sample code is based on Sencha Touch 1.1.0 and the foloder [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=564&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Previously, I wrote a tutorial on integrating Spring Security and ExtJS login form. Now I am integrating the same Spring Security code with the Sencha Touch login form. Here I will cover the implementation of the form only and 2 use cases; login &amp; logout. The sample code is based on Sencha Touch 1.1.0 and the foloder structure is following the Sencha Touch MVC.</p>

<a href='http://myxaab.wordpress.com/2011/07/16/integrating-sencha-touch-login-form-with-spring-security/img_0946/' title='Login'><img data-attachment-id='566' data-orig-size='320,419' data-liked='0'width="114" height="150" src="http://myxaab.files.wordpress.com/2011/07/img_0946.png?w=114&#038;h=150" class="attachment-thumbnail" alt="Login" title="Login" /></a>
<a href='http://myxaab.wordpress.com/2011/07/16/integrating-sencha-touch-login-form-with-spring-security/img_0944/' title='Login - Error'><img data-attachment-id='567' data-orig-size='320,419' data-liked='0'width="114" height="150" src="http://myxaab.files.wordpress.com/2011/07/img_0944.png?w=114&#038;h=150" class="attachment-thumbnail" alt="Login - Error" title="Login - Error" /></a>
<a href='http://myxaab.wordpress.com/2011/07/16/integrating-sencha-touch-login-form-with-spring-security/img_0945/' title='Login - Success'><img data-attachment-id='568' data-orig-size='320,418' data-liked='0'width="114" height="150" src="http://myxaab.files.wordpress.com/2011/07/img_0945.png?w=114&#038;h=150" class="attachment-thumbnail" alt="Login - Success" title="Login - Success" /></a>

<p>First, lets see the login form and controller. The form has 2 fields, login id &amp; password. When you click the login button, the form is submitted to http://&lt;ownurl&gt;/j_spring_security_check (the <em>defLoginUrl</em> in line 4 is defined in login.jsp).</p>
<blockquote><p> Just a note, if you are using Sencha Touch 1.0 then you will need to implement a listener within the form to catch the &#8220;submit&#8221; and &#8220;exception&#8221; event. This is because there is a minor defect in the Ext.form.FormPanel submit function and it caused the form to ignore &#8220;success&#8221; &amp; &#8220;failure&#8221; function in the submit.</p></blockquote>
<p><pre class="brush: jscript;">
test.views.LoginForm = Ext.extend(Ext.form.FormPanel, {
   scroll: 'vertical',
   fullscreen: true,
   url: defLoginUrl,
   items: [{
      xtype: 'textfield',
      label: 'Login',
      name: 'j_username'
   },{
      xtype: 'passwordfield',
      label: 'Password',
      name: 'j_password'
   }],
   dockedItems: [{
      xtype: 'toolbar',
      dock: 'bottom',
      items: [{
         text: 'Reset',
         handler: function() {
            test.views.loginForm.reset();
         }
      },{
         text: 'Login',
         ui: 'confirm',
            handler: function() {
               Ext.dispatch({
                  controller: test.controllers.loginController,
                  action: 'submit',
                  data: test.views.loginForm
               });
             }
      }]
   }],
   initComponent: function() {
      test.views.LoginForm.superclass.initComponent.apply(this, arguments);
   }
});
</pre></p>
<p>&nbsp;</p>
<p><pre class="brush: jscript;">
test.controllers.loginController = new Ext.Controller({
   submit: function(options) {
      var theForm = options.data;
      test.views.loginForm.submit({
         method: 'POST',
         waitMsg: {
            message: 'Processing',
            cls : 'demos-loading'
         },
         scope: this,
         success: function(form, response) {
            window.location = '/';
         },
         failure: function(form, response) {
            Ext.Msg.alert('Warning', response.errorMessage);
         }
      });
   }
});
</pre></p>
<p>Depending on the result of the authentication the server side will return a JSON data. The format is</p>
<p><pre class="brush: jscript;">
{&quot;username&quot;:null,&quot;errorMessage&quot;:&quot;Login failed. Try again.&quot;,&quot;loggedIn&quot;:false,&quot;success&quot;:false}
</pre></p>
<p>Once authenticated, you will see the main page with a logout button. The code is shown below.</p>
<p><pre class="brush: jscript;">
test.views.Dashboard = Ext.extend(Ext.Panel, {
   fullscreen: true,
   dockedItems: [{
      xtype: 'toolbar',
      title: 'Dashboard',
      dock: 'top',
      items: [{
         xtype: 'button',
         text: 'Logout',
         ui: 'confirm',
         handler: function() {
            Ext.dispatch({
               controller: test.controllers.dashboardController,
               action: 'logout'
            });
         },
         scope: this
      }]
   }],
   html: '&lt;p&gt;Welcome!&lt;/p&gt;',
   initComponent: function() {
      test.views.Dashboard.superclass.initComponent.apply(this, arguments);
   }
});
</pre></p>
<p>&nbsp;</p>
<p><pre class="brush: jscript;">
test.controllers.dashboardController = new Ext.Controller({
   logout: function(options) {
      window.location = '/j_spring_security_logout';
   }
});
</pre></p>
<p>Hope that is useful. Happy coding!</p>
<p style="text-align:center;"><a href="http://spring-mvc-mlogin.cloudfoundry.com/app/login.do" target="_blank">view demo</a> &#8211; <a href="https://github.com/wswijaya/spring-mvc-mlogin" target="_blank">download source </a></p>
<p>References:</p>
<ul>
<li><a href="http://wp.me/pIacA-81" target="_blank">Customizing Spring Security Login using ExtJS</a></li>
<li><a href="http://wp.me/pIacA-6s" target="_blank">Sencha Touch MVC Application &#8211; Part 2</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myxaab.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myxaab.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myxaab.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myxaab.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/myxaab.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/myxaab.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/myxaab.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/myxaab.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myxaab.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myxaab.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myxaab.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myxaab.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myxaab.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myxaab.wordpress.com/564/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=564&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://myxaab.wordpress.com/2011/07/16/integrating-sencha-touch-login-form-with-spring-security/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f623b52e3d6e71e1599b86e0c5f512?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">wsw1jaya</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/07/img_0946.png?w=114" medium="image">
			<media:title type="html">Login</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/07/img_0944.png?w=114" medium="image">
			<media:title type="html">Login - Error</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/07/img_0945.png?w=114" medium="image">
			<media:title type="html">Login - Success</media:title>
		</media:content>
	</item>
		<item>
		<title>Custom Number Formatting in Flex.</title>
		<link>http://myxaab.wordpress.com/2011/07/12/custom-number-formatting-in-flex/</link>
		<comments>http://myxaab.wordpress.com/2011/07/12/custom-number-formatting-in-flex/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 15:55:00 +0000</pubDate>
		<dc:creator>rudygun4w4n</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[currencyformatter]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[numberformatter]]></category>

		<guid isPermaLink="false">http://myxaab.wordpress.com/?p=550</guid>
		<description><![CDATA[A quick intro before I start. I&#8217;m Rudy and I&#8217;m a new contributor here. Lately I&#8217;m doing a lot of flex programming and although Adobe Flex is quite mature (It has reached version 4.5 this year), I feel that the language is still lack of support to business. One of the missing feature is Number/Currency [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=550&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A quick intro before I start. I&#8217;m Rudy and I&#8217;m a new contributor here.</p>
<p>Lately I&#8217;m doing a lot of flex programming and although Adobe Flex is quite mature (It has reached version 4.5 this year), I feel that the language is still lack of support to business. One of the missing feature is Number/Currency Formatting that accepts pattern as a template format.</p>
<p>In Flex, we have &lt;mx:CurrencyFormatter&gt;<a title="Link" href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/formatters/CurrencyFormatter.html" target="_blank">[link]</a>. However it does not accept Pattern. In addition, it&#8217;s implemented as a tag which does not allow to be invoked in ActionScript. However, in Java this capability is being implemented nicely using DecimalFormat <a title="link" href="http://download.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html">[link]</a>.</p>
<p>Based on the reasons above I decided to create my own formatter that can be called from both ActionScript and mxml. Note that since this is just a quick hack, the code maybe a little bit messy.</p>
<p>Currently it able to cater currency symbol, percentage, # and 0. For example :</p>
<ul>
<li>1234.56 with pattern #,###.## has output 1,234.56</li>
<li>1234.56 with pattern USD#,###.## has output USD 1,234.56</li>
<li>1234.56 with pattern $#,###.## has output $ 1,234.56</li>
<li>1.23 with pattern 000.000 has output 001,230</li>
<li>-12.34 with pattern USD0##.## has output -USD 012.34</li>
<li>123.45 with pattern ###.##% has output 123.45%</li>
</ul>
<p>Usage :</p>
<p><pre class="brush: as3;">
var nf:NumberFormatter = new NumberFormatter();
var number:Number = 1234.56;
nf.formatString = &quot;#,###.##&quot;;
var resultFormatted:String = nf.format(number);
</pre></p>
<p>You can download the full code in <a title="Custom Formatter" href="http://goo.gl/xhBtM" target="_blank">http://goo.gl/xhBtM</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myxaab.wordpress.com/550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myxaab.wordpress.com/550/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myxaab.wordpress.com/550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myxaab.wordpress.com/550/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/myxaab.wordpress.com/550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/myxaab.wordpress.com/550/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/myxaab.wordpress.com/550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/myxaab.wordpress.com/550/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myxaab.wordpress.com/550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myxaab.wordpress.com/550/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myxaab.wordpress.com/550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myxaab.wordpress.com/550/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myxaab.wordpress.com/550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myxaab.wordpress.com/550/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=550&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://myxaab.wordpress.com/2011/07/12/custom-number-formatting-in-flex/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6918c400dfb380e8c452e372247ab7b9?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">rudygun4w4n</media:title>
		</media:content>
	</item>
		<item>
		<title>Display JSON Data using ExtJS 4 Store</title>
		<link>http://myxaab.wordpress.com/2011/07/09/display-json-data-using-extjs4-store/</link>
		<comments>http://myxaab.wordpress.com/2011/07/09/display-json-data-using-extjs4-store/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 05:25:39 +0000</pubDate>
		<dc:creator>wowi</dc:creator>
				<category><![CDATA[Sencha ExtJS]]></category>
		<category><![CDATA[ExtJS 4]]></category>

		<guid isPermaLink="false">http://myxaab.wordpress.com/?p=532</guid>
		<description><![CDATA[I am sharing a short example of how to display JSON data using ExtJS 4 Store. In previous version of ExtJS, there is a small helper class call JsonStore which is used to simplify creation Stores from JSON data. In ExtJS 4 the class is no longer there. In this example, I am retrieving USGS [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=532&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am sharing a short example of how to display JSON data using ExtJS 4 Store. In previous version of ExtJS, there is a small helper class call JsonStore which is used to simplify creation Stores from JSON data. In ExtJS 4 the class is no longer there. In this example, I am retrieving USGS data as JSON and display it in Grid as shown below.</p>
<div id="attachment_534" class="wp-caption aligncenter" style="width: 610px"><a href="http://myxaab.files.wordpress.com/2011/07/9-7-2011-12-51-52-pm1.png"><img class="size-full wp-image-534" title="USGS Data in Grid" src="http://myxaab.files.wordpress.com/2011/07/9-7-2011-12-51-52-pm1.png?w=600&#038;h=175" alt="" width="600" height="175" /></a><p class="wp-caption-text">USGS Data in Gri</p></div>
<p>As shown below in line 20, I use proxy of type JSONP in Ext.data.Store to retrieve the JSON data.</p>
<p><pre class="brush: jscript;">
Ext.onReady(function(){
  Ext.define('UsgsList', {
    extend: 'Ext.data.Model',
    fields: [
       {name: 'fid',       type: 'int'},
       {name: 'title',     type: 'string'},
       {name: 'description',  type: 'string'},
       {name: 'link',      type: 'string'},
       {name: 'pubDate',    type: 'date'},
       {name: 'lat',      type: 'string'},
       {name: 'long',      type: 'string'}
    ],
    idProperty: 'fid'
});

var store = Ext.create('Ext.data.Store', {
    id: 'store',
    model: 'UsgsList',
    proxy: {
       type: 'jsonp',
       url: 'http://query.yahooapis.com/v1/public/yql',
    extraParams: {
       q: 'select * from rss where url=&quot;http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M2.5.xml&quot;',
       format: 'json'
   },
   reader: {
      root: 'query.results.item',
   }
 }
});

function renderTitle(value, p, record) {
   return Ext.String.format('&lt;a href=&quot;{1}&quot; target=&quot;_blank&quot;&gt;{0}&lt;/a&gt;',
   value,
   record.data.link
   );
}

var grid = Ext.create('Ext.grid.Panel', {
   width: 700,
   height: 500,
   title: 'USGS - M2.5+',
   store: store,
   loadMask: true,
   disableSelection: true,
   invalidateScrollerOnRefresh: false,
   viewConfig: {
     trackOver: false
   },
   // grid columns
   columns:[{
      xtype: 'rownumberer',
      width: 50,
      sortable: false
   },{
      id: 'title',
      text: &quot;Title&quot;,
      dataIndex: 'title',
      flex: 1,
      renderer: renderTitle,
      sortable: false
   },{
      id: 'pubDate',
      text: &quot;Published Date&quot;,
      dataIndex: 'pubDate',
      width: 130,
      renderer: Ext.util.Format.dateRenderer('n/j/Y g:i A'),
      sortable: true
   }],
   renderTo: Ext.getBody()
});

// trigger the data store load
store.load();
});

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myxaab.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myxaab.wordpress.com/532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myxaab.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myxaab.wordpress.com/532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/myxaab.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/myxaab.wordpress.com/532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/myxaab.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/myxaab.wordpress.com/532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myxaab.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myxaab.wordpress.com/532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myxaab.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myxaab.wordpress.com/532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myxaab.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myxaab.wordpress.com/532/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=532&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://myxaab.wordpress.com/2011/07/09/display-json-data-using-extjs4-store/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f623b52e3d6e71e1599b86e0c5f512?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">wsw1jaya</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/07/9-7-2011-12-51-52-pm1.png" medium="image">
			<media:title type="html">USGS Data in Grid</media:title>
		</media:content>
	</item>
		<item>
		<title>HTML5 @Google I/O 2011</title>
		<link>http://myxaab.wordpress.com/2011/06/22/html5-google-io-2011/</link>
		<comments>http://myxaab.wordpress.com/2011/06/22/html5-google-io-2011/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 13:09:15 +0000</pubDate>
		<dc:creator>wowi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HTML5]]></category>

		<guid isPermaLink="false">http://myxaab.wordpress.com/?p=526</guid>
		<description><![CDATA[Just sharing some of the talk/presentations on HTML5 at Google I/O 2011. HTML5 seems to be moving fast and you will see some of the cool stuff in the &#8220;HTML5 versus Android&#8221; demo, I/O BootCamp 2011: Getting Started with HTML5 &#160; HTML5 Showcase for Web Developers: The Wow and the How &#160; HTML5 and What&#8217;s Next [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=526&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just sharing some of the talk/presentations on HTML5 at Google I/O 2011. HTML5 seems to be moving fast and you will see some of the cool stuff in the &#8220;HTML5 versus Android&#8221; demo,</p>
<ul>
<li><strong>I/O BootCamp 2011: Getting Started with HTML5</strong><br />
<span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='600' height='368' src='http://www.youtube.com/embed/yd30Nmb3mPU?version=3&amp;rel=1&amp;fs=1&amp;showsearch=0&amp;showinfo=1&amp;iv_load_policy=1&amp;wmode=transparent' frameborder='0'></iframe></span></li>
</ul>
<p>&nbsp;</p>
<ul>
<li><strong>HTML5 Showcase for Web Developers: The Wow and the How</strong><br />
<span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='600' height='368' src='http://www.youtube.com/embed/WlwY6_W4VG8?version=3&amp;rel=1&amp;fs=1&amp;showsearch=0&amp;showinfo=1&amp;iv_load_policy=1&amp;wmode=transparent' frameborder='0'></iframe></span></li>
</ul>
<p>&nbsp;</p>
<ul>
<li><strong>HTML5 and What&#8217;s Next</strong><br />
<span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='600' height='368' src='http://www.youtube.com/embed/qzA60hHca9s?version=3&amp;rel=1&amp;fs=1&amp;showsearch=0&amp;showinfo=1&amp;iv_load_policy=1&amp;wmode=transparent' frameborder='0'></iframe></span></li>
</ul>
<p>&nbsp;</p>
<ul>
<li><strong>GWT + HTML5: A web developers dream!</strong><br />
<span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='600' height='368' src='http://www.youtube.com/embed/KEkR1ox_K10?version=3&amp;rel=1&amp;fs=1&amp;showsearch=0&amp;showinfo=1&amp;iv_load_policy=1&amp;wmode=transparent' frameborder='0'></iframe></span></li>
</ul>
<p>&nbsp;</p>
<ul>
<li><strong>HTML5 vs. Android: Apps or Web Mobile Development?</strong><br />
<span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='600' height='368' src='http://www.youtube.com/embed/4f2Zky_YyyQ?version=3&amp;rel=1&amp;fs=1&amp;showsearch=0&amp;showinfo=1&amp;iv_load_policy=1&amp;wmode=transparent' frameborder='0'></iframe></span></li>
</ul>
<p>&nbsp;</p>
<ul>
<li><strong>HTML5 Today with Google Chrome Frame</strong><br />
<span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='600' height='368' src='http://www.youtube.com/embed/3YkEUpJQP3o?version=3&amp;rel=1&amp;fs=1&amp;showsearch=0&amp;showinfo=1&amp;iv_load_policy=1&amp;wmode=transparent' frameborder='0'></iframe></span></li>
</ul>
<p>&nbsp;</p>
<ul>
<li><strong>Kick-Ass Game Programming with Google Web Toolkit</strong><br />
<span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='600' height='368' src='http://www.youtube.com/embed/F_sbusEUz5w?version=3&amp;rel=1&amp;fs=1&amp;showsearch=0&amp;showinfo=1&amp;iv_load_policy=1&amp;wmode=transparent' frameborder='0'></iframe></span></li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myxaab.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myxaab.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myxaab.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myxaab.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/myxaab.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/myxaab.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/myxaab.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/myxaab.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myxaab.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myxaab.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myxaab.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myxaab.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myxaab.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myxaab.wordpress.com/526/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=526&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://myxaab.wordpress.com/2011/06/22/html5-google-io-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f623b52e3d6e71e1599b86e0c5f512?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">wsw1jaya</media:title>
		</media:content>
	</item>
		<item>
		<title>Integrating JSR303 with Spring MVC 3 and ExtJS Forms</title>
		<link>http://myxaab.wordpress.com/2011/03/22/integrating-jsr303-with-spring-mvc-3-and-extjs-forms/</link>
		<comments>http://myxaab.wordpress.com/2011/03/22/integrating-jsr303-with-spring-mvc-3-and-extjs-forms/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 13:28:05 +0000</pubDate>
		<dc:creator>wowi</dc:creator>
				<category><![CDATA[Sencha ExtJS]]></category>
		<category><![CDATA[Spring MVC]]></category>
		<category><![CDATA[Bean Validation]]></category>
		<category><![CDATA[Ext JS]]></category>
		<category><![CDATA[JSR-303]]></category>
		<category><![CDATA[Spring MVC 3]]></category>

		<guid isPermaLink="false">http://myxaab.wordpress.com/?p=515</guid>
		<description><![CDATA[Previously in Spring MVC and ExtJS Forms I created a simple data entry form and there was no data validation implemented. Typically data validation occurs throughout application layers, from presentation to persistence layer. Here I will be using JSR-303 Bean Validation, where the data validation is defined in the domain model and can be used [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=515&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Previously in <a href="http://wp.me/pIacA-7O" target="_blank">Spring MVC and ExtJS Forms</a> I created a simple data entry form and there was no data validation implemented. Typically data validation occurs throughout application layers, from presentation to persistence layer. Here I will be using JSR-303 Bean Validation, where the data validation is defined in the domain model and can be used thoughout application layers. I will walk through how to integrate data validation into Spring MVC and will be using Hibernate Validator 4.x &#8211; which is the reference implementation for JSR-303 &#8211; to integrate into my previous example.</p>
<p>What is JSR-303?</p>
<blockquote><p>&#8220;This JSR defines a metadata model and API for JavaBean validation. The default metadata source is annotations,<br />
with the ability to override and extend the meta-data through the use of XML validation descriptors.<br />
The validation API developed by this JSR is not intended for use in any one tier or programming model. It is specifically<br />
not tied to either the web tier or the persistence tier, and is available for both server-side application programming,<br />
as well as rich client Swing application developers.&#8221; &#8211; <a title="JSR-303" href="http://jcp.org/en/jsr/summary?id=303" target="_blank">JSR-303 Specification</a></p></blockquote>
<p>The data validation is achieved by defining constraints in the beans. Constraints are defined by a combination of constraint annotation and a list of constraint validation implementations. The constraint annotation can be applied at field-level, property-level (getter), class-level. Currently there are 22 built-in constraints for example <em>@NotNull</em> to check that the annotated value is not null or <em>@Size(min=, max=)</em> to check whether the annotated value lies between the specified range. You can also create your own custom constraint to meet your specific requirement. The concept here is similar to database constraints where the constraint can be applied to table column.</p>
<p>For now, I will walk through how to use the built-in constraints only. As usual, I will start with the configuration required to make the project work. Open the Maven pom.xml and add the following dependencies and repository:</p>
<p><pre class="brush: xml;">
&lt;!-- JSR 303 with Hibernate Validator --&gt;
&lt;dependency&gt;
	&lt;groupId&gt;javax.validation&lt;/groupId&gt;
	&lt;artifactId&gt;validation-api&lt;/artifactId&gt;
	&lt;version&gt;1.0.0.GA&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
	&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
	&lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
	&lt;version&gt;4.1.0.Final&lt;/version&gt;
&lt;/dependency&gt;
...
&lt;!-- For Hibernate Validator Repository --&gt;
&lt;repository&gt;
	&lt;id&gt;org.jboss.repository.release&lt;/id&gt;
	&lt;name&gt;JBoss Maven Release Repository&lt;/name&gt;
	&lt;url&gt;https://repository.jboss.org/nexus/content/repositories/releases&lt;/url&gt;
	&lt;snapshots&gt;&lt;enabled&gt;false&lt;/enabled&gt;&lt;/snapshots&gt;
&lt;/repository&gt;
</pre></p>
<p>In the example, the form is submitted to HomeController and the form is mapped to PersonalContact bean. I added 3 built-in constraints into the PersonalContact bean, @NotBlank, @Patter (using regular expression) and @Email. When message is not define in the constraint annotation, the validator will assign a default value. The second part of the code below shows the validation process. The HomeController is autowired to the Validator bean and the validation() is executed inside the add().</p>
<p><pre class="brush: java;">
public class PersonalContact implements Serializable
{
	private static final long serialVersionUID = 1L;
	private Long id;

	@NotBlank(message=&quot;Please enter name&quot;)
	private String name;
               // using regular expression to define the constraint
	@Pattern(regexp=&quot;[0-9]{8}&quot;, message=&quot;Please enter 8 digit phone number&quot;)
	private String phone;

	@Email
	private String email;

	public PersonalContact() {}

	public PersonalContact(Long id, String name, String phone, String email) {
		super();
		this.id = id;
		this.name = name;
		this.phone = phone;
		this.email = email;
	}
	//getter &amp; setter
}
</pre></p>
<p><pre class="brush: java;">
@Controller
public class HomeController
{
	@Autowired
	private Validator validator;

	@RequestMapping(value=&quot;/&quot;, method=RequestMethod.GET)
	public String home() {
		return &quot;home&quot;;
	}

	@RequestMapping(value=&quot;/load&quot;, method=RequestMethod.POST)
	public @ResponseBody Map&lt;String, ? extends Object&gt; load(PersonalContact input) {
	...
	}

	@RequestMapping(value=&quot;/add&quot;, method=RequestMethod.POST)
	public @ResponseBody Map&lt;String, ? extends Object&gt; add(PersonalContact input, HttpSession session) {
		Map&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();

		Set&lt;ConstraintViolation&lt;PersonalContact&gt;&gt; failures = validator.validate(input);
		if (!failures.isEmpty()) {
			//structure the response for ExtJS Form.
			data.put(&quot;success&quot;,Boolean.FALSE);
			data.put(&quot;errors&quot;, validationMessages(failures));
			data.put(&quot;errorMessage&quot;, &quot;Add Failed!&quot;);
		} else {
			session.setAttribute(input.getName(), input);
			data.put(&quot;success&quot;,Boolean.TRUE);
		}

		return data;
	}
	//iterate to retrieve validation errors and store it in HashMap
	private Map&lt;String, String&gt; validationMessages(Set&lt;ConstraintViolation&lt;PersonalContact&gt;&gt; failures) {
		Map&lt;String, String&gt; failureMessages = new HashMap&lt;String, String&gt;();
		for (ConstraintViolation&lt;PersonalContact&gt; failure : failures) {
			failureMessages.put(failure.getPropertyPath().toString(), failure.getMessage());
		}
		return failureMessages;
	}
}
</pre></p>
<p>Since I used ExtJS forms, I must return JSON response in a specific format and the errors are mapped to the field and displayed as quicktips.<br />

<a href='http://myxaab.wordpress.com/2011/03/22/integrating-jsr303-with-spring-mvc-3-and-extjs-forms/screen2/' title='Error Message'><img data-attachment-id='516' data-orig-size='489,241' data-liked='0'width="150" height="73" src="http://myxaab.files.wordpress.com/2011/03/screen2.png?w=150&#038;h=73" class="attachment-thumbnail" alt="Error Message" title="Error Message" /></a>
<a href='http://myxaab.wordpress.com/2011/03/22/integrating-jsr303-with-spring-mvc-3-and-extjs-forms/screen1/' title='Error Message'><img data-attachment-id='517' data-orig-size='406,232' data-liked='0'width="150" height="85" src="http://myxaab.files.wordpress.com/2011/03/screen1.png?w=150&#038;h=85" class="attachment-thumbnail" alt="Error Message" title="Error Message" /></a>
<br />
The spring-mvc-forms project is updated and available for download at <a href="https://github.com/wswijaya/spring-mvc-forms" target="_blank">myGit</a>. Hope you find it useful. Happy coding! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>References</p>
<ul>
<li>List of built-in constraints is available in the <a href="http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html/validator-usingvalidator.html#validator-defineconstraints-builtin" target="_blank">Hibernate Validator documentation</a>.</li>
<li>JSON response for ExtJS Forms</li>
</ul>
<p><pre class="brush: jscript;">
{
   success: true,
   errors: { field1: 'error for field 1',
                 field2: 'error for field 2',
   	   ...
   }
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myxaab.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myxaab.wordpress.com/515/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myxaab.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myxaab.wordpress.com/515/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/myxaab.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/myxaab.wordpress.com/515/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/myxaab.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/myxaab.wordpress.com/515/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myxaab.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myxaab.wordpress.com/515/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myxaab.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myxaab.wordpress.com/515/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myxaab.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myxaab.wordpress.com/515/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=515&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://myxaab.wordpress.com/2011/03/22/integrating-jsr303-with-spring-mvc-3-and-extjs-forms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f623b52e3d6e71e1599b86e0c5f512?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">wsw1jaya</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/screen2.png?w=150" medium="image">
			<media:title type="html">Error Message</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/screen1.png?w=150" medium="image">
			<media:title type="html">Error Message</media:title>
		</media:content>
	</item>
		<item>
		<title>Customizing Spring Security Login using ExtJS</title>
		<link>http://myxaab.wordpress.com/2011/03/20/customizing-spring-security-login-using-extjs/</link>
		<comments>http://myxaab.wordpress.com/2011/03/20/customizing-spring-security-login-using-extjs/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 07:30:32 +0000</pubDate>
		<dc:creator>wowi</dc:creator>
				<category><![CDATA[Sencha ExtJS]]></category>
		<category><![CDATA[Spring Security]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Spring MVC 3]]></category>
		<category><![CDATA[Spring Security 3]]></category>

		<guid isPermaLink="false">http://myxaab.wordpress.com/?p=497</guid>
		<description><![CDATA[This tutorial will walk through the steps to customize Spring Security login page using Ext JS form. There are a few steps need to be done to customize the login form, because Ext JS form does not work in the same way as the standard HTML form. By default Ext Forms are submitted through Ajax [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=497&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>This tutorial will walk through the steps to customize Spring Security login page using Ext JS form. There are a few steps need to be done to customize the login form, because Ext JS form does not work in the same way as the standard HTML form. By default Ext Forms are submitted through Ajax and response packets are assumed to be JSON. I will be adding the customize login page into my previous example (in <a href="http://wp.me/pIacA-7O" target="_blank">Spring 3 MVC and ExtJS Forms</a>). I will walk through:</div>
<ol>
<li>configuration required to integrate with Spring Security 3 (3.0.5 to be exact),</li>
<li>customize login page, and</li>
<li>implement login handler to return JSON.</li>
</ol>
<div><strong>Step 1</strong>: Configuration required to integrate with Spring Security. If you are using the Spring MVC project template from STS, you will need to add dependencies to Spring Security by modifying the Maven pom.xml file. Add the following property and dependencies:</div>
<p><pre class="brush: xml;">
&lt;properties&gt;
	...
	&lt;org.springframework.security-version&gt;3.0.5.RELEASE&lt;/org.springframework.security-version&gt;
	...
&lt;/properties&gt;
&lt;dependencies&gt;
      ...
      &lt;!-- Spring Security --&gt;
      &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
            &lt;artifactId&gt;spring-security-core&lt;/artifactId&gt;
            &lt;version&gt;${org.springframework.security-version}&lt;/version&gt;
            &lt;exclusions&gt;
                &lt;exclusion&gt;
                    &lt;groupId&gt;commons-logging&lt;/groupId&gt;
                    &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
                &lt;/exclusion&gt;
            &lt;/exclusions&gt;
      &lt;/dependency&gt;
    &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
            &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
            &lt;version&gt;${org.springframework.security-version}&lt;/version&gt;
            &lt;exclusions&gt;
                &lt;exclusion&gt;
                    &lt;groupId&gt;commons-logging&lt;/groupId&gt;
                    &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
                &lt;/exclusion&gt;
            &lt;/exclusions&gt;
      &lt;/dependency&gt;
    &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
            &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
            &lt;version&gt;${org.springframework.security-version}&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
            &lt;artifactId&gt;spring-security-taglibs&lt;/artifactId&gt;
            &lt;version&gt;${org.springframework.security-version}&lt;/version&gt;
      &lt;/dependency&gt;
      ...
&lt;/dependencies&gt;
</pre></p>
<div>Now, create security context file. Let&#8217;s name it applicationContext-security.xml. For this tutorial I used in memory user service and declare user id and password as part of the authentication manager. In the configuration, I declared the form login URL and the login handler. The login page is pointing to the login controller which forward to login.jsp. While login handler beans are used to return JSON to Ext JS form. The interceptor defined that every URL must be authenticated except for login and resources (images,css,javascript). Remember to set the access permission of login page to permit all to avoid endless loop. It is a good practice to default all URL to isAuthenticate() and only permit the necessary URL.</div>
<p><pre class="brush: xml;">
&lt;http use-expressions=&quot;true&quot;&gt;
    &lt;intercept-url pattern=&quot;/resources/**&quot; filters=&quot;none&quot;/&gt;
    &lt;intercept-url pattern=&quot;/app/login.do&quot; access=&quot;permitAll()&quot; /&gt;
    &lt;intercept-url pattern=&quot;/**&quot; access=&quot;isAuthenticated()&quot; /&gt;
      &lt;form-login login-page=&quot;/app/login.do&quot;
      			authentication-success-handler-ref=&quot;loginSuccessHandler&quot;
      			authentication-failure-handler-ref=&quot;loginFailureHandler&quot; /&gt;
      &lt;logout invalidate-session=&quot;true&quot; logout-success-url=&quot;/&quot; logout-url=&quot;/j_spring_security_logout&quot;/&gt;
      &lt;remember-me key=&quot;xaab.springmvclogin&quot; /&gt;
      &lt;session-management session-fixation-protection=&quot;newSession&quot; &gt;
          &lt;concurrency-control max-sessions=&quot;1&quot; error-if-maximum-exceeded=&quot;false&quot;/&gt;
      &lt;/session-management&gt;
&lt;/http&gt;
&lt;!-- all password = password --&gt;
&lt;authentication-manager&gt;
     &lt;authentication-provider&gt;
      	&lt;password-encoder hash=&quot;md5&quot; /&gt;
        &lt;user-service&gt;
            &lt;user name=&quot;user1&quot; password=&quot;5f4dcc3b5aa765d61d8327deb882cf99&quot; authorities=&quot;ROLE_SUPERVISOR, ROLE_USER, ROLE_TELLER&quot; /&gt;
            &lt;user name=&quot;user2&quot; password=&quot;5f4dcc3b5aa765d61d8327deb882cf99&quot; authorities=&quot;ROLE_USER,ROLE_TELLER&quot; /&gt;
            &lt;user name=&quot;user3&quot; password=&quot;5f4dcc3b5aa765d61d8327deb882cf99&quot; authorities=&quot;ROLE_USER&quot; /&gt;
            &lt;user name=&quot;user4&quot; password=&quot;5f4dcc3b5aa765d61d8327deb882cf99&quot; authorities=&quot;ROLE_USER&quot; /&gt;
         &lt;/user-service&gt;
      &lt;/authentication-provider&gt;
&lt;/authentication-manager&gt;

&lt;beans:bean id=&quot;loginSuccessHandler&quot; class=&quot;org.xaab.springmvc.LoginSuccessHandler&quot; /&gt;
&lt;beans:bean id=&quot;loginFailureHandler&quot; class=&quot;org.xaab.springmvc.LoginFailureHandler&quot; /&gt;
</pre></p>
<div>In order to activate the above configuration, you need to include the security context into the context parameter and include the security filter in web.xml.</div>
<p><pre class="brush: xml;">
&lt;!-- part of web.xml --&gt;
&lt;!-- The definition of the Root Spring Container shared by all Servlets and Filters --&gt;
&lt;context-param&gt;
	&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
	&lt;param-value&gt;
		/WEB-INF/spring/root-context.xml
		/WEB-INF/spring/applicationContext-security.xml
	&lt;/param-value&gt;
&lt;/context-param&gt;

&lt;filter&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
&lt;/filter&gt;

&lt;filter-mapping&gt;
    &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
    &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
&lt;/filter-mapping&gt;
</pre></p>
<div><strong>Step 2</strong>: Customize login page. There are basic 3 elements in the default login page generated by Spring Security. They are:</div>
<ol>
<li>Form action: j_spring_security_check</li>
<li>User name input: j_username</li>
<li>Password input: j_password</li>
</ol>
<div>Those are the form fields needed for the Ext login form. The UsernamePasswordAuthenticationFilter watches for a request to the virtual URL (/j_spring_security_check) used for form-based authentication, and attempts to authenticate the user. If necessary, You can customize it to use your own controller to authenticate. Take a look at the spring-mvc-login.js below. One thing to note is, this example redirect to a default URL upon successful login. It is done by modifying the window.location.</div>
<p><pre class="brush: jscript;">
Ext.onReady(function(){
	Ext.QuickTips.init();

	var loginForm = new Ext.FormPanel({
		url: defLoginUrl,
		title: 'Login',
		renderTo: Ext.getBody(),
		frame: true,
		cls: 'my-form-class',
		width: 350,
		items: [{
			xtype: 'textfield',
			fieldLabel: 'Login',
			name: 'j_username'
	              },{
			xtype: 'textfield',
			inputType: 'password',
			fieldLabel: 'Password',
			name: 'j_password'
		}, {
			xtype: 'checkbox',
			fieldLabel: 'Remember Me?',
			name: '_spring_security_remember_me',
			checked: false
		}],
		buttons: [{
			id: 'lf.btn.login',
			text: 'Login',
			handler: function() {
				fnLoginForm(loginForm);
			}
		},{
			id: 'lf.btn.reset',
			text: 'Reset',
			handler: function() {
				fnResetForm(loginForm);
			}
		}]
	});

});
//Submit login and handler response
function fnLoginForm(theForm)
{
theForm.getForm().submit({
	success: function(form, action) {
		Ext.Msg.alert('Success', 'Login Successful!', function(btn, text) {
			if (btn == 'ok') {
				window.location = homeUrl;
			}
		});
	},
	failure: function(form, action) {
		Ext.Msg.alert('Warning', action.result.errorMessage);
	}
});
} //end fnLoginForm

function fnResetForm(theForm)
{
theForm.getForm().reset();
} //end fnResetForm
</pre></p>
<div><strong>Step 3</strong>: Implement login handler to return JSON. Remember the authentication handlers declared in applicationContext-security.xml? now you will need implement it to handle succcess and failure case. For this purpose I used Jackson JSON processor and to include it add the dependency to pom.xml.</div>
<p><pre class="brush: xml;">
&lt;!-- Jackson JSON Processor --&gt;
&lt;dependency&gt;
	&lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
	&lt;artifactId&gt;jackson-mapper-asl&lt;/artifactId&gt;
	&lt;version&gt;1.7.4&lt;/version&gt;
&lt;/dependency&gt;
</pre></p>
<p><pre class="brush: java;">
public class LoginSuccessHandler implements AuthenticationSuccessHandler
{
	public void onAuthenticationSuccess(HttpServletRequest request,
			HttpServletResponse response, Authentication auth) throws IOException,
			ServletException {

		ObjectMapper mapper = new ObjectMapper();
		LoginStatus status = new LoginStatus(true, auth.isAuthenticated(), auth.getName(), null);
		OutputStream out = response.getOutputStream();
		mapper.writeValue(out, status);
	}

}

public class LoginFailureHandler implements AuthenticationFailureHandler
{
	public void onAuthenticationFailure(HttpServletRequest request,
			HttpServletResponse response, AuthenticationException auth)
			throws IOException, ServletException {

		ObjectMapper mapper = new ObjectMapper();
		LoginStatus status = new LoginStatus(false, false, null, &quot;Login failed. Try again.&quot;);
		OutputStream out = response.getOutputStream();
		mapper.writeValue(out, status);
	}

}
public class LoginStatus
{
  private final boolean success;
  private final boolean loggedIn;
  private final String username;
  private final String errorMessage;

  public LoginStatus(boolean success, boolean loggedIn, String username, String errorMessage) {
    this.success = success;
    this.loggedIn = loggedIn;
    this.username = username;
    this.errorMessage = errorMessage;
  }
}
</pre></p>
<div>Time to test drive the code. Lauch <a href="http://localhost:8080/spring-mvc-login/">http://localhost:8080/spring-mvc-login/</a> in the browser and you will be redirected to the login page <a href="http://localhost:8080/spring-mvc-login/app/login.do">http://localhost:8080/spring-mvc-login/app/login.do</a>.</div>

<a href='http://myxaab.wordpress.com/2011/03/20/customizing-spring-security-login-using-extjs/step-1/' title='Login Page'><img data-attachment-id='500' data-orig-size='437,258' data-liked='0'width="150" height="88" src="http://myxaab.files.wordpress.com/2011/03/step-1.png?w=150&#038;h=88" class="attachment-thumbnail" alt="Login Page" title="Login Page" /></a>
<a href='http://myxaab.wordpress.com/2011/03/20/customizing-spring-security-login-using-extjs/step-2/' title='Successful Login'><img data-attachment-id='501' data-orig-size='499,297' data-liked='0'width="150" height="89" src="http://myxaab.files.wordpress.com/2011/03/step-2.png?w=150&#038;h=89" class="attachment-thumbnail" alt="Successful Login" title="Successful Login" /></a>

<div>Some of the things to improve on :</div>
<ul>
<li>Use of SSL</li>
<li>Authenticate to LDAP</li>
<li>Securing &#8220;remember me&#8221; using Token.</li>
</ul>
<div>Hope you find the tutorial useful. Happy coding! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </div>
<div>Update: the source project is downloadable at <a href="https://github.com/wswijaya/spring-mvc-login" target="_blank">myGit</a>.</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myxaab.wordpress.com/497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myxaab.wordpress.com/497/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myxaab.wordpress.com/497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myxaab.wordpress.com/497/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/myxaab.wordpress.com/497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/myxaab.wordpress.com/497/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/myxaab.wordpress.com/497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/myxaab.wordpress.com/497/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myxaab.wordpress.com/497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myxaab.wordpress.com/497/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myxaab.wordpress.com/497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myxaab.wordpress.com/497/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myxaab.wordpress.com/497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myxaab.wordpress.com/497/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=497&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://myxaab.wordpress.com/2011/03/20/customizing-spring-security-login-using-extjs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f623b52e3d6e71e1599b86e0c5f512?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">wsw1jaya</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/step-1.png?w=150" medium="image">
			<media:title type="html">Login Page</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/step-2.png?w=150" medium="image">
			<media:title type="html">Successful Login</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring 3 MVC and ExtJS Forms</title>
		<link>http://myxaab.wordpress.com/2011/03/16/spring-3-mvc-and-extjs-forms/</link>
		<comments>http://myxaab.wordpress.com/2011/03/16/spring-3-mvc-and-extjs-forms/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 16:36:37 +0000</pubDate>
		<dc:creator>wowi</dc:creator>
				<category><![CDATA[Sencha ExtJS]]></category>
		<category><![CDATA[Spring MVC]]></category>
		<category><![CDATA[SpringSource]]></category>
		<category><![CDATA[Ext JS]]></category>
		<category><![CDATA[Ext.FormPanel]]></category>
		<category><![CDATA[Spring MVC 3]]></category>

		<guid isPermaLink="false">http://myxaab.wordpress.com/?p=484</guid>
		<description><![CDATA[In my previous post Beginning Spring MVC 3, I shared a simple tutorial to start developing Spring MVC 3. It covered the tools required and the steps to setup the project. This tutorial will take a step further and walk through how to work with forms &#8211; Ext JS form to be specific &#8211; for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=484&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my previous post <a href="http://wp.me/pIacA-7u">Beginning Spring MVC 3</a>, I shared a simple tutorial to start developing Spring MVC 3. It covered the tools required and the steps to setup the project. This tutorial will take a step further and walk through how to work with forms &#8211; Ext JS form to be specific &#8211; for loading of data and submission of data for processing. I will be assuming that you have the tools and project setup.</p>
<p><a href="http://myxaab.files.wordpress.com/2011/03/form-init.png"><img class="aligncenter size-full wp-image-488" title="Simple Form" src="http://myxaab.files.wordpress.com/2011/03/form-init.png?w=600" alt=""   /></a></p>
<p><strong>Step 1.</strong> The model. Here I assumed a single bean will represent the form and data model (for data access/persistence). The attributes in the bean are mapped to the form fields.</p>
<p><pre class="brush: java;">
public class PersonalContact implements Serializable
{
	private static final long serialVersionUID = 1L;
	private Long id;
	private String name;
	private String phone;
	private String email;

	public PersonalContact() {}

	public PersonalContact(Long id, String name, String phone, String email) {
		super();
		this.id = id;
		this.name = name;
		this.phone = phone;
		this.email = email;
	}

	//regenerate the getter &amp; setter using STS.
}
</pre></p>
<p><strong>Step 2.</strong> The controller. Using the default &#8220;HomeController&#8221;, I added 2 methods to handle the load and add request. Both methods have simple implementation to illustrate the interaction between the form and Spring MVC. There is no data access/persistence code implemented here.</p>
<p><pre class="brush: java;">
@Controller
public class HomeController {

	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value=&quot;/&quot;, method=RequestMethod.GET)
	public String home() {
		logger.info(&quot;Welcome home!&quot;);
		return &quot;home&quot;;
	}

	@RequestMapping(value=&quot;/load&quot;, method=RequestMethod.POST)
	public @ResponseBody Map&lt;String, ? extends Object&gt; load(PersonalContact input) {
		logger.info(&quot;Inside load&quot;);
		PersonalContact pc = new PersonalContact(1L, &quot;Wowi&quot;, &quot;89281932&quot;, &quot;wo.wi@abcxyz.com&quot;);
		Map&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();
		data.put(&quot;success&quot;,Boolean.TRUE);
		data.put(&quot;data&quot;, pc);

		return data;
	}

	@RequestMapping(value=&quot;/add&quot;, method=RequestMethod.POST)
	public @ResponseBody Map&lt;String, ? extends Object&gt; add(PersonalContact input, HttpSession session) {
		logger.info(&quot;Inside add&quot;);

		Map&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();

		if (input.getName() == null) {
			data.put(&quot;success&quot;,Boolean.FALSE);
			data.put(&quot;errorMessage&quot;, &quot;No Name?&quot;);
		} else if (session.getAttribute(input.getName()) != null) {
			data.put(&quot;success&quot;,Boolean.FALSE);
			data.put(&quot;errorMessage&quot;, &quot;There is an existing data, unable to add. Please enter a different name&quot;);
		} else {
			session.setAttribute(input.getName(), input);
			data.put(&quot;success&quot;,Boolean.TRUE);
		}

		return data;
	}
}
</pre></p>
<p><strong>Step 3.</strong> The view. Similar to the controller, I built on the default home.jsp. As you can see there isn&#8217;t much code in the JSP. The core UI codes are in the JavaScript (spring-mvc-forms.js). By default the response assumed to be in JSON. Do remember to add the Jackson into the pom.xml and set the header to &#8220;Accept&#8221; application/json.</p>
<p><pre class="brush: xml;">
&lt;%@ taglib uri=&quot;http://java.sun.com/jsp/jstl/core&quot; prefix=&quot;c&quot; %&gt;
&lt;%@ page session=&quot;false&quot; %&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Home&lt;/title&gt;
	&lt;link href=&quot;&lt;c:url value=&quot;/resources/lib/ext-3.3.1/resources/css/ext-all.css&quot; /&gt;&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;&lt;c:url value=&quot;/resources/lib/ext-3.3.1/adapter/ext/ext-base.js&quot; /&gt;&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;&lt;c:url value=&quot;/resources/lib/ext-3.3.1/ext-all.js&quot; /&gt;&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		if (Ext.BLANK_IMAGE_URL.substr(0, 5) != 'data:') {
			Ext.BLANK_IMAGE_URL = '&lt;c:url value=&quot;/resources/lib/ext-3.3.1/resources/images/default/s.gif&quot; /&gt;';
		}
		var loadUrl = '&lt;c:url value=&quot;/load&quot; /&gt;';
		var addUrl = '&lt;c:url value=&quot;/add&quot; /&gt;';
	&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;&lt;c:url value=&quot;/resources/js/spring-mvc-forms.js&quot; /&gt;&quot;&gt;&lt;/script&gt;
	&lt;style type=&quot;text/css&quot;&gt;
		body {
		  	font: normal 12px helvetica,arial,verdana,tahoma,sans-serif;
		}
		.my-form-class {
			margin:  20px 30px;
		}
	&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre></p>
<p><pre class="brush: jscript;">
Ext.onReady(function(){
	Ext.QuickTips.init();

	var mf = new Ext.FormPanel({
			url: addUrl,
			renderTo: Ext.getBody(),
			frame: true,
			cls: 'my-form-class',
			width: 350,
			items: [{
					xtype: 'textfield',
					fieldLabel: 'Name',
					name: 'name'
			},{
					xtype: 'textfield',
					fieldLabel: 'Phone No.',
					name: 'phone'
			},{
					xtype: 'textfield',
					fieldLabel: 'EMail',
					name: 'email'
			}],
			buttons: [{
					id: 'mf.btn.load',
					text: 'Load',
					handler: function() {
						fnLoadForm(mf);
					}
				},{
					id: 'mf.btn.add',
					text: 'Add',
					disabled: true,
					handler: function() {
						fnUpdateForm(mf);
					}
			},{
					id: 'mf.btn.reset',
					text: 'Reset',
					disabled: true,
					handler: function() {
						fnResetForm(mf);
					}
			}]
	});

});

function fnLoadForm(theForm)
{
	//for the purpose of this tutorial, load 1 record.
	theForm.getForm().load({
		url: loadUrl,
		headers: {Accept: 'application/json, text/javascript, */*; q=0.01'},
    waitMsg: 'loading...',
		params : {
			id: 1
		},
		success: function(form, action) {
			Ext.getCmp('mf.btn.add').setDisabled(false);
			Ext.getCmp('mf.btn.reset').setDisabled(false);
			Ext.getCmp('mf.btn.load').setDisabled(true);
		},
		failure: function(form, action) {
			Ext.Msg.alert('Warning', 'Error Unable to Load Form Data.');
		}
	});
} //end fnLoadForm
function fnUpdateForm(theForm)
{
	theForm.getForm().submit({
		success: function(form, action) {
			Ext.Msg.alert('Success', 'Data is stored in session.');
			form.reset();
		},
		failure: function(form, action) {
			Ext.Msg.alert('Warning', action.result.errorMessage);
		}
	});
} //end fnUpdateForm
function fnResetForm(theForm)
{
	theForm.getForm().reset();
	Ext.getCmp('mf.btn.add').setDisabled(true);
	Ext.getCmp('mf.btn.reset').setDisabled(true);
} //end fnResetForm
</pre></p>
<p>Now that all the components are ready, launch the example and to begin with click &#8220;load&#8221; button. The form will be pre-populated with example data. To try the form submission, click &#8220;add&#8221;. Hope you find the tutorial useful. Happy coding! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Update: the source project is downloadable at <a href="https://github.com/wswijaya/spring-mvc-forms" target="_blank">myGit</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myxaab.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myxaab.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myxaab.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myxaab.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/myxaab.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/myxaab.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/myxaab.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/myxaab.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myxaab.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myxaab.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myxaab.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myxaab.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myxaab.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myxaab.wordpress.com/484/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=484&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://myxaab.wordpress.com/2011/03/16/spring-3-mvc-and-extjs-forms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f623b52e3d6e71e1599b86e0c5f512?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">wsw1jaya</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/form-init.png" medium="image">
			<media:title type="html">Simple Form</media:title>
		</media:content>
	</item>
		<item>
		<title>Beginning Spring MVC 3</title>
		<link>http://myxaab.wordpress.com/2011/03/13/beginning-spring-mvc3/</link>
		<comments>http://myxaab.wordpress.com/2011/03/13/beginning-spring-mvc3/#comments</comments>
		<pubDate>Sun, 13 Mar 2011 13:13:45 +0000</pubDate>
		<dc:creator>wowi</dc:creator>
				<category><![CDATA[Spring MVC]]></category>
		<category><![CDATA[SpringSource]]></category>
		<category><![CDATA[Spring MVC 3]]></category>

		<guid isPermaLink="false">http://myxaab.wordpress.com/?p=464</guid>
		<description><![CDATA[It&#8217;s been awhile since I used Spring framework. It has evolved and gotten simpler &#38; easier to work with. This tutorial will walk through how to setup a simple Spring MVC project and to return JSON object to client browser. In this tutorial I will be using SpringSource Tool Suite, its project template helps to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=464&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been awhile since I used Spring framework. It has evolved and gotten simpler &amp; easier to work with. This tutorial will walk through how to setup a simple Spring MVC project and to return JSON object to client browser. In this tutorial I will be using SpringSource Tool Suite, its project template helps to reduce the time to get a Spring MVC project up and running.</p>
<p>In order to start the tutorial, you will need</p>
<ol>
<li><a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html" target="_blank">JDK installed</a>. SpringSource Tool Suite requires full JDK, and</li>
<li><a href="http://www.springsource.com/landing/best-development-tool-enterprise-java" target="_blank">SpringSource Tool Suite</a> (STS). The installer includes the IDE and tc Server Developer Edition.</li>
</ol>
<p>Let&#8217;s start with creating the Spring MVC project in STS.</p>
<p><strong>Step 1</strong>: Create a new project:  File -&gt; New -&gt; Spring Template Project. You will be prompted to download the template, go ahead and download.</p>
<p><a href="http://myxaab.files.wordpress.com/2011/03/step1.png"><img class="aligncenter size-full wp-image-466" title="Step1" src="http://myxaab.files.wordpress.com/2011/03/step1.png?w=600" alt=""   /></a></p>
<p><strong>Step 2</strong>: Define project and top-level package name, then click &#8220;Finish&#8221;</p>
<p><a href="http://myxaab.files.wordpress.com/2011/03/step2.png"><img class="aligncenter size-full wp-image-467" title="step2" src="http://myxaab.files.wordpress.com/2011/03/step2.png?w=600" alt=""   /></a></p>
<p><strong>Step 3</strong>: After the project created you will see the file structure and default controller (HomeController). The dependencies are defined in pom.xml and you will need to add Jackson JSON Processor to complete the tutorial. Without the library you will get HTTP 406 when getting JSON object. Add the following to pom.xml.</p>
<p><pre class="brush: xml;">
&lt;!-- Jackson JSON Processor --&gt;
&lt;dependency&gt;
 &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
 &lt;artifactId&gt;jackson-mapper-asl&lt;/artifactId&gt;
 &lt;version&gt;1.6.4&lt;/version&gt;
&lt;/dependency&gt;
</pre></p>
<p><a href="http://myxaab.files.wordpress.com/2011/03/step3.png"><img class="aligncenter size-full wp-image-469" title="Step3" src="http://myxaab.files.wordpress.com/2011/03/step3.png?w=600" alt=""   /></a><br />
<strong>Step 4</strong>: Deploy the project into SpringSource tc Server. It cannot get easier then this.</p>
<p><a href="http://myxaab.files.wordpress.com/2011/03/step4.png"><img class="aligncenter size-full wp-image-470" title="step4" src="http://myxaab.files.wordpress.com/2011/03/step4.png?w=600" alt=""   /></a></p>
<p><strong>Step 5</strong>: Deploy the project then start the server.</p>
<p><a href="http://myxaab.files.wordpress.com/2011/03/step5.png"><img class="aligncenter size-full wp-image-471" title="step5" src="http://myxaab.files.wordpress.com/2011/03/step5.png?w=600" alt=""   /></a></p>
<p><a href="http://myxaab.files.wordpress.com/2011/03/step6.png"><img class="aligncenter size-full wp-image-472" title="step6" src="http://myxaab.files.wordpress.com/2011/03/step6.png?w=600" alt=""   /></a></p>
<p><a href="http://myxaab.files.wordpress.com/2011/03/step71.png"><img class="aligncenter size-full wp-image-474" title="step7" src="http://myxaab.files.wordpress.com/2011/03/step71.png?w=600" alt=""   /></a><br />
<strong>Step 6</strong>: Once the server is ready. Test you configuration by opening http://localhost:8080/spring-mvc-basic/ in your browser. That is all for the setup, now we move on to add a simple function to get JSON data and to get request information.</p>
<p><a href="http://myxaab.files.wordpress.com/2011/03/step8.png"><img class="aligncenter size-full wp-image-475" title="step8" src="http://myxaab.files.wordpress.com/2011/03/step8.png?w=600" alt=""   /></a></p>
<p><strong>Step 7</strong>: Open HomeController and add 2 methods. The displayRequest() is a simple GET method which take an input parameter &#8220;input&#8221;, servlet request and request header. The content will be passed back to the view, in this case display.jsp. The 2nd method is getJsonData(), a simple method that return JSON object.</p>
<p><pre class="brush: java;">
	@RequestMapping(value=&quot;/display&quot;, method=RequestMethod.GET)
	public String displayRequest(HttpServletRequest request,
		@RequestHeader(value=&quot;Accept&quot;) String accept,
		@RequestHeader(&quot;Accept-Encoding&quot;) String encoding,
		@RequestHeader(&quot;Accept-Charset&quot;) String charset,
                @RequestParam(&quot;input&quot;) String input,
                Model model)  {
	  logger.info(&quot;Calling displayRequest&quot;);
	  model.addAttribute(&quot;RemoteAddress&quot;, request.getRemoteAddr());
	  model.addAttribute(&quot;HeaderAccept&quot;, accept);
	  model.addAttribute(&quot;HeaderAcceptEncoding&quot;, encoding);
	  model.addAttribute(&quot;HeaderAcceptCharset&quot;, charset);
	  model.addAttribute(&quot;Output&quot;, input);
	  return &quot;display&quot;;
	}

	@RequestMapping(value=&quot;/extractJson&quot;, method=RequestMethod.GET)
	public @ResponseBody Map&lt;String,String&gt; getJsonData(@RequestParam(&quot;input&quot;) String input)  {
	  logger.info(&quot;Calling extractJson&quot;);
	  person.put(&quot;name&quot;, &quot;Simba&quot;);
	  person.put(&quot;website&quot;, &quot;http://www.tanbh.net&quot;);
	  person.put(&quot;output&quot;, input);
	  return person;
	}
</pre></p>
<p><strong>Step 8</strong>: Let&#8217;s work on the views now, by adding the link to call the controller &#8220;/display&#8221; and jQuery code to get JSON.</p>
<p><pre class="brush: xml;">
&lt;!-- home.jsp --&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsp/jstl/core&quot; prefix=&quot;c&quot; %&gt;
&lt;%@ page session=&quot;false&quot; %&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Home&lt;/title&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;http://code.jquery.com/jquery-1.5.1.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Hello Spring MVC 3!&lt;/h1&gt;
&lt;a href=&quot;&lt;c:url value=&quot;/display?input=HelloWorldEcho&quot; /&gt;&quot;&gt;Click to Get Request Info&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;div id=&quot;result&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {

	$.getJSON('&lt;c:url value=&quot;extractJson?input=HelloWorldEcho&quot; /&gt;', function(data) {
	    $('#result').append('Result from ajax/json&lt;br/&gt;');
	    $('#result').append('Name: ' + data.name);
	    $('#result').append('&lt;br/&gt;');
	    $('#result').append('Website: ' + data.website);
	    $('#result').append('&lt;br/&gt;');
	    $('#result').append('Input Parameter: ' + data.output);
	});
});
&lt;/script&gt;
</pre></p>
<p><pre class="brush: xml;">
&lt;!-- display.jsp --&gt;
&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot; pageEncoding=&quot;ISO-8859-1&quot;%&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsp/jstl/core&quot; prefix=&quot;c&quot; %&gt;
&lt;%@ page session=&quot;false&quot; %&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
&lt;title&gt;Insert title here&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;strong&gt;&lt;c:out value=&quot;Remote Address: ${RemoteAddress}&quot;&gt;&lt;/c:out&gt;&lt;/strong&gt;&lt;br/&gt;
&lt;strong&gt;&lt;c:out value=&quot;Accept ${HeaderAccept}&quot;&gt;&lt;/c:out&gt;&lt;/strong&gt;&lt;br/&gt;
&lt;strong&gt;&lt;c:out value=&quot;Accept-Encoding: ${HeaderAcceptEncoding}&quot;&gt;&lt;/c:out&gt;&lt;/strong&gt;&lt;br/&gt;
&lt;strong&gt;&lt;c:out value=&quot;Accept-Charset: ${HeaderAcceptCharset}&quot;&gt;&lt;/c:out&gt;&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;
&lt;strong&gt;&lt;c:out value=&quot;Input Parameter: ${Output}&quot;&gt;&lt;/c:out&gt;&lt;/strong&gt;&lt;br/&gt;

&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;a href=&quot;&lt;c:url value=&quot;/&quot; /&gt;&quot;&gt;Home&lt;/a&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre></p>
<p>Now save all the file and sit back and wait for tc Server to reload. Once reloaded, launch trigger http://localhost:8080/spring-mvc-basic/. I also observed, I need to restart the tc Server after compilation error in the controller. Anyway, you should see your result:</p>
<p><a href="http://myxaab.files.wordpress.com/2011/03/step91.png"><img class="aligncenter size-full wp-image-477" title="step9" src="http://myxaab.files.wordpress.com/2011/03/step91.png?w=600" alt=""   /></a></p>
<p>Update: the source is downloadable at <a href="https://github.com/wswijaya/spring-mvc-basic" target="_blank">myGit</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myxaab.wordpress.com/464/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myxaab.wordpress.com/464/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myxaab.wordpress.com/464/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myxaab.wordpress.com/464/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/myxaab.wordpress.com/464/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/myxaab.wordpress.com/464/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/myxaab.wordpress.com/464/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/myxaab.wordpress.com/464/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myxaab.wordpress.com/464/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myxaab.wordpress.com/464/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myxaab.wordpress.com/464/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myxaab.wordpress.com/464/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myxaab.wordpress.com/464/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myxaab.wordpress.com/464/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myxaab.wordpress.com&amp;blog=10525652&amp;post=464&amp;subd=myxaab&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://myxaab.wordpress.com/2011/03/13/beginning-spring-mvc3/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f623b52e3d6e71e1599b86e0c5f512?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">wsw1jaya</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/step1.png" medium="image">
			<media:title type="html">Step1</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/step2.png" medium="image">
			<media:title type="html">step2</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/step3.png" medium="image">
			<media:title type="html">Step3</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/step4.png" medium="image">
			<media:title type="html">step4</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/step5.png" medium="image">
			<media:title type="html">step5</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/step6.png" medium="image">
			<media:title type="html">step6</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/step71.png" medium="image">
			<media:title type="html">step7</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/step8.png" medium="image">
			<media:title type="html">step8</media:title>
		</media:content>

		<media:content url="http://myxaab.files.wordpress.com/2011/03/step91.png" medium="image">
			<media:title type="html">step9</media:title>
		</media:content>
	</item>
	</channel>
</rss>
