<?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/"
	>

<channel>
	<title>maxheapsize.com &#187; Web</title>
	<atom:link href="http://maxheapsize.com/category/web/feed/" rel="self" type="application/rss+xml" />
	<link>http://maxheapsize.com</link>
	<description>Oliver Wehrens on Programming and Agile</description>
	<lastBuildDate>Thu, 29 Jul 2010 10:53:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spring 3 MVC, Ajax and jQuery Magic (or better: simplicity)</title>
		<link>http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/</link>
		<comments>http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 04:00:09 +0000</pubDate>
		<dc:creator>Oliver Wehrens</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[spring 3]]></category>

		<guid isPermaLink="false">http://maxheapsize.com/?p=595</guid>
		<description><![CDATA[
			
				
			
		
I&#8217;m playing around with some web frameworks lately and to see what&#8217;s in store with Spring 3 MVC (never did too much with it) I gave it a try to see how it handles Ajax. According to ajax simplification announcement it should be possible to get up and running in (almost) no time.
We will do [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fmaxheapsize.com%2F2010%2F07%2F20%2Fspring-3-mvc-ajax-and-jquery-magic-or-better-simplicity%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fmaxheapsize.com%2F2010%2F07%2F20%2Fspring-3-mvc-ajax-and-jquery-magic-or-better-simplicity%2F&amp;source=owehrens&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;m playing around with some web frameworks lately and to see what&#8217;s in store with Spring 3 MVC (never did too much with it) I gave it a try to see how it handles Ajax. According to <a href="http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/">ajax simplification announcement</a> it should be possible to get up and running in (almost) no time.</p>
<p>We will do a simple web application which will show the current time via Ajax. </p>
<p>The directory layout (using maven) should look like this:</p>
<div class="wp-caption aligncenter" style="width: 339px"><img alt="Directory Layout" src="http://maxheapsize.com/static/Spring3MVCFiles.png" title="Ajax result" width="329" height="308" /><p class="wp-caption-text">Directory Layout</p></div>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
	xmlns:web=&quot;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
	id=&quot;WebApp_ID&quot; version=&quot;2.5&quot;&gt;
	&lt;display-name&gt;Spring3MVC&lt;/display-name&gt;
	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;

	&lt;servlet&gt;
		&lt;servlet-name&gt;spring&lt;/servlet-name&gt;
		&lt;servlet-class&gt;
			org.springframework.web.servlet.DispatcherServlet
		&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;spring&lt;/servlet-name&gt;
		&lt;url-pattern&gt;*.html&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
&lt;/web-app&gt;
</pre>
<p>The web.xml holds no secrets. The Dispatcher servlet is defined and it should react on everything *.html.</p>
<p>Since we named our Servlet &#8217;spring&#8217; we need to add a servlet configuration for that. It goes in WEB-INF as well.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
	xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context-3.0.xsd&quot;&gt;

	&lt;context:component-scan base-package=&quot;com.maxheapsize.springmvc3.controller&quot; /&gt;

	&lt;bean id=&quot;viewResolver&quot;
		class=&quot;org.springframework.web.servlet.view.UrlBasedViewResolver&quot;&gt;
		&lt;property name=&quot;viewClass&quot; value=&quot;org.springframework.web.servlet.view.JstlView&quot; /&gt;
		&lt;property name=&quot;prefix&quot; value=&quot;/WEB-INF/jsp/&quot; /&gt;
		&lt;property name=&quot;suffix&quot; value=&quot;.jsp&quot; /&gt;
	&lt;/bean&gt;
&lt;/beans&gt;
</pre>
<p>It uses the component scanning feature of spring and instructs spring to check the package &#8216;com.maxheapsize.springmvc3.controller&#8217; for controllers. Furthermore a url based view resolver is defined which uses Jstl and looks into /WEB-INF/jsp for jsp with the ending &#8216;.jsp&#8217;. </p>
<p>In  WEB-INF/jsp/hello.jsp we define a jQuery snippet for the Ajax request and provide a button which we should push if we want to know the time.</p>
<pre class="brush: xml;">
&lt;jsp:useBean id=&quot;message&quot; scope=&quot;request&quot; type=&quot;java.lang.String&quot;/&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;Spring MVC Ajax Demo&lt;/title&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;scripts/jquery.js&quot;&gt;&lt;/script&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
    function doAjax() {
      $.ajax({
        url: 'time.html',
        data: ({name : &quot;me&quot;}),
        success: function(data) {
          $('#time').html(data);
        }
      });
    }
  &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
${message}
&lt;button id=&quot;demo&quot; onclick=&quot;doAjax()&quot; title=&quot;Button&quot;&gt;Get the time!&lt;/button&gt;
&lt;div id=&quot;time&quot;&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>How does Spring now know which classes or methods to call? Here comes the nice part about it.</p>
<pre class="brush: java;">
package com.maxheapsize.springmvc3.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.Date;

@Controller
public class HelloWorldController {

  @RequestMapping(&quot;/hello&quot;)
  public ModelAndView helloWorld() {
    return new ModelAndView(&quot;hello&quot;, &quot;message&quot;, &quot;Spring MVC Demo&quot;);
  }

  @RequestMapping(value = &quot;/time&quot;, method = RequestMethod.GET)
  public @ResponseBody String getTime(@RequestParam String name) {
    String result = &quot;Time for &quot; + name + &quot; is &quot; + new Date().toString();
    return result;
  }
}
</pre>
<p>The RequestMappings define the Url&#8217;s which can be called to reach that code. So the helloWorld method is available with &#8216;hello.html&#8217; in the web app. Why hello.html and not just hello ? Because we said so in the web.xml. I included a sample message which will be shown at the web  page when this method is called.</p>
<p> If you now push the button on the webpage, &#8216;time.html&#8217; with a parameter &#8216;name&#8217; is called. This will go directly to the second method. Spring will also check if a string parameter &#8216;name&#8217; (@RequestParam) is present in the original request. The @ResponseBody annotation  indicates that a method return value should be bound to the web response body.</p>
<p>The result will be returned and shown in the webpage.</p>
<div class="wp-caption aligncenter" style="width: 564px"><img alt="Ajax Result" src="http://maxheapsize.com/static/Spring3MVCAjax.png" title="Ajax result" width="554" height="83" /><p class="wp-caption-text">Ajax Result</p></div>
<p>Overall this is a pretty nice integration. I tend to use Spring for many projects and this makes it even easier to write some nice web apps in it. If you have a single page application and all you do is sending ajax request back and forth this might be a solution. </p>
<p><strong>JSON response Update</strong></p>
<p>To get a JSON response from your Controller you need to:</p>
<ol>
<li>Make sure the jackson mapper is present in your classpath. Maven users use:
<pre class="brush: xml;">
    &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.5.3&lt;/version&gt;
    &lt;/dependency&gt;
</pre>
<p>in their pom.xml.
</li>
<li>MySimpleDataObject is a Pojo</li>
<li>The method you are calling has a signature like:
<pre class="brush: java;">
@RequestMapping(value = &quot;/demo&quot;, method= RequestMethod.GET)
public @ResponseBody MySimpleDataObject doSomething(@RequestParam name, @RequestParam email)
</pre>
</li>
<li>You are returning MySimpleDataObject at the end</li>
<li>Your calling javascript looks like this:
<pre class="brush: jscript;">
jQuery.getJSON(&quot;demo.html&quot;, {name: name, email: email}, function (data) {
        alert(data.someValueInMySimpleDataObject);
      });
</pre>
</li>
</ol>
<p>See also <a href="http://rwehner.wordpress.com/2010/06/09/2-ways-to-create-json-response-for-ajax-request-in-spring3/">Ralf&#8217;s post about Json and Spring MVC</a>. </p>
<img src="http://maxheapsize.com/?ak_action=api_record_view&id=595&type=feed" alt="" /><!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/&amp;title=Spring+3+MVC%2C+Ajax+and+jQuery+Magic+%28or+better%3A+simplicity%29" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/&amp;title=Spring+3+MVC%2C+Ajax+and+jQuery+Magic+%28or+better%3A+simplicity%29" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Spring+3+MVC%2C+Ajax+and+jQuery+Magic+%28or+better%3A+simplicity%29&amp;url=http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/&amp;title=Spring+3+MVC%2C+Ajax+and+jQuery+Magic+%28or+better%3A+simplicity%29" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/&amp;title=Spring+3+MVC%2C+Ajax+and+jQuery+Magic+%28or+better%3A+simplicity%29" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/&amp;bm_description=Spring+3+MVC%2C+Ajax+and+jQuery+Magic+%28or+better%3A+simplicity%29" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/&amp;title=Spring+3+MVC%2C+Ajax+and+jQuery+Magic+%28or+better%3A+simplicity%29" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/&amp;title=Spring+3+MVC%2C+Ajax+and+jQuery+Magic+%28or+better%3A+simplicity%29" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.sphere.com/sphereit/http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/" rel="nofollow" title="Add to&nbsp;SphereIt"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/sphereit.png" title="Add to&nbsp;SphereIt" alt="Add to&nbsp;SphereIt" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.spurl.net/spurl.php?url=http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/&amp;title=Spring+3+MVC%2C+Ajax+and+jQuery+Magic+%28or+better%3A+simplicity%29" rel="nofollow" title="Add to&nbsp;Spurl"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/spurl.png" title="Add to&nbsp;Spurl" alt="Add to&nbsp;Spurl" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Spring+3+MVC%2C+Ajax+and+jQuery+Magic+%28or+better%3A+simplicity%29+@+http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to detect if your server is down when making jQuery Ajax calls</title>
		<link>http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/</link>
		<comments>http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 19:19:33 +0000</pubDate>
		<dc:creator>Oliver Wehrens</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://maxheapsize.com/?p=546</guid>
		<description><![CDATA[
			
				
			
		
If you developed an ajax rich web application, maybe even a single page interface, you want to make sure that the user gets notified if the server is not reachable anymore. This happens either if the it goes down or the client loses its network connection.
Depending on your code the application can run for a [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fmaxheapsize.com%2F2010%2F04%2F26%2Fhow-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fmaxheapsize.com%2F2010%2F04%2F26%2Fhow-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls%2F&amp;source=owehrens&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>If you developed an <strong>ajax rich web application</strong>, maybe even a single page interface, you want to make sure that the user gets <strong>notified</strong> if the server is <strong>not reachable</strong> anymore. This happens either if the it goes down or the client loses its network connection.<br />
Depending on your code the application can run for a while and the <strong>user is confused</strong> about missing interactivity.</p>
<p>So how do you detect this? jQuery offers an error callback if something with the call goes wrong. </p>
<pre class="brush: jscript;">
window.setInterval(function() {
$.ajax({
   type: 'GET',
   url: 'http://www.myapp.com/heartbeat',
   success: function(data, textStatus, XMLHttpRequest) {},
   error: function(XMLHttpRequest, textStatus, errorThrown) {
      alert('Failure');
    }
  });
}, 2000);
</pre>
<p>Unfortunately this does not work for a server which is down and if you are using a debugger like Firebug you will see that these calls have the status aborted. It turns out that if the <strong>server goes away</strong> jQuery will still execute the <strong>success callback</strong>. So how do you know that the server died?</p>
<p>I changed the response of the <strong>heartbeat</strong> query to contain some simple string like &#8216;alive&#8217;.  In the success callback I just check if the data contains this string. If it does not, I know that I do have a problem and I need to make sure that the user can&#8217;t do anything anymore.</p>
<p>I use the <a href='http://jquery.malsup.com/block/'>jQuery plugin uiBlock</a> to block every interaction and show a nice little message. Check out the <a href="http://jquery.malsup.com/block/#demos">uiBlock demos</a>.</p>
<pre class="brush: jscript;">
var uiBlocked = false;

window.setInterval(function() {
    $.ajax({
      cache: false,
      type: 'GET',
      url: '/mywebapp/alive.txt',
      timeout: 1000,
      success: function(data, textStatus, XMLHttpRequest) {
        if (data != 'alive') {
          if (uiBlocked == false) {
            uiBlocked = true;
            $.blockUI({
              message: &quot;I'm trying to connect to the server.&quot;,
              css: {
                border: 'none',
                padding: '15px',
                backgroundColor: '#000',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                opacity: .5,
                color: '#fff'
              } });
          }
        } else {
          if (uiBlocked == true) {
            uiBlocked = false;
            $.unblockUI();
          }
        }
      }
    })

  }, 2000);
</pre>
<p>This code will check the server every 2 seconds and will<strong> block the UI</strong> when the server is not reachable and will <strong>come back up</strong> if the connection is <strong>alive</strong> again. Depending on your scenario (intranet/internet) you can change the interval for checking the connection.</p>
<p>This took me a couple of hours to get to this point and I thought it might be worth sharing. It seems a bit hacky but it works. What do you think?</p>
<img src="http://maxheapsize.com/?ak_action=api_record_view&id=546&type=feed" alt="" /><!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/&amp;title=How+to+detect+if+your+server+is+down+when+making+jQuery+Ajax+calls" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/&amp;title=How+to+detect+if+your+server+is+down+when+making+jQuery+Ajax+calls" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=How+to+detect+if+your+server+is+down+when+making+jQuery+Ajax+calls&amp;url=http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/&amp;title=How+to+detect+if+your+server+is+down+when+making+jQuery+Ajax+calls" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/&amp;title=How+to+detect+if+your+server+is+down+when+making+jQuery+Ajax+calls" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/&amp;bm_description=How+to+detect+if+your+server+is+down+when+making+jQuery+Ajax+calls" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/&amp;title=How+to+detect+if+your+server+is+down+when+making+jQuery+Ajax+calls" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/&amp;title=How+to+detect+if+your+server+is+down+when+making+jQuery+Ajax+calls" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.sphere.com/sphereit/http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/" rel="nofollow" title="Add to&nbsp;SphereIt"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/sphereit.png" title="Add to&nbsp;SphereIt" alt="Add to&nbsp;SphereIt" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.spurl.net/spurl.php?url=http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/&amp;title=How+to+detect+if+your+server+is+down+when+making+jQuery+Ajax+calls" rel="nofollow" title="Add to&nbsp;Spurl"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/spurl.png" title="Add to&nbsp;Spurl" alt="Add to&nbsp;Spurl" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+How+to+detect+if+your+server+is+down+when+making+jQuery+Ajax+calls+@+http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://maxheapsize.com/2010/04/26/how-to-detect-if-your-server-is-down-when-making-jquery-ajax-calls/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lightweight Web Prototyping for the Framework loving (Java) Developer</title>
		<link>http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/</link>
		<comments>http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 13:00:53 +0000</pubDate>
		<dc:creator>Oliver Wehrens</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://maxheapsize.com/?p=532</guid>
		<description><![CDATA[
			
				
			
		
A couple of month ago I had an idea for a small web app. But what does it take to do it ? Do you start with the back end or the front end (read server or client side) ? Typically I would start at the back end, get the domain right and then see [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fmaxheapsize.com%2F2010%2F04%2F20%2Flightweight-web-prototyping-for-the-framework-loving-java-developer%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fmaxheapsize.com%2F2010%2F04%2F20%2Flightweight-web-prototyping-for-the-framework-loving-java-developer%2F&amp;source=owehrens&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.flickr.com/photos/istylr/3777635804/sizes/s/"><img class="alignleft" src="http://farm3.static.flickr.com/2562/3777635804_babcd16f90_m.jpg" title="© iStylr @ flickr"  /></a>A couple of month ago I had an idea for a small web app. But what does it take to do it ? Do you start with the back end or the front end (read server or client side) ? Typically I would start at the back end, get the domain right and then see how I can fit the UI in. If a programmer starts this way you end with the typical &#8216;the programmer did the GUI&#8217; scenario. That&#8217;s not really what I wanted. Don&#8217;t think too much about the domain, just see what the needs of the end user are and get the UI done (right). </p>
<h3>Trying frameworks &#8230;</h3>
<p>But there you go, being a framework loving web developer, how do you do the UI, or better, in what technology? Among other I tried  <a href="https://javaserverfaces.dev.java.net/">JSF 2</a> and I thought it&#8217;s cool. After a couple of hours I realized that this will slow me down. Fiddling with different ideas and concepts I just could not do that with JSF right away. I would have to write my own components. This is supposed to be very easy but still too much waste when I&#8217;m not sure if I even will use this.</p>
<h3> Trying paper&#8230; </h3>
<p>Next I started very basic and did some drawings. While this is all nice (I did it on my white board, I strongly recommend to do this on something you can erase) it turns out I had no idea on how to realize that in Html. I knew this must be possible somehow today but I had no idea what does it take to implement things like drag and drop, box scrolling, reordering and more. Nice thing I build on <a href="http://www.raincreativelab.com/paperbrowser/">paper</a>&#8230;but can I do it ?</p>
<h3>The solution</h3>
<p>What if I now combine those two approaches ? I needed some lightweight web framework, easy to learn (maybe one I already know) with  quick turn around. After looking around for a couple of hours I came up with <a href="http://www.w3.org/TR/html5/">Html</a> and <a href="http://jquery.com/">jQuery</a>. </p>
<p>I have some knowledge in Html and Css but I never did anything in Javascript or jQuery. So there is something new to learn. Since this was on my agenda anyway and I already bought Mannings <a href="http://www.manning.com/bibeault/">jQuery in Action</a> book in December I went this route. I hoped that adding jQuery into the page would give me some interactivity to the otherwise static Html page.</p>
<p> It turns out, it was the best choice. I came up with at least three completely different designs in a matter of evenings, got them to a working stage and could &#8216;feel&#8217; how they would work (or not). After experiencing this I decided to do some substantial changes to the UI. Dragging and dropping is all nice and dandy, but it&#8217;s too much clicking and dragging for the app. On paper this really looked cool but in practice it was not. </p>
<p>It&#8217;s amazing what you can do with jQuery. You can save state on elements using Html 5 attribute, can load other Html snippets as Ajax responses and use a dozen jQuery plugins for menus, zooming, dragging and so on. Not to mention the power of jQuery itself. You can append action, animations or anything to any element. Without programming one line server side I got a fully working prototype running including adding and removing items, saving, loading and dynamic generated forms.</p>
<p>Some more iterations later (still not 100% happy) I started to implement it for real. Since I wanted to stay with that design (and very much Ajax oriented) I went the route of <a href="http://directwebremoting.org/dwr/index.html">Direct Web Remoting</a> and <a href="http://freemarker.sourceforge.net/">Freemarker</a>. Freemarker will render my templates and DWR talks to my Spring beans. Whenever I needed to design another page I first did the standalone Html version, got it to a working state and then integrated it in the app.</p>
<h3>Conclusion</h3>
<p>Even if I would not have decided to use jQuery and pure Html for the final implementation (totally depends on the use case) I would strongly consider going the same route for doing the prototype again. It was so easy and the feedback was right there. I could throw away not working ideas  and make new ones very easily. There was a learning curve using jQuery (and I needed to refresh my CSS) but it was time well invested.</p>
<p>How do you your prototypes? Fully integrated with your existing frameworks or on paper? </p>
<img src="http://maxheapsize.com/?ak_action=api_record_view&id=532&type=feed" alt="" /><!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/&amp;title=Lightweight+Web+Prototyping+for+the+Framework+loving+%28Java%29+Developer" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/&amp;title=Lightweight+Web+Prototyping+for+the+Framework+loving+%28Java%29+Developer" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Lightweight+Web+Prototyping+for+the+Framework+loving+%28Java%29+Developer&amp;url=http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/&amp;title=Lightweight+Web+Prototyping+for+the+Framework+loving+%28Java%29+Developer" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/&amp;title=Lightweight+Web+Prototyping+for+the+Framework+loving+%28Java%29+Developer" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/&amp;bm_description=Lightweight+Web+Prototyping+for+the+Framework+loving+%28Java%29+Developer" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/&amp;title=Lightweight+Web+Prototyping+for+the+Framework+loving+%28Java%29+Developer" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/&amp;title=Lightweight+Web+Prototyping+for+the+Framework+loving+%28Java%29+Developer" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.sphere.com/sphereit/http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/" rel="nofollow" title="Add to&nbsp;SphereIt"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/sphereit.png" title="Add to&nbsp;SphereIt" alt="Add to&nbsp;SphereIt" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.spurl.net/spurl.php?url=http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/&amp;title=Lightweight+Web+Prototyping+for+the+Framework+loving+%28Java%29+Developer" rel="nofollow" title="Add to&nbsp;Spurl"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/spurl.png" title="Add to&nbsp;Spurl" alt="Add to&nbsp;Spurl" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Lightweight+Web+Prototyping+for+the+Framework+loving+%28Java%29+Developer+@+http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://maxheapsize.com/2010/04/20/lightweight-web-prototyping-for-the-framework-loving-java-developer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Selenium2 for web testing (and not Selenium IDE)</title>
		<link>http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/</link>
		<comments>http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 05:38:15 +0000</pubDate>
		<dc:creator>Oliver Wehrens</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[selenium ide]]></category>
		<category><![CDATA[selenium2]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[webdriver]]></category>

		<guid isPermaLink="false">http://maxheapsize.com/?p=393</guid>
		<description><![CDATA[
			
				
			
		
Selenium IDE
Selenium is well know for automatic testing web pages. It does support many browsers, operating systems and languages. A Selenium IDE exists to aid you creating automated tests. 
It is possible to write extensions in JavaScript to have data driven tests. If you organize your selenium tests in a way that you split  [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fmaxheapsize.com%2F2010%2F01%2F04%2Fusing-selenium-2-for-web-testing%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fmaxheapsize.com%2F2010%2F01%2F04%2Fusing-selenium-2-for-web-testing%2F&amp;source=owehrens&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<h3>Selenium IDE</h3>
<p><a href="http://seleniumhq.org">Selenium</a> is well know for automatic testing web pages. It does support many <a href="http://seleniumhq.org/about/platforms.htm">browsers, operating systems and languages<a/>. A <a href="http://seleniumhq.org/projects/ide/">Selenium IDE</a> exists to aid you creating automated tests. </p>
<div class="wp-caption alignleft" style="width: 313px"><img alt="Selenium" src="http://maxheapsize.com/static/selenium.png" title="Selenium IDE" width="303" height="177" /><p class="wp-caption-text">Selenium IDE</p></div>
<p>It is possible to write extensions in JavaScript to have data driven tests. If you organize your selenium tests in a way that you split  the pages and forms in components, you can  load up new data for the tests (written in xml) to fill out forms differently for each use case. The Selenium IDE will be of a great help here since you start develop the tests in the IDE and later &#8216;just&#8217; parametrize the pages. With a couple of more javascript magic you can run these as well in <a href="http://seleniumhq.org/projects/remote-control/">Selenium Remote Control</a> (Selenium RC for short). This even works for running  the tests in continuous integration systems like Hudson or Teamcity.</p>
<p>Great Stuff.</p>
<h3>The problem.</h3>
<p>The drawback coding up your tests with the Selenium IDE is: <b>HTML</b>.  </p>
<p>You will end up with some test suites including many test scenarios. It will be one big ball of </p>
<pre class="brush: xml;">
&lt;tr&gt;
  &lt;td&gt;type&lt;/td&gt;
  &lt;td&gt;accountnumber:Value&lt;/td&gt;
  &lt;td&gt;82892892811&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;type&lt;/td&gt;
  &lt;td&gt;accountAmount:Value&lt;/td&gt;
  &lt;td&gt;2345.33&lt;/td&gt;
&lt;/tr&gt;
</pre>
<p>You will build components and you will end up with GotoIf and Label statements. Back to Basic programming from the 80ties. Without more javascript extensions you also can&#8217;t reuse combinations of scenarios. </p>
<p>While this works pretty ok: I&#8217;m a programmer and do have a <strong>problem</strong> with the <strong>quality of the produced code</strong>. It&#8217;s <strong>easy to mess up</strong>. It&#8217;s <strong>not safe for refactoring</strong>. To extend functionality you need to have javascript knowledge. Depending on your company profile (e.g. java shop) , this might be a problem.  Having a dedicated tester on the team certainly helps to overcome these obstacles, but if everybody in the team just once in a while looks into the Selenium IDE tests, the quality and the reliability of the code will not improve. Not to mention all the <strong>copy and paste</strong>. Been there, done that.</p>
<h3>Selenium 2</h3>
<p>A much nicer approach for me would be something like this:</p>
<pre class="brush: java;">
WebDriver driver  = new FirefoxDriver();
AppWebTest test = new AppWebTest(driver, &quot;http://myapp.com/login&quot;);
LoggedInUser user = test.login(&quot;user&quot;, &quot;password&quot;);
Account account = user.createNewAccount(&quot;DemoAccount&quot;);
account.addPerson(PersonFactory.createPersonWithNoIncome());
...
account.verify();
</pre>
<p>This would log in a user, creates an account and assigns a person to it. Everybody could <strong>read and understand</strong> it. Furthermore you can easily reuse components and logic. I would imagine that creating a DSL, matchers and finders is everything one would need to have a very nice test scenario.</p>
<p>All that is already possible with Selenium 1 and the language bindings (more or less). </p>
<p>Just with the release of the first alpha of Selenium 2 mid december 2009 it became just a little bit easier.</p>
<p>Selenium 2 is the <strong>combined effort</strong> of Google&#8217;s Webdriver and Selenium. Webdriver tries to <a href="http://google-opensource.blogspot.com/2009/05/introducing-webdriver.html">tackle</a> Seleniums problems with Javascript and the security model as well as the complex Selenium RC API. </p>
<blockquote><p>
Selenium is written in JavaScript which causes a significant weakness: browsers impose a pretty strict security model on any JavaScript that they execute in order to protect a user from malicious scripts.<br />
&#8230;<br />
Additionally, being a mature product, the API for Selenium RC has grown over time, and as it has done so it has become harder to understand how best to use it. For example, it&#8217;s not immediately obvious whether you should be using &#8220;type&#8221; instead of &#8220;typeKeys&#8221; to enter text into a form control. Although it&#8217;s a question of aesthetics, some find the large API intimidating and difficult to navigate.
</p></blockquote>
<p>Webdriver does not use JavaScript to control the web browser but <strong>uses native controls</strong>, e.g. an extension for Firefox or the native automation extensions of IE. Furthermore it introduces an object based API instead of following Seleniums directory based approach.</p>
<p>So given the above example the login method would look something like this:</p>
<pre class="brush: java;">
 public LoggedInUser login(String userName, String password) {
    driver.get(url);
    driver.findElement(By.id(&quot;user&quot;)).sendKeys(userName);
    driver.findElement(By.id(&quot;password&quot;)).sendKeys(password);
    driver.findElement(By.id(&quot;login&quot;)).click();

    LoggedInUser user = new LoggedInUser(driver);

    WebElement startPage = driver.findElement(By.id(&quot;startPage&quot;));

    assertThat(startPage().getText()).isEqualTo(&quot;Start&quot;);
    return user;
  }
</pre>
<p>You can take this to any level. It took me just a few hours to model the above use case with componentized input elements. </p>
<p>With a bit more abstraction addPerson looks something like the following code. Whatever is needed to add a person to an account will be replayed. This is what Selenium IDE would normally do.</p>
<pre class="brush: java;">
public void addPerson(Person person) {
    jumpToAccountOverView();
    clickOnLink(&quot;menu:Overview&quot;);
    clickOnLink(&quot;table_personTable:link_newPerson&quot;);

    inputGuiElement(person.getTitle());
    inputGuiElement(person.getLastName());
...
    clickSave();
</pre>
<p>And now for the best part. You <strong>don&#8217;t really need a real web browser</strong>. Selenium 2 supports 4 WebDriver: </p>
<ul>
<li>Firefox</li>
<li>Chrome</li>
<li>Internet Explorer (on Windows)</li>
<li>HtmlUnit</li>
</ul>
<h3>HtmlUnit</h3>
<p>With enabled JavaScript on HtmlUnit (it uses Rhino, so not all JavaScript tricks might work, could be a drawback depending on your scenario) I can run my test as <strong>TestNG or JUnit</strong> test case. No need for a Selenium RC anymore. <strong>No  browsers running locally</strong> or on remote machine listing to ports to execute tests and transmitting results back. </p>
<p>It is very useful to have the Selenium RC take screen shots during it&#8217;s run. Selenium 2 can&#8217;t do this right now (and with HtmlUnit never can). But by simply integrating some logging in the components and elements and you know right away where things went wrong.<br />
Developing with the <strong>Selenium IDE</strong> might seem like a must, but during the work on my prototype all I needed was Firebug and a XPath Searcher. I <strong>did not miss it</strong> at all. To do integration tests you could test all components independently and one at a time. Once these work, chain them together and let them run as unit tests. Did I mention <strong>HtmlUnit is fast</strong> ? </p>
<h3>Conclusion</h3>
<p>I barely dug into the webdriver code, I played around with it for a couple of hours and I&#8217;m sure there more is stuff (and bugs) to find. Given that Selenium 2 is in alpha 1 stage right now I expect very nice things coming out of it. It certainly looks like the way to go. </p>
<p>Another strong contender is <a href="http://webtest.canoo.com/webtest/manual/WebTestHome.html">Canoo WebTest</a>. I will have a look at this one in another post.</p>
<p><strong>Update Ajax and HtmlUnit</strong> 1/5/2010 </p>
<p>It does not seem to work. You need a real browser to get dynamically content re-rendered through Ajax. </p>
<p>A method waiting for an id to be rendered (or timeout after x seconds) could look like this:</p>
<pre class="brush: java;">
  public void waitForElementOrTimeout(String idToWaitFor, int timeout) {
    long end = System.currentTimeMillis() + timeout * 1000;
    RenderedWebElement resultsDiv = null;
    while (System.currentTimeMillis() &lt; end) {
      try {
        resultsDiv = (RenderedWebElement) driver.findElement(By.id(idToWaitFor));
      }
      catch (NoSuchElementException e) {
        //
      }
      if (resultsDiv != null &amp;&amp; resultsDiv.isDisplayed()) {
        break;
      }
    }
    assertThat(resultsDiv).isNotNull();
  }
</pre>
<p>This will either find the element specified or throw an assertion (updated example from the selenium 2 page).</p>
<img src="http://maxheapsize.com/?ak_action=api_record_view&id=393&type=feed" alt="" /><!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/&amp;title=Using+Selenium2+for+web+testing+%28and+not+Selenium+IDE%29" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/&amp;title=Using+Selenium2+for+web+testing+%28and+not+Selenium+IDE%29" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Using+Selenium2+for+web+testing+%28and+not+Selenium+IDE%29&amp;url=http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/&amp;title=Using+Selenium2+for+web+testing+%28and+not+Selenium+IDE%29" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/&amp;title=Using+Selenium2+for+web+testing+%28and+not+Selenium+IDE%29" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/&amp;bm_description=Using+Selenium2+for+web+testing+%28and+not+Selenium+IDE%29" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/&amp;title=Using+Selenium2+for+web+testing+%28and+not+Selenium+IDE%29" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/&amp;title=Using+Selenium2+for+web+testing+%28and+not+Selenium+IDE%29" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.sphere.com/sphereit/http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/" rel="nofollow" title="Add to&nbsp;SphereIt"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/sphereit.png" title="Add to&nbsp;SphereIt" alt="Add to&nbsp;SphereIt" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.spurl.net/spurl.php?url=http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/&amp;title=Using+Selenium2+for+web+testing+%28and+not+Selenium+IDE%29" rel="nofollow" title="Add to&nbsp;Spurl"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/spurl.png" title="Add to&nbsp;Spurl" alt="Add to&nbsp;Spurl" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Using+Selenium2+for+web+testing+%28and+not+Selenium+IDE%29+@+http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://maxheapsize.com/2010/01/04/using-selenium-2-for-web-testing/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Getting started with JSF 2 (and Maven)</title>
		<link>http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/</link>
		<comments>http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 21:21:39 +0000</pubDate>
		<dc:creator>Oliver Wehrens</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[jsf2]]></category>

		<guid isPermaLink="false">http://maxheapsize.com/?p=270</guid>
		<description><![CDATA[
			
				
			
		
I use Apache Trinidad at work and since JSF 2 is now final I decided to play with it a bit.
Of course this is going to be the classic Hello World example (as there are many other like this around the web).
First you need to setup a simple Maven project. 
The file layout should be [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fmaxheapsize.com%2F2009%2F07%2F03%2Fgetting-started-with-jsf-2-and-maven%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fmaxheapsize.com%2F2009%2F07%2F03%2Fgetting-started-with-jsf-2-and-maven%2F&amp;source=owehrens&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I use Apache Trinidad at work and since JSF 2 is now final I decided to play with it a bit.</p>
<p>Of course this is going to be the classic Hello World example (as there are many other like this around the web).</p>
<p>First you need to setup a simple Maven project. </p>
<p>The file layout should be something like that.</p>
<div class="wp-caption alignnone" style="width: 300px"><img alt="Directory Layout for JSF 2 Ajax Demo" src="http://maxheapsize.com/static/JSF2AjaxDemoFileLayout.png" title="Directory Layout for JSF 2 Ajax Demo" width="290" height="234" /><p class="wp-caption-text">Directory Layout for JSF 2 Ajax Demo</p></div>
<p>After that change your pom.xml to include the servlet and jsf2 libs.</p>
<pre class="brush: xml;">
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.maxheapsize&lt;/groupId&gt;
  &lt;artifactId&gt;jsf2demo&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;jsf2demo Maven Webapp&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
      &lt;artifactId&gt;jsf-api&lt;/artifactId&gt;
      &lt;version&gt;2.0.0-b13&lt;/version&gt;
      &lt;scope&gt;compile&lt;/scope&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
      &lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
      &lt;artifactId&gt;jsf-impl&lt;/artifactId&gt;
      &lt;version&gt;2.0.0-b13&lt;/version&gt;
      &lt;scope&gt;compile&lt;/scope&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
      &lt;artifactId&gt;jstl&lt;/artifactId&gt;
      &lt;version&gt;1.2&lt;/version&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
      &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
      &lt;version&gt;2.5&lt;/version&gt;
    &lt;/dependency&gt;

  &lt;/dependencies&gt;
  &lt;build&gt;
    &lt;finalName&gt;jsf2demo&lt;/finalName&gt;
  &lt;/build&gt;

  &lt;repositories&gt;
    &lt;repository&gt;
      &lt;id&gt;maven2-repository.dev.java.net&lt;/id&gt;
      &lt;name&gt;Java.net Repository for Maven&lt;/name&gt;
      &lt;url&gt;http://download.java.net/maven/2&lt;/url&gt;
    &lt;/repository&gt;
  &lt;/repositories&gt;

&lt;/project&gt;
</pre>
<p>First we are going to create the managed bean to hold the name we are going to enter.</p>
<pre class="brush: java;">
package com.maxheapsize.jsf2demo;

import javax.faces.bean.*;
import java.io.Serializable;

@ManagedBean
@SessionScoped
public class HelloWorldBean implements Serializable {

  private String name = &quot;&quot;;

  @ManagedProperty(value = &quot;#{demoService}&quot;)
  private Service service;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public void setService(Service service) {
    this.service = service;
  }

  public String getReverseName() {
    return service.reverse(name);
  }
}
</pre>
<p>To demonstrate the dependency injection with JSF 2 I use a service to reverse the name. Simply add the @ManagedProperty with the name of the service and it will get injected. Of course we need the service. Here it is:</p>
<pre class="brush: java;">
package com.maxheapsize.jsf2demo;

import javax.faces.bean.*;

@ManagedBean(name=&quot;demoService&quot;)
@ApplicationScoped
public class Service {

  public String reverse(String name) {
    return new StringBuffer(name).reverse().toString().toLowerCase();
  }
}
</pre>
<p>Very simple&#8230;isn&#8217;t it ?</p>
<p>The only thing what&#8217;s missing is the web.xml and the webpage itself.</p>
<p>The web.xml is pretty straight forward and should not show any surprises.</p>
<pre class="brush: xml;">
&lt;!DOCTYPE web-app PUBLIC
    &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;
    &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot; &gt;
&lt;web-app&gt;
  &lt;display-name&gt;Web Application&lt;/display-name&gt;

  &lt;servlet&gt;
    &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
    &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;

  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;

  &lt;context-param&gt;
    &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
    &lt;param-value&gt;Development&lt;/param-value&gt;
  &lt;/context-param&gt;
&lt;/web-app&gt;
</pre>
<p>The index.xhtml has some differences from earlier versions of JSF. First, JSF now supports Ajax out of the box. To have this enabled you need to load the jsf.js javascript library. The inputText tag binds to our managed bean and includes an f:ajax tag. This tag determines which part should be rerendered (in this case the element with the id reverseName). F:ajax will execute on value holding components always with an &#8216;onchange&#8217; event and on action components (like commandButtons) with an &#8216;onclick&#8217; event.<br />
The output will trigger the injected service in our managed bean and return the reversed input string.</p>
<pre class="brush: xml;">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
        &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
      xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
      xmlns:f=&quot;http://java.sun.com/jsf/core&quot;
      xmlns:h=&quot;http://java.sun.com/jsf/html&quot;&gt;

&lt;h:head&gt;
  &lt;title&gt;JSF Demo&lt;/title&gt;
&lt;/h:head&gt;
&lt;h:body&gt;
  &lt;h:outputScript name=&quot;jsf.js&quot; library=&quot;javax.faces&quot; target=&quot;body&quot;&gt;
&lt;/h:outputScript&gt;
  &lt;h1&gt;Ajax JSF 2 Demo&lt;/h1&gt;
  &lt;h:form&gt;

    &lt;h:inputText id=&quot;name&quot; value=&quot;#{helloWorldBean.name}&quot;&gt;
      &lt;f:ajax render=&quot;reverseName&quot;/&gt;
    &lt;/h:inputText&gt;

    &lt;h:commandButton value=&quot;Say reverse Hi via Ajax&quot;&gt;
      &lt;f:ajax execute=&quot;name&quot; render=&quot;reverseName&quot;/&gt;
    &lt;/h:commandButton&gt;
    &lt;h:outputText id=&quot;reverseName&quot; value=&quot;#{helloWorldBean.reverseName}&quot;/&gt;
  &lt;/h:form&gt;

&lt;/h:body&gt;
&lt;/html&gt;
</pre>
<div class="wp-caption alignnone" style="width: 406px"><img alt="JSF 2 Ajax Demo" src="http://maxheapsize.com/static/JSF2AjaxDemo.png" title="JSF 2 Ajax Demo" width="396" height="107" /><p class="wp-caption-text">JSF 2 Ajax Demo</p></div>
<p>And that&#8217;s it. Sure it&#8217;s a simple example, but so far I do like the minimal configuration and the ajax integration.</p>
<img src="http://maxheapsize.com/?ak_action=api_record_view&id=270&type=feed" alt="" /><!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/&amp;title=Getting+started+with+JSF+2+%28and+Maven%29" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/&amp;title=Getting+started+with+JSF+2+%28and+Maven%29" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Getting+started+with+JSF+2+%28and+Maven%29&amp;url=http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/&amp;title=Getting+started+with+JSF+2+%28and+Maven%29" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/&amp;title=Getting+started+with+JSF+2+%28and+Maven%29" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/&amp;bm_description=Getting+started+with+JSF+2+%28and+Maven%29" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/&amp;title=Getting+started+with+JSF+2+%28and+Maven%29" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/&amp;title=Getting+started+with+JSF+2+%28and+Maven%29" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.sphere.com/sphereit/http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/" rel="nofollow" title="Add to&nbsp;SphereIt"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/sphereit.png" title="Add to&nbsp;SphereIt" alt="Add to&nbsp;SphereIt" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.spurl.net/spurl.php?url=http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/&amp;title=Getting+started+with+JSF+2+%28and+Maven%29" rel="nofollow" title="Add to&nbsp;Spurl"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/spurl.png" title="Add to&nbsp;Spurl" alt="Add to&nbsp;Spurl" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Getting+started+with+JSF+2+%28and+Maven%29+@+http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://maxheapsize.com/2009/07/03/getting-started-with-jsf-2-and-maven/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Getting the Browsers GeoLocation with HTML 5</title>
		<link>http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/</link>
		<comments>http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 08:00:23 +0000</pubDate>
		<dc:creator>Oliver Wehrens</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[html 5]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[LBS]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://maxheapsize.com/?p=200</guid>
		<description><![CDATA[
			
				
			
		
Until now it was almost impossible to get the GeoLocation of a user browsing your site. You could try to use several services to more or less guess the current position. Most of the time they where using the IP address to tackle the problem. This was not very reliable when it came to mobile [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fmaxheapsize.com%2F2009%2F04%2F11%2Fgetting-the-browsers-geolocation-with-html-5%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fmaxheapsize.com%2F2009%2F04%2F11%2Fgetting-the-browsers-geolocation-with-html-5%2F&amp;source=owehrens&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Until now it was almost impossible to get the <strong>GeoLocation</strong> of a user browsing your site. You could try to use several services to more or less guess the current position. Most of the time they where using the IP address to tackle the problem. This was <strong>not very reliable</strong> when it came to mobile devices. </p>
<p>Ever since the iPhone hit the market mobile adoption of the web grew exponentially. Google threw in Android and I&#8217;m sure some Windows Mobile phones do have GPS as well.  According to some talks at <a href="http://www.re-publica.de">re:publica 09</a> the big telco carriers such as T-Mobile and Vodafone see their <strong>future in the mobile (geolocation aware) web</strong>.</p>
<p>Even though these devices had the capabilities to get the current location,  website developers are still facing the problem that they can <strong>not access the positioning hardware of the phone</strong>. There was almost no way for (mobile) web developers to get the location of the user. There are some solution out there but you needed to install extra software which is not always possible on a phone. </p>
<p>Fortunately W3C is working on the <b><a href="http://dev.w3.org/html5/spec/Overview.html">HTML 5</a></b> standard which includes JavaScript <b>access to the <a href="http://dev.w3.org/geo/api/spec-source.html">browsers location</a></b> (at least I hope it will be included). The latest beta of <a href="http://en-us.www.mozilla.com/en-US/firefox/3.1b3/releasenotes/">Firefox 3.1 (beta3)</a> already supports that API.   If you don&#8217;t have a GPS system in your computer you can install an <a href="https://addons.mozilla.org/en-US/firefox/addon/8420 ">addon</a> to set your location. Rumors has it that Apple will release the upcoming <strong>iPhone 3.0</strong> OS with a location aware browser and Google will do the same with one of the next updates of <strong>Android</strong>.</p>
<p>To test that I wrote a small <a href="http://maxheapsize.com/static/html5geolocationdemo.html">geolocation aware demo webpage</a> with some JavaScript to pull out the information. If you are accessing it with Firefox 3.1b3+ (plugin installed and configured with your position) you will be prompted for unveiling your location to the website. If you do so it will show you your current position on the map and print out the address. </p>
<div class="wp-caption alignnone" style="width: 500px"><img alt="Allow access to the browsers GeoLocation" src="http://maxheapsize.com/static/html5geolocation01.jpg" title="Allow access to the browsers GeoLocation" width="490" height="482" /><p class="wp-caption-text">Allow access to the browsers GeoLocation</p></div>
<div class="wp-caption alignnone" style="width: 500px"><img alt="Showing the GeoLocation of the Browser" src="http://maxheapsize.com/static/html5geolocation02.jpg" title="Showing the GeoLocation of the Browser" width="490" height="527" /><p class="wp-caption-text">Showing the GeoLocation of the Browser</p></div>
<p>To access this information all you need to do is:</p>
<pre class="brush: jscript;">
    function showMap(position) {
      // Show a map centered at
      // (position.coords.latitude, position.coords.longitude).
    }
    // One-shot position request.
    navigator.geolocation.getCurrentPosition(showMap);
</pre>
<p>Once this feature is widely available in mobile browsers (I do hope for this summer) my bet is that we will see a whole bunch of websites doing all sort of crazy things with these information. I&#8217;m a big Location Based Services (LBS) fan and I can&#8217;t wait to see people taking advantage of this.</p>
<p> <strong>Update</strong> Firefox 3.5.x uses Google&#8217;s Geolocation service if no other way can be used. This is halfway accurate. It gathers information about nearby wireless access points and your computer’s IP address. No more plugin needed.</p>
<img src="http://maxheapsize.com/?ak_action=api_record_view&id=200&type=feed" alt="" /><!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/&amp;title=Getting+the+Browsers+GeoLocation+with+HTML+5" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/&amp;title=Getting+the+Browsers+GeoLocation+with+HTML+5" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Getting+the+Browsers+GeoLocation+with+HTML+5&amp;url=http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/&amp;title=Getting+the+Browsers+GeoLocation+with+HTML+5" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/&amp;title=Getting+the+Browsers+GeoLocation+with+HTML+5" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/&amp;bm_description=Getting+the+Browsers+GeoLocation+with+HTML+5" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/&amp;title=Getting+the+Browsers+GeoLocation+with+HTML+5" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/&amp;title=Getting+the+Browsers+GeoLocation+with+HTML+5" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.sphere.com/sphereit/http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/" rel="nofollow" title="Add to&nbsp;SphereIt"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/sphereit.png" title="Add to&nbsp;SphereIt" alt="Add to&nbsp;SphereIt" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.spurl.net/spurl.php?url=http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/&amp;title=Getting+the+Browsers+GeoLocation+with+HTML+5" rel="nofollow" title="Add to&nbsp;Spurl"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/spurl.png" title="Add to&nbsp;Spurl" alt="Add to&nbsp;Spurl" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Getting+the+Browsers+GeoLocation+with+HTML+5+@+http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://maxheapsize.com/2009/04/11/getting-the-browsers-geolocation-with-html-5/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>IE7 caches rendered elements?</title>
		<link>http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/</link>
		<comments>http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 20:19:57 +0000</pubDate>
		<dc:creator>Oliver Wehrens</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[ie7]]></category>

		<guid isPermaLink="false">http://maxheapsize.com/?p=164</guid>
		<description><![CDATA[
			
				
			
		
I&#8217;m tasked with some css tweaking to our current product. We need to implement a &#8216;Print Preview&#8217; screen so the customer can see how this looks before printing. Css supports exactly this use case with the @media notation.
So far so good.
Now Internet Explorer gives me some headache. Basically it looks like that if I render [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fmaxheapsize.com%2F2009%2F03%2F30%2Fie7-caches-rendered-element%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fmaxheapsize.com%2F2009%2F03%2F30%2Fie7-caches-rendered-element%2F&amp;source=owehrens&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;m tasked with some css tweaking to our current product. We need to implement a &#8216;Print Preview&#8217; screen so the customer can see how this looks before printing. Css supports exactly this use case with the @media notation.</p>
<p>So far so good.</p>
<p>Now Internet Explorer gives me some headache. Basically it looks like that if I render a page and then render the same page again with a slightly different style sheet, the lovely IE (7) will cache the width/text-align of the element. That means formerly right aligned text now looks like center aligned. Using FireBug under Firefox confirms the correct right aligned styled text. Even using the IE Developer Toolbar shows the correct style sheet information and element. Still, it renders sort of centered. By accident the right border of the text is exactly as far away from the left border as in the previous rendering. If I add any attribute to the text cell (or delete an attribute) all of the sudden the text will be rendered right aligned exactly how it should have been in the first place. </p>
<p>My guess is that IE remembers the width and alignment of the text cell from the previous page (why else the centered text appears to be the size). Deleting/adding an element via the developer tools forces a refresh and voila it renders how it should be.</p>
<p>I hate it.</p>
<div class="wp-caption alignnone" style="width: 275px"><img alt="First rendering of the text cell" src="http://www.maxheapsize.com/static/ie_align_01.jpg" title="First rendering of the text cell" width="265" height="22" /><p class="wp-caption-text">First rendering of the text cell</p></div> 
<div class="wp-caption alignnone" style="width: 429px"><img alt="Rendering with almost the same style sheet" src="http://www.maxheapsize.com/static/ie_align_02.jpg" title="Rendering with almost the same style sheet" width="419" height="28" /><p class="wp-caption-text">Rendering with almost the same style sheet</p></div>
<div class="wp-caption alignnone" style="width: 439px"><img alt="Identifying the cell with the IE developer toolbar" src="http://www.maxheapsize.com/static/ie_align_03.jpg" title="Identifying the cell with the IE developer toolbar" width="429" height="28" /><p class="wp-caption-text">Identifying the cell with the IE developer toolbar</p></div>
<div class="wp-caption alignnone" style="width: 524px"><img alt="Deleting the id attribute with the Developer Toolbar" src="http://www.maxheapsize.com/static/ie_align_04.jpg" title="Deleting the id attribute with the Developer Toolbar" width="514" height="89" /><p class="wp-caption-text">Deleting the &#39;id&#39; attribute with the Developer Toolbar</p></div>
<div class="wp-caption alignnone" style="width: 429px"><img alt="Voila, just after deleting the attribute, the cell renders how it should have been" src="http://www.maxheapsize.com/static/ie_align_05.jpg" title="Voila, just after deleting the attribute, the table cell renders how it should have been" width="419" height="30" /><p class="wp-caption-text">Voila, just after deleting the attribute, the cell renders how it should have been</p></div>
<p>I guess there is a solution for this, I just don&#8217;t know it. In any case&#8230;.this is unexpected behavior.</p>
<p>On top of that: using css and Apache Trindad with a print preview on screen makes it hard to manipulate the css for the printout since I just don&#8217;t know the names of the css classes nor the imported Trinidad css file name (and I do have pre compiled/packaged css file where I have to restart the server every time if I do some changes).</p>
<p>*rant off*</p>
<img src="http://maxheapsize.com/?ak_action=api_record_view&id=164&type=feed" alt="" /><!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/&amp;title=IE7+caches+rendered+elements%3F" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/&amp;title=IE7+caches+rendered+elements%3F" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=IE7+caches+rendered+elements%3F&amp;url=http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/&amp;title=IE7+caches+rendered+elements%3F" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/&amp;title=IE7+caches+rendered+elements%3F" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/&amp;bm_description=IE7+caches+rendered+elements%3F" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/&amp;title=IE7+caches+rendered+elements%3F" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/&amp;title=IE7+caches+rendered+elements%3F" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.sphere.com/sphereit/http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/" rel="nofollow" title="Add to&nbsp;SphereIt"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/sphereit.png" title="Add to&nbsp;SphereIt" alt="Add to&nbsp;SphereIt" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.spurl.net/spurl.php?url=http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/&amp;title=IE7+caches+rendered+elements%3F" rel="nofollow" title="Add to&nbsp;Spurl"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/spurl.png" title="Add to&nbsp;Spurl" alt="Add to&nbsp;Spurl" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+IE7+caches+rendered+elements%3F+@+http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://maxheapsize.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://maxheapsize.com/2009/03/30/ie7-caches-rendered-element/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
