<?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>Andy Gibson &#187; Seam</title>
	<atom:link href="http://www.andygibson.net/blog/tag/seam/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andygibson.net/blog</link>
	<description>Open Source Projects &#38; Technical Writings</description>
	<lastBuildDate>Fri, 30 Jul 2010 02:42:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A Guide to Spigot For Seam Developers</title>
		<link>http://www.andygibson.net/blog/article/spigot-for-seam-developers/</link>
		<comments>http://www.andygibson.net/blog/article/spigot-for-seam-developers/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 17:00:57 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Project Kenai]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[Spigot]]></category>
		<category><![CDATA[Weld]]></category>
		<category><![CDATA[Wicket]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=874</guid>
		<description><![CDATA[Note : Spigot has been renamed to DataValve.
(Edit : I renamed this post so it doesn&#8217;t seem like Spigot is just for Seam, Spigot can be used with different frameworks or without any at all. However, I wrote this post since Spigot is so familiar to the Seam EntityQuery that it should be easy for [...]]]></description>
			<content:encoded><![CDATA[<p><b>Note</b> : Spigot has been renamed to <a href="http://www.fluttercode.com/projects/datavalve/">DataValve</a>.</p>
<p>(<small><b>Edit </b>: I renamed this post so it doesn&#8217;t seem like Spigot is just for Seam, Spigot can be used with different frameworks or without any at all. However, I wrote this post since Spigot is so familiar to the Seam EntityQuery that it should be easy for Seam users to get the idea</small>)</p>
<p>Seam developers should become familiar with <a href="http://kenai.com/projects/spigot/">Spigot</a> concepts fairly quickly since they are very similar to those found in the Seam <code>EntityQuery</code> which was one of the main inspirations for the framework. If you imagine taking the entity query class and splitting it in two, one part to keep hold of state and the other to actually fetch the data. The stateful part is the <code>Paginator</code> that keeps track of what the current ordering of the data is, what is the current page and how big the pages are. The stateless part takes the Ejbql and the pagination information and returns a subset of the data. Now imaging that the data provider has the JPA pieces taken out and replaced with an abstract <code>fetchResults</code> method. This method is implemented in subclasses for specific data providers for text files, sql queries, jpa queries, native jpa queries, xml files, comma delimited or just an in memory dataset.<br />
<span id="more-874"></span><br />
I also abstracted the concepts of parameterization and parameter resolution so you can have parameters on data providers that are no t query based and your parameters can be resolved using different mechanisms such as EL, reflection, a map, or using custom parameter resolution.<br />
So really, for Seam developers, its like a Seam <code>EntityQuery</code> that doesn&#8217;t just use JPA, but uses any kind of data source you want but still returns just a list of objects.</p>
<p>Spigot works nicely with CDI and there is even a demo of it in the distribution that uses JSF and was generated using the Weld maven archetypes. Also, there is a Seam Jpa Dataset Adapter that you can use as a direct replacement for the <code>EntityQuery</code> which will adapt the entity query calls to the underlying data provider calls so you can have a seam-less transition if you want to switch over. This is still a little in-progress, but works. The one area that isn&#8217;t implemented is the sorting, which may not be possible, but I still need to add in the methods to the adapter even if they don&#8217;t do anything. The other issue is of course the configuration of the query from components.xml using the Seam Framework tags. However, you can define the query using regular component xml tags to define the Ejbql, restrictions and page sizes.</p>
<p>Two things to note if you start using Spigot in place of the entity query. All rows are returned by default, and you need to specify both a select statement and a count statement. I separated those two out so you can put join fetch phrases in the select statement without it breaking the count statement. There is an <code>init</code> method that you can use to set both of these statements for a class type.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/spigot-for-seam-developers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Spigot 0.9.CR1 released</title>
		<link>http://www.andygibson.net/blog/news/spigot-0-9-cr1-released/</link>
		<comments>http://www.andygibson.net/blog/news/spigot-0-9-cr1-released/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 13:07:55 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[Spigot]]></category>
		<category><![CDATA[Weld]]></category>
		<category><![CDATA[Wicket]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=861</guid>
		<description><![CDATA[Note : Spigot has been renamed to DataValve and is hosted over on FlutterCode.com.
It&#8217;s been a while since I&#8217;ve posted anything new as I&#8217;ve been busy with a new Open Source software project called Spigot. It&#8217;s a java library that sits between your application code and your data sources (Hibernate, JPA, JDBC or any arbitrary [...]]]></description>
			<content:encoded><![CDATA[<p><b>Note</b> : Spigot has been renamed to <a href="http://www.fluttercode.com/projects/datavalve/">DataValve</a> and is hosted over on <a href="http://www.fluttercode.com">FlutterCode.com</a>.</p>
<p>It&#8217;s been a while since I&#8217;ve posted anything new as I&#8217;ve been busy with a new Open Source software project called Spigot. It&#8217;s a java library that sits between your application code and your data sources (Hibernate, JPA, JDBC or any arbitrary source of data) and helps with things like pagination and sorting using a common interface so you can switch out data providers and use alternatives. </p>
<p>For query language data providers, Spigot also facilitates excluding restrictions from WHERE clauses when parameters are resolved to null. Parameters are handled using parameter resolvers so there is more than one way to parameterize the query including EL expressions, reflection or a value map on the data provider.</p>
<p>Spigot also provides a few other add-ins like converting any dataset into an in-memory dataset that can itself be paginated and sorted and shared across an application (such as commonly used data in a web application). The <code>IndexedDataProviderCache</code> can give you random access into a dataset with caching and look ahead loading. This lets you hook a dataset with thousands of rows up to a Swing JTable with an instant response and a very small memory footprint since it doesn&#8217;t need to load all the objects at once as the provider will load the records as needed and cache the results. This is demonstrated in the Swing Demo in the download. There are also demos for Wicket and CDI with JSF.</p>
<p>You can ready about why I created Spigot in the <a href="http://spigot.kenai.com/docs/html/pr01.html">documentation</a></p>
<p>Spigot is currently hosted on <a href="http://www.projectkenai.com/projects/spigot/">Project Kenai</a>, where you can download the release, view documentation online or read about <a href="http://kenai.com/projects/spigot/pages/10WaysSpigotHelpsDevelopers">10 ways Spigot helps developers</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/news/spigot-0-9-cr1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding Nested Conversations</title>
		<link>http://www.andygibson.net/blog/article/understanding-nested-conversations/</link>
		<comments>http://www.andygibson.net/blog/article/understanding-nested-conversations/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 03:04:53 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=778</guid>
		<description><![CDATA[I had a bit of epiphany on the subject of nested conversations the other day when I was thinking about them and thought I&#8217;d share. I think nested conversations have been a little misunderstood with people unsure of how to use them, myself included, but I think I have found the best way to think [...]]]></description>
			<content:encoded><![CDATA[<p>I had a bit of epiphany on the subject of nested conversations the other day when I was thinking about them and thought I&#8217;d share. I think nested conversations have been a little misunderstood with people unsure of how to use them, myself included, but I think I have found the best way to think of them.<br />
<span id="more-778"></span><br />
In summary, nested conversations do for regular conversations what conversations do for session scope. With session scope, you cannot have mutliple instances of a named variable, you have to put each variable instance in its own conversation where it will be unique. However, if you want to have multiple instances of a named variable within the conversation, again, you cannot and you have the same problem you have with the session scope, that variables must be unique. Therefore  you have to have each variable in its own nested conversation under the main conversation the same way we had the top level conversation under the session scope.</p>
<p>In some weird web app which lets you pick a person and then put costumes on them, you might have a main page where you select the person, and then in separate browser windows you can pick different outfits for that person. You put the selected person value in a different conversation so the value of <code>#{selectedPerson}</code> is local to the conversation allowing multiple selected people in different browser windows. This overcomes the limitations of the session which allows only one value for <code>#{selectedPerson}</code></p>
<p> However, if you had that conversation open in multiple windows or tabs so you can compare different costumes on that person, there would only be one value of <code>#{selectedCostume}</code> for the conversation shared between all windows. As you select a costume in one window, it would affect all the other windows as they share the variable in that conversation. Using nested conversations would allow the conversation to have different values for the selected costume under the same parent conversation with the same selected person.</p>
<p>Taking it further you could select the person in the top level conversation, select the costume in the nested conversation, and then you could have multiple windows open with further nested conversation letting you pick different shoes to go with that costume. Also, if you change the person in the top level conversation, it will change the selected person for all windows using that conversation or any of its nested conversations.</p>
<p>I&#8217;m not sure there is a great need for nested conversations, I&#8217;ve never really used them or found the need and I don&#8217;t think users open that many browser windows or tabs to create different logic paths within a conversation. I think it is acceptable to limit the data isolation to a single conversation level.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/understanding-nested-conversations/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Seam is Dead, Long live Seam</title>
		<link>http://www.andygibson.net/blog/article/seam-is-dead-long-live-seam/</link>
		<comments>http://www.andygibson.net/blog/article/seam-is-dead-long-live-seam/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 13:39:30 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=637</guid>
		<description><![CDATA[With Weld 1.0, the reference implementation of JSR 299 &#8211; Java Contexts and Dependency Injection now released, attention at JBoss has no doubt turned to Seam 3 which is going to be built on top of Weld. Red Hat and JBoss are committed to returning innovations back the JCP as is the case with Seam [...]]]></description>
			<content:encoded><![CDATA[<p>With Weld 1.0, the reference implementation of JSR 299 &#8211; Java Contexts and Dependency Injection now released, attention at JBoss has no doubt turned to Seam 3 which is going to be built on top of Weld. Red Hat and JBoss are committed to returning innovations back the JCP as is the case with Seam which not only resulted in JSR 299, but has also influenced a number of other JSRs especially JSF 2. With JSR 299 standardizing the Seam &#8217;style&#8217; of development it also brings about a some fundamental game changes for Seam 3 (hence the title) as much of the strength of Seam becomes part of the JEE standards.<br />
<span id="more-637"></span><br />
One problem I have with Seam is the all-or-nothing level of intrusion it has. I&#8217;m either working on a Seam app, or I&#8217;m not, and I pretty much have to commit to it at the start of the project. One thing Spring had going for it was you didn&#8217;t need to commit to it initially. You could start your web app, and then just add in a little bit of Spring at a time. You could continue adding Spring until it is littered all the way through your code.</p>
<p>Developers can be finnicky at times, and find topics such as heavy app servers and framework lock-in (even to the standards) to be more of an issue than they should be. On this level, Seam really lost out since it was based on standards, ran on an app server (although it ran in many environments), and there was a degree of lock-in as a Seam project, not much more than any other framework based project.</p>
<p>However, Seam itself is an excellent framework and it certainly helped make JSF 1.2 a more usuable framework. Most of those holes are now patched permanently with JSF 2.0 which logically would mean that JSF 2.0 is up to par with JSF 1.2 plus Seam. Well, not quite, although JSF has come a long way I think the one reason Seam soothed a lot of pains was not just down to the fact that it made JSF 1.2 usable. It was also because of the additional functionality it provided above and beyond the average web framework. First was the conversation scope which not only provided a more versatile scope than request and session scope, but also laid the foundation for resolving other problems. With conversation scope we are able to easily handle multiple browser windows/tabs, including independent page flows within those tabs as well as providing Workspace management. Second, it was a full stack solution with a (softly) predefined set of libraries providing different pieces of the stack. No more piecing together different technologies and getting it to work properly, you got everything in one bundle to create stateful rich web applications.</p>
<p>There are probably interesting times ahead for Seam with the evolution of JEE 6 and the release of CDI. EJB 3.1 continues the trend of making EJBs easier than ever, JSF 2.0 makes it a more pleasant experience (now with AJAX), and Weld now provides us not only with a standards based, contextual dependency injection framework, and also makes conversational applications possible out of the box. Many of the great things Seam offered is now available in JEE 6 as part of a standard stack. This is an exciting prospect for developers and makes the JEE 6 stack far more attractive, but doesn&#8217;t it also reduce the need for Seam?</p>
<p>JEE 6 isn&#8217;t simply Seam standardized, nor is it even Seam lite. There are still a number of larger features in Seam not available in JEE and rightfully so since there are a number of functions which are too specific to be standardized. This particularly applies to the features that span across multiple technologies that fit into neither the CDI, JPA, or JSF libraries. Interestingly, the Seam name would also still be suitable as a framework used to stitched them all together which was originally the concept for Seam. JSR 299 offers not only a firm base onto which you can implement those features, but allows implementing them as expansion plugins to the CDI framework through which most of Seam 3 will be implemented.</p>
<p>My hope is that Seam 3 will consist of a set of fairly independent plugins that can be added to applications in the form of CDI / JSF plugins so there is less lock-in and more of a sense of adding Seam where it is needed. This way we don&#8217;t need to start with a Seam application from the start, we can start with a standard plain old JEE 6 web application using EJB, CDI, JSF, JPA and add the Seam features as needed. Another benefit here is that when we add Seam components in such a manner, we are not adding framework code, we are adding features that works on top of our existing framework since the base code for such features is already in the JEE stack. This has worked well in the past on various different platforms, specifically in Java with JSF and the different component libraries available for it.  I think this softer approach to integration will make it more appealing in the long run, . While JEE 6 may have lower barriers to entry for this functionality, JBoss have shown they are able to compete in such environments, for example on the JSF front they have previously competed with different stateful and conversational frameworks.</p>
<p>Overall, things are looking very interesting for the future of JEE 6, and its progress has sparked a resurgent interest from developers. JSR 299 fills an important gap in JEE giving developers a powerful and feature filled standard web stack which can be extended easily. While it may remove some of the need for Seam, it also offers more opportunities for Seam to integrate with the new stack effortlessly and build on it with more features.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/seam-is-dead-long-live-seam/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Conversational Pitfalls</title>
		<link>http://www.andygibson.net/blog/article/conversational-pitfalls/</link>
		<comments>http://www.andygibson.net/blog/article/conversational-pitfalls/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 01:44:52 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=524</guid>
		<description><![CDATA[Seam conversations have certain rules that you need to be aware of when using them. This article came about because for the last couple of years, the same questions have been asked on the Seam forums regarding conversations. It is also a couple of issues that cropped up while I was working on the Seam [...]]]></description>
			<content:encoded><![CDATA[<p>Seam conversations have certain rules that you need to be aware of when using them. This article came about because for the last couple of years, the same questions have been asked on the Seam forums regarding conversations. It is also a couple of issues that cropped up while I was working on the Seam vs. Spring Web Flow articles. Some of the problems are uncannily similar with similar solutions, so parts of this series may be of interest to non-Seam users. Additionally, it seems like a lot of this stuff will also apply to the conversational pieces of JSR 299 &#8211; Contexts and Dependency Injection which will be a part of JEE 6.<br />
<span id="more-524"></span></p>
<h1>Conversational Fundamentals</h1>
<p>Let&#8217;s start with a fairly descriptive and steady paced description of what conversations are and what they are not. Some of these behaviors are probably more figurative that literal. This mainly applies to Seam, but is also similar to CDI.</p>
<p>Conversations in Seam are like buckets that hold conversational data. A user session has a list of conversation contexts each identified by a conversation Id. A conversation is either long running or temporary and even when you are not in a long running conversation, you are using a temporary conversational context or bucket. The only difference between a long running conversation and a temporary conversation is the boolean <code>longRunning</code> flag on the conversation instance. When you start a conversation, all that happens is the <code>longRunning</code> flag on the conversation is set to true. When you end the conversation, the <code>longRunning</code> flag is cleared. There is no destruction of conversational objects and no clearing out of the conversation. Abandoned long running conversations sit in the conversation list until they time out. Note that in JCDI (JSR 299), the long running flag has been renamed to a <code>isTransient</code> flag on the conversation. </p>
<p>Components that are scoped to the conversation are still held in the conversation context regardless of whether it is long running or temporary. The only difference with a long running conversation is that the id for the conversation is propagated from one page to the next. When the id is propagated, that same conversation &#8216;bucket&#8217; is used by the next page and the objects that were in the previous page are accessible in the new page. In each request, Seam determines if the conversation is long running, and if so, it passes the conversation id to the next page as a parameter. Obviously, this propagation only takes place with faces requests, or GET requests that have special handling like manual conversation propagation or you are using the Seam JSF controls that provide GET requests with automatic conversation propagation. </p>
<p>When rendering a new page, at some point Seam will need to access the conversational context. It does this by looking to see if the request contained a conversation id and if so, looking up the existing conversation context instance for that id. Otherwise, it obtains a new conversation instance with a new conversation Id. When there is no long running conversation, no id is propagated so each page obtains a new conversation instance and Id. When we start a long running conversation Seam will automatically propagate the conversation id from one page to the next for us which is how we write applications with multiple pages using the same conversation. </p>
<p>When you end a conversation, the <code>longRunning</code> flag is set to false and Seam no longer propagates the id from one page to the next. However, when you end a conversation on one page, Seam will still propagate the conversation to the next page one last time. This allows us to carry things like faces messages and any other data over the conversation boundary. This next page gets to use the same conversation instance that just finished outside of the conversation boundary. It has a number of benefits as well as some important consequences that can cause many problems that are tricky to track down.</p>
<p>If you end your conversation and set the <code>before-redirect</code> attribute to true the conversation is ended before the redirect so the conversation id is not propagated and the new page starts with a fresh conversation context. The problem with this is that since there is no propagation of the conversation, faces messages (and any other information you wanted to carry to the new page) is not propagated either. This is to be expected since you explicitly specified that you wanted to end the conversation before the new page.</p>
<p>There are also times when Seam will propagate the conversation from one page to the next when it is not long running. If a redirect is taking place, then Seam promotes the conversation to long running temporarily so the conversation id parameter is passed to the redirect. The conversation is then demoted again to a temporary conversation. This allows items such as faces messages to propagate so you can show messages even after a redirect.</p>
<p>One useful way of seeing which conversation you are using is to add <code>Conversation = #{conversation.id}</code> to your template so you can see what conversation id the page is using. This way you can see whether or not the conversation has propagated and whether you are using the same value from the previous page. If the conversation id on two pages is the same, they are using the same conversation instance and sharing data.</p>
<p>Hopefully, this section has provided enough of an overview into Seam conversations, cleared some of the misconceptions up and will make understanding some of the conversational pitfalls easier.</p>
<h1>Dirty Data</h1>
<p>When you end a conversation, the conversation instance contains multiple pieces of data. Let&#8217;s take the scenario of editing a widget, and clicking save or cancel and being taken back to the widget view page. Our Seam page uses a factory method to generate the <code>#{widget}</code> instance from our <code>WidgetHome</code> bean. We may edit the instance, and post back the changes, and then decide to cancel our changes. At this point, our widget in the conversation is dirty, it has changes made to it that we have cancelled. If we do nothing and just go back to the view page, the conversation will be re-used since we propagate that ended conversation id over one last time. The <code>#{widget}</code> references in the view page will refer to our existing dirty instance in the re-used conversation. Since the variable exists in the conversation already, Seam won&#8217;t call the factory method to get a fresh instance.  As a result our view page shows the dirty instance with all our modifications.</p>
<p>This problem can be solved in a couple of different ways, each with its own problems. The simplest is to use <code>before-redirect=true</code> when ending the conversation. This way our view page won&#8217;t use the dirty data from the ended conversation and it starts with a fresh conversation. This may be a problem though if you are passing the widgetId parameter from the previous page. Pages.xml lets you easily add parameters to redirects, but pageflows don&#8217;t. It also means that you won&#8217;t be able to pass any other data over such as a message to say you have cancelled changes. Another similar, but more forceful, way of doing this is just to have a non-faces &#8216;cancel&#8217; link on your edit page that takes you straight to the edit page with a GET request and passes in the widget Id. In this scenario, the conversation is abandoned since we used a link and it will not propagate the conversation or the associated dirty data over with it, nor can you pass any cancellation messages over.</p>
<p>The other method is to let the view page re-use the conversation, but when the user cancels the changes, actually refresh the entity that has been changed. You create a cancel method on the entity home bean which is called when the user cancels their changes and it will refresh the entity so it is no longer dirty. This has the benefit of causing minimal disruption, but if you have a long chain of objects that ended up dirty, making sure you refresh them all can be tricky. </p>
<h1>Stale Data</h1>
<p>The stale data problem is similar to the dirty data problem except the problem occurs within the same conversation and without ending it. If we have some data in a conversation that depends on other values in the conversation, when those values change, we have to make sure we update our data, otherwise it will become stale. For example a paginated list of sales orders from on an EntityQuery means that we need to get a new set of results when we click next or previous. However, if the results of the query are outjected from the query bean and referenced as <code>#{orderList}</code> in the JSF page, then we will see the stale data problem. The first time we enter the page, the variable <code>#{orderList}</code> doesn&#8217;t exist, so Seam calls the factory for <code>#{orderList}</code> which returns the list of the first 10 results.  Our datatable shows the list of results using the variable <code>orderlist</code>.</p>
<pre class="brush: xml;">
&lt;h:dataTable value=&quot;#{orderList}&quot;&gt;
  &lt;!-- Columns Here --&gt;
&lt;/h:dataTable&gt;
</pre>
<p>The user clicks next in the paginator which does a postback, increases the <code>firstResult</code> value and causes a refresh on the result list referenced by the entity query to show the next 10 results. The page is rendered but the displayed results are exactly the same. We are still looking at the first 10 rows. Why? Because the <code>orderList</code> context variable is used by the view to obtain the list of orders. When the page is rendered the second time, JSF looks for the value of <code>#{orderList}</code> and finds it already exists in the conversational context even though it contains the first 10 results, and not the second 10. Seam has no reason to call the factory method to obtain the latest values. In essence, we have two sets of results, the original set which is referenced by the <code>orderList</code> seam variable, and the current set which is the correct list of results and is held by the query bean. </p>
<p>We have two ways of fixing this problem. The first is to change the value our data table is referencing so it is always referencing the result set on the query bean directly.</p>
<pre class="brush: xml;">
&lt;h:dataTable value=&quot;#{orderQuery.resultList}&quot;&gt;
  &lt;!-- Columns Here --&gt;
&lt;/h:dataTable&gt;
</pre>
<p>With this code, there is no El expression used that can become stale. When the page is re-rendered the table will get the results from the order query directly each time ensuring that the most up to date values are used. This is the easiest solution but it cannot be used if you are using the <code>DataModel</code> annotation since Seam requires you to use the outjected data model variable. In such cases refer to the second solution which is to invalidate the <code>orderList</code> variable when we refresh the search results. This is fairly easy, but requires us to override the <code>refresh</code> method in the entity query. When we refresh the list of orders, we simply remove the <code>#{orderList}</code> context variable. i.e.</p>
<pre class="brush: java;">
@Override
public void refresh()
{
    super.refresh();
    Contexts.removeFromAllContexts(&quot;orderList&quot;);
}
</pre>
<p>This means that when the user causes a refresh of the query data, the variables referencing that data will be ejected from all contexts and the next time that value is requested in a JSF page, the appropriate Seam factory will be called to get the most up to date result set.</p>
<h1>Starting a conversation</h1>
<p>Even starting a conversation can be a problem. In most cases, we utilize the <code>join="true"</code> attribute to gloss over the fact that we are going into a page that requires a conversation with or without a conversation already started. When we hit our target page, we know that we will be in a conversation, either a newly started one, or an existing conversation. We may not care which except that not considering our conversation start and end points has side effects. Using the join attribute is not a substitue for thinking about conversation demarcation.</p>
<p>First is the issue of old data where a new page may re-use data from the last page because they share the conversation. For example, we are viewing a widget and the widget instance is loaded into the temporary conversation. 10 minutes later, we click edit which takes us to the widget edit page and starts a long running conversation. The edit page needs an instance of a widget which it already has from the view page, but this instance of a widget is 10 minutes old and has been edited by another user since you loaded the view page and therefore, you need to do a refresh. This problem arose without us even starting a long running conversation in the view page. The answer here is to ensure that you are always starting with a fresh conversation instance when you go in to the edit page. The easiest way to do that is to use <code>propagation="none"</code> on the link to edit the widget, or just use a plain old GET link.</p>
<p>If a page is meant to start a conversation and also start a pageflow then you cannot enter that page with an existing conversation. If you do, the page will join the existing conversation and the pageflow will not start. Pageflows can only be started with a fresh conversation. Note that initially a page may be simple enough that you don&#8217;t need a pageflow and you could ignore conversation demarcation, but if you later start a pageflow on that page, you could end up with all sorts of headaches as invoking that page from different places may or may not start the pageflow depending on whether the page you were on previously had a long running conversation.</p>
<h1>Menus</h1>
<p>Always consider your menus and their links and what pages they will be used in. They could be called from pages where there may or may not be a long running conversation. Consider whether that conversation is propagated or not. Typically (and luckily) most links in menus are to top level items and thus conversation propagation is never really required which means you can just never propagate it. Propagation is mostly task centric and therefore is more likely to appear in the main page itself rather than a general application wide menu.</p>
<p>One other problem I found was with rich menu items which only allow an action on the menu item. Typically to end or demarcate a conversation, you would need an <code>s:link</code> or <code>s:button</code> since only these Seam specific controls were are aware of the concept of conversation propagation. Since our menu is shared across all pages if we were in a pageflow, we could end up with Illegal Navigation issues since we don&#8217;t account for global menu navigation in our pageflows. Alternatively, we might be in a conversation and calling a page that starts a new conversation with a pageflow so we need to end the conversation before we get there so we can start the new conversation and also the new pageflow. In a nutshell, we need to end any current conversation then re-direct to a new page where we will start a new conversation. We also need to be able to do this from a JSF <code>action</code> since some menu components require actions instead of allowing you to add links.</p>
<p>One solution to this is to use a navigator component that will perform these tasks for us and we just pass in the view-id that we want to go to.</p>
<pre class="brush: java;">
@Name(&quot;navigator&quot;)
@Scope(ScopeType.STATELESS)
public class Navigator {

	public void gotoView(String view) {

		if (Conversation.instance().isLongRunning()) {
			Conversation.instance().end(true);
		}

		Redirect.instance().setViewId(view);
		Redirect.instance().execute();
	}

}
</pre>
<p>With this, we can define our action methods as <code>#{navigator.gotoView("/startBookingProcess")}</code> and when that menu item is selected, it will end the conversation and perform the redirect so on our new page we can start a new conversion and pageflow.</p>
<h1>Conversational Best Practices</h1>
<p>These are best practices that I&#8217;ve found working with Seam and conversations in general. Obviously, it&#8217;s a personal thing, and some people may disagree with me on them, but these rules have served me and my team well.</p>
<p>Always determine where a page fits in terms of conversations and always treat that page the same way. For example, edit and view pages I tend to isolate from other conversations. I tend to only use the temporary conversation for the view page so if you click refresh, it reloads the data which is really what you want, a refreshed view of what you are looking it. Any links to a view (or edit) page do not propagate the conversation at all. </p>
<p>I always start conversations in <code>pages.xml</code> since this provides a single common place to do it. I&#8217;ve never really used the annotations since it requires knowledge of the target page to know which method you need to call. To edit a widget, with pages.xml you can just go to <code>/widgetEdit.seam?widgetId=234</code> as opposed to calling a specific method annotated with <code>@Begin</code>.</p>
<p>Hope this has helped guide you through some of the complexities of conversations in Seam. Once you understand the basic principles, it makes it much easier to figure out why something isn&#8217;t working quite right, and some of these bugs relating to stale and dirty data can be subtle and sneaky.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/conversational-pitfalls/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Glassfish, Netbeans and JSF 2.0 Test Drive</title>
		<link>http://www.andygibson.net/blog/article/glassfish-netbeans-and-jsf-2-0-test-drive/</link>
		<comments>http://www.andygibson.net/blog/article/glassfish-netbeans-and-jsf-2-0-test-drive/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 04:32:44 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=611</guid>
		<description><![CDATA[I&#8217;ve spent some time in the last couple of weeks playing around with Glassfish, Netbeans 6.8 Beta (and milestone 2 before it) and JSF 2.0, and I have to say that this is turning out to be a really good set of development libraries and tools.

(note This post relates to both the milestone 2 and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent some time in the last couple of weeks playing around with Glassfish, Netbeans 6.8 Beta (and milestone 2 before it) and JSF 2.0, and I have to say that this is turning out to be a really good set of development libraries and tools.<br />
<span id="more-611"></span></p>
<p>(<b>note</b> This post relates to both the milestone 2 and beta versions of Netbeans 6.8 which I have been tinkering with over the duration of this article being written.)</p>
<p>The <a href="http://www.netbeans.org/community/releases/68/">download for Netbeans 6.8 </a> comes with <a href="https://glassfish.dev.java.net/">Glassfish v3 </a> which implements JEE 6 including <a href="http://jcp.org/en/jsr/detail?id=314">JSF 2.0</a> and <a href="http://jcp.org/en/jsr/detail?id=317">JPA 2.0</a>.</p>
<p>Glassfish now has <b>really</b> fast hot deployment so you can change a line of code, save it, and it re-deploys instantly which in my opinion, this is a huge productivity booster. This isn&#8217;t limited to Netbeans, the eclipse plugins also provide this feature, and it works with pretty much any framework. I tried it with Wicket and Spring MVC and it was fantastic to get a wicket error where I had forgotten to add a component, so I go back to the java page code, add the component, refresh my browser and it works. Glassfish now has support for JEE 6 so you can make a pojo a local EJB just by adding the <code>@stateless</code> annotation to it. You can also deploy EJBs in war files as well without needing the whole EAR setup. One problem I did see was that when you used the EAR project setup with an EJB and War project, the hot deploy didn&#8217;t appear to work as well. Changes to the war file didn&#8217;t appear to redeploy, maybe because it is the EAR file that is deployed and not the war. However, still fantastic stuff.</p>
<p>Netbeans 6.8 beta was released in the last week or so. Feature-wise it is a great product with better tooling for JSF, including JSF 2.0, facelets support, and auto-completion for JSF backing beans in the JSF page. It also includes support for JEE 6, EJB 3.1, JPA 2.0 and development with Glassfish v3. It also improves upon the existing Maven support by providing for mavenized Ear projects. </p>
<p>While the features are impressive, Netbeans still seems hindered by performance issues and some minor bugs (although it is a milestone/beta release). Personally, I found this release no more sluggish that other releases although some people in the forums have had worse experiences. Netbeans strength has always been that it offers one standard solution without the plugin nightmares that eclipse has. While Netbeans has plugins they are more like installable features, they have a higher granularity than Eclipse plugins which is more like DLL hell. That said, I use Eclipse at work and it is always hard to shift from one keyboard mapping to another, and Eclipse does seem faster without the intermittent pauses. However, right now, Netbeans is a superior product in terms of features, especially for a JSF developer. I&#8217;d keep an eye out for the 6.8 final release to see how it comes out, and give 6.8 milestone 2 a go just to enjoy the experience if you are interested in using a standards based stack because thats obviously where the Netbeans folks are focused. </p>
<p>One big issue I have with Netbeans is the oddness of some of the key mappings. I think in nearly every application I use I press Alt+F and then C to close the currently edited document. Whether is it in MS Office, Borland Delphi, Eclipse, Firefox, while in the file menu, the C key always closes the currently open document you are editing. In Netbeans, it closes the currently edited project which means suddenly my project disappears when I want to close an edited file. Another is the use of Ctrl+Space for invoking auto completion which in Netbeans sends focus to the project manager or something like that. Sure, I can change the keymappings, such as to the Eclipse profile, but then I&#8217;m using some arbitrary weird key mapping which isn&#8217;t Netbeans and it isn&#8217;t completely the same as Eclipse. It is probably this way for legacy reasons, but some of these key presses are de facto standards.</p>
<p>Lastly, we come to JSF 2.0 which was forged from JSF 1.2 and the litany of complaints about it. The JSR group looked at the solutions out in the wild that already work around those problems (many of which were written by people in that very group) and incorporates those fixes in a standard JSF API type of way. Primarily we have the dropping of JSP as the default view in exchange for the Facelets / JSF templating solution. This also lent itself very well to easier component creation including no-code components. There is now zero configuration required except for the servlet in <code>web.xml</code> and managed beans can now be defined using annotations. Navigation which also used to be in the <code>faces-config.xml</code> is also more convention of configuration. Another big request was the inclusion of AJAX awareness in the JSF lifecycle . It provides the bare minimum features that 3rd party developers can build upon using the standard API instead of their own AJAX solutions. There is better support for GET requests and page parameters as well as invoking actions on page requests which is a feature often used in Seam.<br />
There is also some performance boosts with regards to re-working state saving and the resource access mechanisms have been improved a great deal.</p>
<p>Also noteworthy is the inclusion of <a href="http://www.seamframework.org/Weld">Weld CR 1</a> which is the reference implementation of <a href="http://jcp.org/en/jsr/detail?id=299"> JSR 299 &#8211; Java Contexts and Dependency Injection </a> from JBoss. Admittedly, I haven&#8217;t really gotten round to taking a look at it, but from what I have seen and read so far, it looks like it fills some gaps in the JEE 6 platform and is up to par with the new found simplicity and strength that JEE 6 is promoting right now.</p>
<p>Overall, this is a pretty exciting set of tools and framworks and well worth a look if you are interested in adopting a standards based stack. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/glassfish-netbeans-and-jsf-2-0-test-drive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logging Conversation Demarcation In Seam</title>
		<link>http://www.andygibson.net/blog/tutorial/logging-conversation-demarcation-in-seam/</link>
		<comments>http://www.andygibson.net/blog/tutorial/logging-conversation-demarcation-in-seam/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 15:24:12 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=533</guid>
		<description><![CDATA[One way to see where your conversations start and end is to use the Seam event model to observe the conversation start and ends. 

@Name(&#34;conversationListener&#34;)
@Scope(STATELESS)
public class ConversationListenerBean implements ConversationListener {

	@Logger
	private Log log;

	@In
	private Conversation conversation;

	@Observer(value=&#34;org.jboss.seam.beginConversation&#34;)
	public void observeConversationStart() {
		log.debug(&#34;Conversation #0 Started&#34;,conversation.getId());
	}

	@Observer(value=&#34;org.jboss.seam.endConversation&#34;)
	public void observeConversationEnd() {
		log.debug(&#34;Conversation #0 Ended&#34;,conversation.getId());

	}
}

Just add this bean into your project and it will automatically log [...]]]></description>
			<content:encoded><![CDATA[<p>One way to see where your conversations start and end is to use the Seam event model to observe the conversation start and ends. </p>
<pre class="brush: java;">
@Name(&quot;conversationListener&quot;)
@Scope(STATELESS)
public class ConversationListenerBean implements ConversationListener {

	@Logger
	private Log log;

	@In
	private Conversation conversation;

	@Observer(value=&quot;org.jboss.seam.beginConversation&quot;)
	public void observeConversationStart() {
		log.debug(&quot;Conversation #0 Started&quot;,conversation.getId());
	}

	@Observer(value=&quot;org.jboss.seam.endConversation&quot;)
	public void observeConversationEnd() {
		log.debug(&quot;Conversation #0 Ended&quot;,conversation.getId());

	}
}
</pre>
<p>Just add this bean into your project and it will automatically log when you start and end conversations. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/logging-conversation-demarcation-in-seam/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Notes On Choosing A Web Framework</title>
		<link>http://www.andygibson.net/blog/article/notes-on-choosing-a-web-framework/</link>
		<comments>http://www.andygibson.net/blog/article/notes-on-choosing-a-web-framework/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 13:24:47 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Wicket]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=549</guid>
		<description><![CDATA[I&#8217;m looking at starting a new project and once again find myself choosing between frameworks. Having spent some time evaluating different ones I wrote up some notes to share and get some feedback that might alter my thoughts or opinions. Here&#8217;s the criteria I&#8217;m using to choose a framework in no particular order.

IDE Support &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m looking at starting a new project and once again find myself choosing between frameworks. Having spent some time evaluating different ones I wrote up some notes to share and get some feedback that might alter my thoughts or opinions. Here&#8217;s the criteria I&#8217;m using to choose a framework in no particular order.<br />
<span id="more-549"></span></p>
<p><strong>IDE Support</strong> &#8211; I would like to get as much IDE support as possible for auto completion, code validation and general helpfulness.</p>
<p><strong>Resume Building</strong> &#8211; How much demand is there for the skills? I&#8217;m looking to bolster my skills that have wide adoption in the industry. As this is an important factor, it also means I probably won&#8217;t be choosing a framework that I am already very familiar with. I&#8217;ll be using job trends and opinion to determine the industry support for the frameworks. I know job sites aren&#8217;t the best measure, especially since many ads are stuffed with buzzwords so they appear in searches even if there is no JSF, JAXB or JAX-WS involved. However, the fact that they are included at all indicates some kind of market penetration of the technology.</p>
<p><strong>Ajax Support</strong> &#8211; How well does it support Ajax natively out of the box as opposed to requiring third party libraries and are there de-facto standard libraries for that framework if they are needed.</p>
<p><strong>Templating / Layout</strong> &#8211; How are pages built and organized to enable reusable HTML without using include statements everywhere or some other mechanism which will require every page to be edited if the layout is changed. I think facelets is the best page layout library out there as it pulls the template into the page and then pushes the content from the page into the template making separate files optional. Tiles requires separate definition files and does a similar thing outside of the page being rendered. Sitemesh is non invasive and works by decorating existing pages as they are sent to the client. In terms of writing actual pages, the choices are Jsp, Velocity and Freemarker, of which JSP and Velocity are the two most in demand.</p>
<p><strong>Completeness</strong> &#8211; How much is in the framework out of the box without requiring additional libraries for core functionality. Obviously, you are going to need libraries for things like data access, but the framework should be able to put text in a page without requiring third party libraries. One other aspect of this is how easy it is to get up and running without having to get different pieces configured and talking to each other. Some frameworks discussed here like Spring MVC and JSF are not meant to be complete frameworks but a framework onto which to build other frameworks (like Servlets). In these cases, the frameworks are expanded by third party libraries so completeness is not so much a factor here. Third party libraries integrated as part of the stack is acceptable (i.e. Sitemesh in Grails and Richfaces in Seam).</p>
<p><strong>Custom Paginated Tables with Sortable Columns</strong> &#8211; This is my barrier for determining how powerful and easy a framework is to use. Simple CRUD is trivial to write, it&#8217;s like hello world for the web so I usually go for a more robust litmus test by writing some pagination code. Action frameworks require you to chug all the parameters backwards and forwards and handle your own binding and determining whether a page was selected or next/previous was clicked while Component frameworks handle most of that for you. For the same reason, clickable columns can be a real pain. For bonus points, how easy is it to implement multiple paginated / sortable tables? </p>
<p><strong>Statefulness</strong> &#8211; Can we integrate some kind of stateful mechanism in there (i.e Spring Web Flow) cleanly? There are a few scenarios where I will need a stateful workflow in the application.</p>
<p><strong>Third Party Support and integration</strong> &#8211; One annoying aspect of java web development is all the pieces and parts that need to be strung together and then you have to get them to play nicely. This is really about the path of least surprise, and not having to deal with issues because I add libraries that don&#8217;t have special mechanisms for working with each other.. I.e Spring MVC embraces Tiles, but how much of a hassle is it to incorporate Velocity with Tiles? This issue is also somewhat redundant for those frameworks that include built-in solutions for most needs. </p>
<p>The application is going to be moderate in size, but hopefully growing as time goes on. For that reason, I&#8217;m looking for something flexible enough to grow and refactor later on. Initially, I&#8217;m also looking for something lightweight and will be looking to deploy it on Tomcat primarily due to ease of hosting. </p>
<h1>Action or Component Based</h1>
<p>I find Action frameworks are great for catalogs and simple CRUD pages but when you start getting to more complex web applications pages, things get much tricker. Take for example a search page with 10 search parameters, suddenly you find yourself having to attach 10 parameters to the next/previous/first/last result links or using javascript funkiness to modify form contents to change the form state and post the form. Add column ordering and things get pretty messy quickly. In my mind, For a web application, any search pages (or other pages that require pagination or other common interface elements) should be trivial to write within minutes. Obviously, if you are Google and your main business is that one search page, you can afford to spend a little more time on it and be as choosy as you like on how to implement it. However, it never fails to amaze how much code people will write to create a single page demonstrating how to do some simple function in a non-reusable way. User interface elements like pagination and column ordering should be totally reusable. </p>
<h1>The Contenders</h1>
<p>Here are the contenders in no specific order</p>
<ul>
<li>Seam with JSF</li>
<li>Wicket</li>
<li>JSF</li>
<li>Grails</li>
<li>Spring MVC with JSP</li>
<li>Spring MVC with JSF</li>
</ul>
<p>First lets look at the job trends for these different frameworks :</p>
<div style="width:540px">
<a href="http://www.indeed.com/jobtrends?q=spring+java%2C+ejb+java%2C+jsf+java%2C+%22spring+mvc%22+java%2C+wicket+java%2C+seam+java%2C+grails+java" title="spring java, ejb java, jsf java, &#034;spring mvc&#034; java, wicket java, seam java, grails java Job Trends"><br />
<img width="540" height="300" src="http://www.indeed.com/trendgraph/jobgraph.png?q=spring+java%2C+ejb+java%2C+jsf+java%2C+%22spring+mvc%22+java%2C+wicket+java%2C+seam+java%2C+grails+java" border="0" alt="spring java, ejb java, jsf java, &#034;spring mvc&#034; java, wicket java, seam java, grails java Job Trends graph"><br />
</a></p>
<table width="100%" cellpadding="6" cellspacing="0" border="0" style="font-size:80%">
<tr>
<td><a href="http://www.indeed.com/jobtrends?q=spring+java%2C+ejb+java%2C+jsf+java%2C+%22spring+mvc%22+java%2C+wicket+java%2C+seam+java%2C+grails+java">spring java, ejb java, jsf java, &#034;spring mvc&#034; java, wicket java, seam java, grails java Job Trends</a></td>
<td align="right"><a href="http://www.indeed.com/q-spring-java-jobs.html">spring java jobs</a> &#8211; <a href="http://www.indeed.com/q-ejb-java-jobs.html">ejb java jobs</a> &#8211; <a href="http://www.indeed.com/q-jsf-java-jobs.html">jsf java jobs</a> &#8211; <a href="http://www.indeed.com/jobs?q=%22spring+mvc%22+java">&#034;spring mvc&#034; java jobs</a> &#8211; <a href="http://www.indeed.com/q-wicket-java-jobs.html">wicket java jobs</a> &#8211; <a href="http://www.indeed.com/q-seam-java-jobs.html">seam java jobs</a> &#8211; <a href="http://www.indeed.com/q-grails-java-jobs.html">grails java jobs</a></td>
</tr>
</table>
</div>
<p>We can see a sort of multi-tier system in place for different frameworks. Spring and EJB both rank up there as first tier technologies. I&#8217;ve already had quite a bit of experience with both of these but Spring is at an advantage with regards to being lightweight and running in tomcat without having to worry about setting up an embedded EJB container. Writing something with EJB 6 might be a possibility, but I think it more likely I&#8217;ll try and use Spring.</p>
<p>Now lets consider the view frameworks :</p>
<div style="width:540px">
<a href="http://www.indeed.com/jobtrends?q=+jsf+java%2C+%22spring+mvc%22+java%2C+wicket+java%2C+seam+java%2C+grails+java" title="jsf java, &#034;spring mvc&#034; java, wicket java, seam java, grails java Job Trends"><br />
<img width="540" height="300" src="http://www.indeed.com/trendgraph/jobgraph.png?q=+jsf+java%2C+%22spring+mvc%22+java%2C+wicket+java%2C+seam+java%2C+grails+java" border="0" alt="jsf java, &#034;spring mvc&#034; java, wicket java, seam java, grails java Job Trends graph"><br />
</a></p>
<table width="100%" cellpadding="6" cellspacing="0" border="0" style="font-size:80%">
<tr>
<td><a href="http://www.indeed.com/jobtrends?q=+jsf+java%2C+%22spring+mvc%22+java%2C+wicket+java%2C+seam+java%2C+grails+java">jsf java, &#034;spring mvc&#034; java, wicket java, seam java, grails java Job Trends</a></td>
<td align="right"><a href="http://www.indeed.com/q-jsf-java-jobs.html">jsf java jobs</a> &#8211; <a href="http://www.indeed.com/jobs?q=%22spring+mvc%22+java">&#034;spring mvc&#034; java jobs</a> &#8211; <a href="http://www.indeed.com/q-wicket-java-jobs.html">wicket java jobs</a> &#8211; <a href="http://www.indeed.com/q-seam-java-jobs.html">seam java jobs</a> &#8211; <a href="http://www.indeed.com/q-grails-java-jobs.html">grails java jobs</a></td>
</tr>
</table>
</div>
<h1>Seam / JSF</h1>
<p>I&#8217;ve had a lot of experience with these two so it&#8217;s easy to comment on. Great IDE support (probably the best), great out of the box support, but it can feel foreign to use on Tomcat where it doesn&#8217;t offer such a rich a developer experience. Great Ajax support, but not so great for the resume since I already have a lot of experience with Seam and there are very few Seam jobs out there.</p>
<table style="width: 100%; font-size: 90%">
<tr>
<th colspan=4>Seam</th>
</tr>
<tr>
<td><strong>IDE Support</strong></td>
<td>Excellent &#8211; JBoss Tools</td>
<td><strong>Demand</strong></td>
<td>Poor</td>
</tr>
<tr>
<td><strong>Ajax Support</strong></td>
<td>Excellent &#8211; Richfaces</td>
<td><strong>Templating</strong></td>
<td>Excellent &#8211; Facelets</td>
</tr>
<tr>
<td><strong>Pagination</strong></td>
<td>Excellent &#8211; reusable component based pagination</td>
<td><strong>Completeness</strong></td>
<td>Excellent</td>
</tr>
<tr>
<td><strong>Statefullness</strong></td>
<td>Excellent &#8211; Conversational scope</td>
<td><strong>3rd Party Library Integration</strong></td>
<td>Ok &#8211; Seam likes things to run a certain way</td>
</tr>
</table>
<h1>JSF</h1>
<p>Despite using Seam a lot, writing a straight JSF application is still quite different and poses a number of challenges. It might be a interesting using just JSF but I have most of that ground covered with my existing JSF work. JSF is in-demand though and this might be an opportunity to use it with other frameworks such as a Spring/Hibernate/JSF combination. It has great Ajax support with multiple frameworks available, but no decent IDE support even though JBoss Tools works well on plain JSF apps without Seam. It may also get frustrating since I&#8217;ll be having constant reminders of how easy things are when you use Seam. Facelets is a great templating framework, if not the best, and I&#8217;d probably go to JSF 2.0 so I can use annotated beans. For statefulness, I could add in Orchestra and pagination should be simple with JSF although I think Seam (or JBoss-El) added ways to call methods (with parameters) on beans passed in to facelets which made it really easy. I haven&#8217;t been able to duplicate that with in JSF or Spring Faces which could be a problem. One annoyance of JSF is the inability to suppress validation when you post the form back but don&#8217;t want to save it which you may want to do as part of a web flow where you want to save the contents, go to another page, come back and finish your data entry. The only solution is to manually perform validation when the form is finally saved and not use JSF validators which is a limitation and I don&#8217;t thing this was fixed in JSF 2.0.</p>
<table style="width: 100%; font-size: 90%">
<tr>
<th colspan=4>JSF</th>
</tr>
<tr>
<td><strong>IDE Support</strong></td>
<td>Ok with JBoss Tools</td>
<td><strong>Demand</strong></td>
<td>Excellent</td>
</tr>
<tr>
<td><strong>Ajax Support</strong></td>
<td>Great with 3rd Party tools or JSF 2.0</td>
<td><strong>Templating</strong></td>
<td>Excellent &#8211; Facelets</td>
</tr>
<tr>
<td><strong>Pagination</strong></td>
<td>Good</td>
<td><strong>Completeness</strong></td>
<td>Ground framework</td>
</tr>
<tr>
<td><strong>Statefulness</strong></td>
<td>None without 3rd party libs like Apache Orchestra</td>
<td><strong>3rd Party Library Integration</strong></td>
<td>Excellent for JSF libs</td>
</tr>
</table>
<h1>Wicket</h1>
<p>Wicket is a great component based framework with good ajax support, a fine grained stateful architecture and because of it&#8217;s emphasis on the java language, good IDE support. Some people don&#8217;t like the heavy use of java code to build web pages, but it&#8217;s a personal thing and I do enjoy it. However, the only thing holding it back for me is the poor industry adoption with very few Wicket jobs. </p>
<table style="width: 100%; font-size: 90%">
<tr>
<th colspan=4>Wicket</th>
</tr>
<tr>
<td><strong>IDE Support</strong></td>
<td>Great since it is mostly java based</td>
<td><strong>Demand</strong></td>
<td>Poor &#8211; unfortunately</td>
</tr>
<tr>
<td><strong>Ajax Support</strong></td>
<td>Excellent &#8211; it comes with Ajaxified components</td>
<td><strong>Templating</strong></td>
<td>Excellent &#8211; Offers page inheritance and panels</td>
</tr>
<tr>
<td><strong>Pagination</strong></td>
<td>Excellent &#8211; reusable component based pagination</td>
<td><strong>Completeness</strong></td>
<td>Good</td>
</tr>
<tr>
<td><strong>Statefullness</strong></td>
<td>Excellent &#8211; Fine grained statefulness</td>
<td><strong>3rd Party Library Integration</strong></td>
<td>Great &#8211; although you won&#8217;t need or be able to use many web libraries (i.e. tiles, velocity etc) here.</td>
</tr>
</table>
<h1>Grails</h1>
<p>I tried to get back into Grails and again, I hit a number of snags. It&#8217;s a great framework, but I find it can be problematic. The IDE support was basic and I often had to clean the eclipse project then the grails project so it wouldn&#8217;t choke on old classes lying around. Netbeans also has Grails support, but was prone to hanging when you want to restart the server. It also lacked the refactoring / renaming features present in eclipse.  I also found problems in the framework itself such as not being able to model embedded classes that contained a reference to another entity. Other times, inexplicably, when I called <code>person.save()</code> nothing would happen, no error, no messages, nothing. I don&#8217;t doubt it was my fault and something I did, but it is off putting and frustrating in a framework that won&#8217;t tell you when you have a syntax error.</p>
<p>Grails and Wicket seem like polar opposites in some ways. Wicket is all about type safety and strict java code checked by the IDE. Grails on the other hand doesn&#8217;t often know when you make a mistake because its a dynamic language.  Developers shouldn&#8217;t have to write tests just to make sure you didn&#8217;t make any typo&#8217;s in your classes, people have spent a number of years and millions of dollars evolving IDEs to solve that very problem.</p>
<p>The dynamic language is all very nice, and Grails is a framework but when I&#8217;m building furniture, I don&#8217;t start out with aflat pack plywood cabinet and slowly replace each piece with half inch mahogany with hand cut dovetail joints in the name of being rapid and agile (umm, Agile Wordworking, there&#8217;s an idea). I can see the point, and for the most part, Grails is unobtrusive but I think for me,  on this project, I&#8217;d rather start out with a workbench and some planks of mahogany and craft it from scratch. </p>
<p>Ajax support is excellent and it also has many plugins which are easy to install and use. Writing taglibs is a breeze and very intuitive. Even pagination was fairly simple and I especially liked the paginator tag that takes a map of parameter values to include on all the previous/next/page links. Again, things are scarce on the job front for Grails, but being such a unique and productive tool I think there is a great future for Grails which lowers the importance of current trends. </p>
<p>Grails also supports Spring Web Flow but I&#8217;m not sure it allows the use of flow scoped persistence contexts. Sitemesh is used for templating and offers a lot of features out of the box. Overall it&#8217;s very impressive and definitely still a contender.</p>
<table style="width: 100%; font-size: 90%">
<tr>
<th colspan=4>Grails</th>
</tr>
<tr>
<td><strong>IDE Support</strong></td>
<td>Poor</td>
<td><strong>Demand</strong></td>
<td>Small but growing</td>
</tr>
<tr>
<td><strong>Ajax Support</strong></td>
<td>Excellent</td>
<td><strong>Templating</strong></td>
<td>Excellent &#8211; Sitemesh and easy taglibs</td>
</tr>
<tr>
<td><strong>Pagination</strong></td>
<td>Great</td>
<td><strong>Completeness</strong></td>
<td>Great &#8211; plugins make things easier</td>
</tr>
<tr>
<td><strong>statefulness</strong></td>
<td>Spring Web Flow </td>
<td><strong>3rd Party Library Integration</strong></td>
<td>Plugins make it really easy</td>
</tr>
</table>
<h1>Spring MVC with JSP</h1>
<p>This is probably the one I was most eager to tackle as I think this one probably has the most potential. Spring and JSP have been largely adopted within the industry, but are they any good? I think Spring MVC is excellent, especially with the new Spring 2.5 Controller annotations and Web Flow integration. As usual with Spring, it provides a lot of flexibility and it sits on the Core Spring Framework. For templating, I can use Sitemesh, Tiles, and it includes support for velocity and free marker. It appears that using both Tiles and Velocity together isn&#8217;t straightforward resulting in this third party <a href="http://anydoby.com/velocity/">plugin</a> to solve the problem.</p>
<p>Spring MVC doesn&#8217;t have any ajax support, <a href="http://static.springsource.org/spring/docs/2.0.x/reference/mvc.html">Chapter 13 &#8211; Web MVC Framework</a> of the Spring reference documentaton doesn&#8217;t even mention the word Ajax. Spring Web Flow has Ajax support but it requires the use of Tiles (or some other compatible templating library) for specifying page fragments to update. This is also requires that pages be designed in such a way that the Ajax updatable pieces are clearly defined in the page definition which is outside of the page being designed. With Richfaces you can create a fragment in the page just by using an output panel tag and giving it a name. Another problem with Spring Web Flow is the inability to use an Open Session In View alongside the Flow Managed Persistence context which means having to work around Lazy Initialization Issues in other ways. On the plus side though, you can make validation optional in Spring Web Flow if you are using the Spring Validators and not JSF.</p>
<table style="width : 100%;font-size : 90%">
<tr>
<th colspan=4>Spring MVC with JSP </th>
</tr>
<tr>
<td><strong>IDE Support</strong></td>
<td>Good &#8211; Spring IDE</td>
<td><strong>Demand</strong></td>
<td>Excellent</td>
</tr>
<tr>
<td><strong>Ajax Support</strong></td>
<td>Poor</td>
<td><strong>Templating</strong></td>
<td>3rd Party</td>
</tr>
<tr>
<td><strong>Pagination</strong></td>
<td>Roll Your Own</td>
<td><strong>Completeness</strong></td>
<td>Spring MVC offers a solid ground on which to build</td>
</tr>
<tr>
<td><strong>statefulness</strong></td>
<td>Spring Web Flow</td>
<td><strong>3rd Party Library Integration</strong></td>
<td>Good</td>
</tr>
</table>
<h1>Spring MVC with JSF / Spring Faces</h1>
<p>If I couldn&#8217;t find a way to reconcile the problems with Spring MVC and JSP, this would be my backup as it solves a number of problems with using Spring MVC and JSP. It fixes the Ajax and templating issues since I can use a JSF based Ajax framework (IceFaces or Richfaces) and Facelets for superior templating. The only problems here is a resource issue for JSF and the fact that I have already worked with JSF extensively. However, I have found Spring Faces to be a great library to use with some nice extensions. While there are only a few jobs explicitly mentioning Spring Faces, there are many jobs involving Spring and JSF. While spring web flow de-couples your view from the back end, it can be a little too decoupled. For example, within a flow, to call a method from a command button and refresh some data requires you to call the method and return an action string that would trigger the refresh of the data in the web flow. In Seam, you can get away with just calling the method and then refreshing the data. Spring Web Flow, forces you to decouple that which makes for a lot more work when you have multiple links that can trigger a refresh of the data. It also doesn&#8217;t fix the open session in view / flow managed persistence context clash. Writing JSF pages outside of a web flow means having to work directly with Spring beans as Jsf backing beans as opposed to dealing with Spring Beans through the web flow. This isn&#8217;t a big deal though, it just means you have two separate styles of writing code.  Even though Spring Web Flow lets you suppress validations for flow transitions, It doesn&#8217;t have any effect when you are using JSF for the view, only when you are using Spring validations.</p>
<table style="width: 100%; font-size: 90%">
<tr>
<th colspan=4>Spring MVC with JSF / Spring Faces</th>
</tr>
<tr>
<td><strong>IDE Support</strong></td>
<td>Good &#8211; JBoss Tools for JSF and Spring IDE</td>
<td><strong>Demand</strong></td>
<td>Great &#8211; Spring and JSF Combination</td>
</tr>
<tr>
<td><strong>Ajax Support</strong></td>
<td>Excellent</td>
<td><strong>Templating</strong></td>
<td>Excellent &#8211; Facelets</td>
</tr>
<tr>
<td><strong>Pagination</strong></td>
<td>Good</td>
<td><strong>Completeness</strong></td>
<td>Good</td>
</tr>
<tr>
<td><strong>statefulness</strong></td>
<td>Soring Web Flow</td>
<td><strong>3rd Party Library Integration</strong></td>
<td>Good</td>
</tr>
</table>
<h1>Summary</h1>
<p>Ultimately, it boils down to Grails or Spring MVC with JSP and probably Tiles and if I can&#8217;t find a solution there, Spring MVC with JSF. I f career/employment was not a factor, I would pick Wicket with Spring in a second, however, as I&#8217;m looking to bolster my resume and make sure my bona fides are in order for the more popular technologies.</p>
<p>All in all, it&#8217;s a difficult choice, but I&#8217;d love to get some more thoughts on the matter. I&#8217;m sure there are plenty of opinions on frameworks out there in The java community <img src='http://www.andygibson.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /><br />
<script type="text/javascript">var dzone_url = 'http://www.andygibson.net/blog/index.php/2009/09/25/notes-on-choosing-a-web-framework/';</script><br />
<script type="text/javascript">var dzone_title = 'Notes On Choosing A Web Framework';</script><br />
<script type="text/javascript">var dzone_blurb = 'Yet another write up of my ongoing evaluation of different web frameworks for a new Java project';</script><br />
<script type="text/javascript">var dzone_style = '1';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/notes-on-choosing-a-web-framework/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Seam vs Spring Web Flow &#8211; vs Wicket</title>
		<link>http://www.andygibson.net/blog/article/seam-versus-spring-web-flow-versus-wicket/</link>
		<comments>http://www.andygibson.net/blog/article/seam-versus-spring-web-flow-versus-wicket/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 00:19:44 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Wicket]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=367</guid>
		<description><![CDATA[In the fifth part of this four part series, I decided to give a non-conversational framework a try and implemented the same application with Wicket which is a semi-stateless framework.  
(update : If you have already read the previous version only chapter 5 is new and has the Wicket example and final comparison.)
Enjoy,
HTML
Single Page [...]]]></description>
			<content:encoded><![CDATA[<p>In the fifth part of this four part series, I decided to give a non-conversational framework a try and implemented the same application with Wicket which is a semi-stateless framework.  </p>
<p>(<b>update</b> : If you have already read the previous version only chapter 5 is new and has the Wicket example and final comparison.)</p>
<p>Enjoy,</p>
<p><a href="http://www.andygibson.net/articles/seam_spring_comparison/html/index.html">HTML</a><br />
<a href="http://www.andygibson.net/articles/seam_spring_comparison/html_single/">Single Page HTML</a><br />
<a href="http://www.andygibson.net/articles/seam_spring_comparison/pdf/SeamSpringComparison.pdf">PDF</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/seam-versus-spring-web-flow-versus-wicket/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Timing JSF Requests Using a Phase Listener</title>
		<link>http://www.andygibson.net/blog/tutorial/timing-jsf-requests-using-a-phase-listener/</link>
		<comments>http://www.andygibson.net/blog/tutorial/timing-jsf-requests-using-a-phase-listener/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 03:55:04 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=295</guid>
		<description><![CDATA[One easy way of determining how long it takes to return a page from Seam, and/or JSF is to use a phase listener. This phase listener below  logs the end of each phase of the JSF lifecycle and measures the time from the start of the RESTORE_VIEW phase (the first phase in the lifecycle [...]]]></description>
			<content:encoded><![CDATA[<p>One easy way of determining how long it takes to return a page from Seam, and/or JSF is to use a phase listener. This phase listener below  logs the end of each phase of the JSF lifecycle and measures the time from the start of the <code>RESTORE_VIEW</code> phase (the first phase in the lifecycle and the start of the request) to the end of the <code>RENDER_RESPONSE</code> phase which is the last one. Logging the end of each stage of the cycle lets you see what else is going on during each phase of the cycle. </p>
<pre class="brush: java;">
public class LogPhaseListener implements PhaseListener {

	public long startTime;

	private static final LogProvider log = Logging
			.getLogProvider(LogPhaseListener.class);

	public void afterPhase(PhaseEvent event) {
		if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
			long endTime = System.nanoTime();
			long diffMs = (long) ((endTime - startTime) * 0.000001);
			if (log.isDebugEnabled()) {
				log.debug(&quot;Execution Time = &quot; + diffMs + &quot;ms&quot;);
			}
		}
		if (log.isDebugEnabled()) {
			log.debug(&quot;Executed Phase &quot; + event.getPhaseId());
		}
	}

	public void beforePhase(PhaseEvent event) {

		if (event.getPhaseId() == PhaseId.RESTORE_VIEW) {
			startTime = System.nanoTime();
		}
	}

	public PhaseId getPhaseId() {
		return PhaseId.ANY_PHASE;
	}

}
</pre>
<p>To use this, simply add the class to your project and insert a new phase listener in the <code>faces-config.xml</code> file.</p>
<pre class="brush: xml;">
  &lt;lifecycle&gt;
    &lt;phase-listener&gt;package.name.LogPhaseListener&lt;/phase-listener&gt;
  &lt;/lifecycle&gt;
</pre>
<p>While it may not be totally accurate, it at least gives you an idea of the scale of the duration of a request (i.e. 68ms versus 394ms). I&#8217;ve used this fairly effectively in a few projects to cut out some bottlenecks as well as comparing and contrasting different JSF frameworks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/timing-jsf-requests-using-a-phase-listener/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
