YOUR FEEDBACK
José D'Andrade wrote: "...it may never be released..." Why? "...if Midori isn’t heir to Windows Mi...


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TOP THREE LINKS YOU MUST CLICK ON


Seam: The Next Step in the Evolution of Web Applications
A powerful new application framework for managing contextual components

Web sites were originally static. Later dynamic content came about through CGI scripts paving the way for the first true Web applications. Since HTTP was entirely stateless, it became necessary to invent ways for requests to be linked together in a sequence. At first state was added to the URLs, but later the cookie concept came into being. By giving each user a special token, the server could maintain a context for each user, the HTTP session where the application can store state. As simple as it is, the HTTP session defines the entire concept of what a Web application is today.

The benefits of the HTTP session are clear, but we don't often stop to think about the drawbacks. When we use the HTTP session in a Web application, we store the sum total of the state of the user's interaction with the application in one place. This means that unless we jump through some seriously complex hoops, the user can only interact with an application in one way at a time.

Consider an application that manages a set of paged search results stored in the HTTP session. If the user were to start a new search in a new window, the new search would overwrite any previous session-scoped results. That's painful enough, but multitasking users aren't the only way session-scoped data causes Web applications to explode.

Consider our friend the back button, the mortal enemy of nearly every Web developer. When a user goes backwards in time to a previous page and presses a button, that application invocation expects to be associated with an HTTP session state that may have subsequently changed. When your application only has one context to store state, there's little hope of creating anything but the fragile Web applications that we all struggle with.

Most applications deal with this by adding state to the URLs, either going back to manually putting state information in the URLs or by adding a cookie-like token in the URL to point to a finer-grained context than the HTTP session. This can force the developer to pay a lot of attention to state management, often spending more time on it than on writing the actual application.

JBoss Seam
This article introduces JBoss Seam, a framework for managing contextual components. You'll see how Seam can manage state information in a Web application, overcoming the fundamental limitations of the HTTP session and enabling entirely new contexts that dramatically extend the capabilities of Web applications. It does all of this while simplifying your Web application development and reducing the amount of code (and XML) you have to write.

Seam is a framework for managing contextual components. What does that mean? Let's first look at a component. They go by many names: JavaBeans, POJOs, Enterprise JavaBeans. They're Java classes that provide some type of function to your application. A Java EE application might have many kinds of components: JSF backing beans creating the Web tier, entity beans providing persistence, and session beans providing business logic. To Seam, they're all components. Seam unifies these diverse component models, letting you think of them all as simply application components.

A Quick Example
The best way to see what Seam can do is to look at some examples. These examples are derived from the Seam DVD Store application. You can see the complete application in the examples directory of the Seam distribution. We'll start with a simple EJB3 entity bean for a product.

@Entity
@Name("product")
public class Product
    implements Serializable
{
     long id;
     String title;
     String description;
     float price;

     @Id @GeneratedValue(strategy=AUTO)
     public long getId() {
       return id;
     }
     public void setId(long id) {
       this.id = id;
     }

     public String getTitle() {
       return title;
     }
     public void setTitle(String title) {
       this.title = title;
     }

     // more getters and setters.
}

This is an EJB3 entity bean, a POJO with a couple of annotations. The only thing that stands out here is the @Name annotation, which marks it as a Seam component named product. We'll see later how this affects things. For now let's move on to an application component that displays a list of all the products in the system.

@Stateful
@Name("search")
@Interceptors(SeamInterceptor.class)
public class SearchAction
     implements Search
{
     @PersistenceContext(type=EXTENDED)
     private EntityManager em;

     @Out
     private List<Product> products;

     @Factory("products")
     public void loadProducts()
     {
       products = em.createQuery("from Product p")
       .getResultList();
     }
}

This is a stateful EJB3 session bean. We've marked it as a Seam component using the @Name annotation and brought in Seam functionality with the SeamInterceptor. Ignoring the remaining Seam annotations for a moment, what we have here is a simple component that keeps track of a list of Product objects.

The loadProducts() method uses the EJB3 persistence API to load that list of products. It makes use of EJB3 dependency injection to receive an EntityManager instance from the container so that it can load the the products into the product list.

The goal of this component is to provide this list of products to the UI. The @Out annotation on the product list does this. @Out marks the list as data to be shared out to the UI.

Let's jump forward to the view. This is part of the Facelets XHTML template, but for our purposes you can think of it as a JSP file that uses the JavaServer Faces tag libraries. The dataTable tag renders the list of items in table form using the three column definitions: title, description, and price.

<h:dataTable value="#{products}" var="prod">
   <h:column>
     <f:facet name="header">title</f:facet>
     #{prod.title}
   </h:column>
   <h:column>
     <f:facet name="header">description</f:facet>
     #{prod.description}
   </h:column>
   <h:column>
     <f:facet name="header">price</f:facet>
     #{prod.price}
   </h:column>
</h:dataTable>

The search component provides the products value for the table to the view, but how does the value get populated in the view? The @Factory annotation on the loadProducts() method tells Seam that if a view needs a products value, the loadProducts() method can be used as a factory method to load the products from the database.

There's something else happening here. SearchAction is a stateful session bean, and the product's value is just part of its state. Stateful components have a lifecycle. They have to be created, kept around, and eventually destroyed. In Seam, stateful components have the lifecycle of their surrounding context. If a stateful component were session-scoped, for example, it would be stored in the HTTP session and destroyed when the HTTP session is destroyed, unless it reaches its natural end of life sooner.

We mentioned earlier that Seam has several more interesting contexts than just simple session-scoped data. Stateful components, by default, have conversational scope. A conversation is a sequence of clicks within a Web application. You can think of it as an actual conversation with part of the application. You interact with one part of the application for a few clicks and say good-bye, maybe moving on to some other part of the application.

About Norman Richards
Norman Richards is a JBoss developer living in Austin, Tx. He is co-author of JBoss: A Developer's Notebook and XDoclet in Action.

YOUR FEEDBACK
Marcus wrote: After all, we all know PHP can be used to write any kind of full featured servers, including a web server. OPS, Php is not multithread. Suck =/
m wrote: The distinction of "java vs 'dynamic' languages' is misleading. Java is also 'dynamic' because it uses dynamic, late binding (between invocation and implementation) at run-time. The more important differences here are whether a language is strongly typed and whether a language is a 'scripting' language or not. Strongly typed languages validate invocation parameters against declared parametric signatures - a general purpose feature that is known to help catch errors earlier in development. A weakly typed language can be easier to get up & running without having to fully flesh out one's object/type models, but can be vulnerable to unexpected runtime results that are hard to debug. A 'scripting' language is a language whose compilation unit consists of a discrete segment of source code (i.e. a statement) that is relatively small compared to a complete logical or source module. A 'compi...
Tuomas wrote: Do you have seen JASCO language (see: http://ssel.vub.ac.be/jasco/ )? It is like a dynamic aspect *java* language, which has many good sides of ascpetj, but has many more, dynamic properties. Does somebody done something commersiell with JASCO?
Matt L. wrote: Here is how I would define a scripting/dynamic language: a language that allows developers to quickly write code by deferring bug discovery until runtime instead of compile time. If your goal is to get software up and running quickly, then perhaps a scripting/dynamic language is the right answer. However, software costs are primarily driving by quality and maintenance. It is well established that the cost of fixing bugs increases dramatically the later they are found. Compiled languages allow an upfront investment to be made in terms of quality and maintainability. In my view, this is the primary benefit of using a compiled language.
David J. wrote: I recently learned that the second "round" of a "debate" is for each person to criticize his/her own arguments. Also, being an experienced software engineer with a B.S. degree in Computer Science, and being having practical programming experience using C, C++, Java, SmallTalk, UNIX, Objective-C, AppleScript, Perl, and PHP, I find myself to be an exception to Ryan Tomayko's "mild accusation" (I mean that seriously) that those who like Java were somehow "lured" into it and never explored other technologies. (I believe that's what he said.) Concerning the term: "Dynamic Languages": I have never described certain "languages" that instruct a "Turing Machine" as "dynamic". I was taught that that certain "computer languages", for lack of a better term (i.e.: English, French, Japanese, etc.), ran on a "runtime model". Exception - (First: Pre-qualifying my possible ignorance here.) If a...
Jasen Halmes wrote: I just sat through a presentation that included a description of Sun's new scientific programming language Fortress. It is described as a compile on demand language, no byte code. So basically the future of programming languages according to sun is a scripting languge.
Gary Renner wrote: I agree with Gosling almost 100%. We have a glut of scripting languages and they "do" get their simplicity at the expense of general purpose features like strong type checking and strong exception handling. Web oriented scripting languages "can" be used for other purposes in the same way that SQL can be used to write non-database applications. But why go there? The problem with the proliferation of languages is that it divides the workforce and wastes their time re-writing applications in new languages. If we want special purpose simplicity - we should use graphical application generators.
Paul wrote: Insightful, funny, relevant. IMHO, Mr Gosling is a living legend, but he's also got something to sell and it skews his message sometimes. I WISH I could get my employer to take Dynamic Languages seriously, but the corporate world is a little backwards, and managers typically out-of-the-technology-loop, so static is often the order of the day. For now.
Mike Mosiewicz wrote: Just one note on scallability. Most php-scales-well rants based on share-nothing horizontal scallability are fine unless you hit a problem that is related to modifying/storing information not only reading. In such case the story is totally different. And it's the fuel that drives development of so called enterprise architectures.
alderete wrote: I don't understand what all the fuss is. Who cares what James Gosling thinks? He's an obviously interested party, with a party line to spew. There are lots of industry luminaries, all spewing their corporate lines. The thing is, as you point out in your article, the knowledge that this is spew is well-documented. Either now or in months or in years, everyone who can have their mind opened will have their mind opened, just by the current motion and inertia that platforms like Rails and PHP possess today. By arguing with Gosling, it's making his words more legitimate. Like there's a debate here. There's no need for debate. We don't need to prove him wrong with articles and blog posts. We just need to keep successfully building real, working systems using the tools that we feel are appropriate. As the current Nike commercial (running during college basketball) says, "Let your...
Mike wrote: Ok since your beating gosling up, you really should know the facts as well, for instance Ruby really doesn't scale well and it doesn't support unicode so most web dev is out. Its a nice tool language but not for real apps, sure the mom and pop usa based shops it will work for a bit but get real. I think all of the languages out there are useful, they are all being used...none of them do it all nor should the always be used. So please stop the childish rants about Java and use what you want, if you don't like something leave it alone
Anjan Bacchu wrote: hi there, James Gosling did a lot of work on LISP to build Emacs. I guess there's a perspective of someone who's done a whole breadth of applications using Java. We all know that Ruby/Python can be used for 80% of the applications that Java can be used. But we know (from the 80/20 rule) that the only 20% of the journey is done when you say that 80% work is done. The last 20% takes 80% of the effort. If you're happy with the 80% work, fine. When he specifically says that breadth is NOT there in the other languages, you should NOT jump to conclusions about his motives. If you ask Bjarne Stroustrup about C++, he is known to defend C++'s successes in a wide area of applications (which is wider than Java's). Gosling has higher motivation than Bjarne ever did to keep his created language going but at the same time we should not put ignorance and ill-motives. Even though one tends t...
Harry Fuecks wrote: Perhaps it's time to nail down the term scripting language - my vote goes for "Anything with a virtual machine is scripting language" - then James might not feel so left out.
George wrote: What is a scripting language? I mean, what's the bare bones of it, technically speaking? It is a language executed as script. That means it is called (from somewhere), then loaded, executed and ends, that's all, and what concerns me, I'm perfectly fine with that. It's the same for me if it is interpreted, pre-compiled into P-code (or similar) or executable, CGI or Fast-CGI, module or stand-alone, as long as it behaves like intended I'll be fine. So why all the fuss about it? Why does Gosling mention it anyway, why are so many users/programmers upset with the term "only scripting"? I think the main reason is that there are different programming philosophies behind the kind PHP (Ruby, Perl etc.) on the one side is used in programming and Java is on the other side. That's all, simple as that. Whereas a "scripting" language is executed and dies afterwards (which has its advantages like...
George wrote: What is a scripting language? I mean, what's the bare bones of it, technically speaking? It is a language executed as script. That means it is called (from somewhere), then loaded, executed and ends, that's all, and what concerns me, I'm perfectly fine with that. It's the same for me if it is interpreted, pre-compiled into P-code (or similar) or executable, CGI or Fast-CGI, module or stand-alone, as long as it behaves like intended I'll be fine. So why all the fuss about it? Why does Gosling mention it anyway, why are so many users/programmers upset with the term "only scripting"? I think the main reason is that there are different programming philosophies behind the kind PHP (Ruby, Perl etc.) on the one side is used in programming and Java is on the other side. That's all, simple as that. Whereas a "scripting" language is executed and dies afterwards (which has its advantages like...
petrIlli wrote: The reality is that large chunks of Mission Control @ NASA as well as the Space Telescope Sciences Institute (the people who run the Hubble) use Python to manage their missions to interplanetary destinations. This was true a few years ago, anyway. The idea that Java is somehow capable of a larger breadth of problems is absurd. It may have a better fit to some problems - though I've yet to figure out what those are, other than increasing my use of mediocre developers - the Turing completeness proves this false. As for scalability. It might affect you, it probably doesn't. Worry about it if it does. The number of customers I run into who think they have "scalability" issues is mindbogglingly huge. The number who actually have it? Almost zero. I've had 1 customer in 10 years who had a real challenge. The rest are just fooling themselves into buying into a more complex solution becaus...
LATEST JAVA STORIES & POSTS
The pressure is on to keep pace with Web 2.0 entrants into the marketplace. Rewriting is expensive; adding AJAX widgets results in a complex, unmaintainable application. Both require you to hire scarce JavaScript developers. Google Web Toolkit -- the SDK that allows you to write ...
SQL Injection attacks are one of the easiest ways to hack into a website. One recent hack, using a script from verynx.cn, involves injecting sql into a web form that then appends some JavaScript code into fields in a database that then gets executed on the client side when a user...
jQuery is a rapidly growing, popular JavaScript library. Its powerful and modular architecture, which emphasizes a simple yet heavily extensible API, has helped it to become one of the most popular Javascript Libraries. Because of its dead-simple plug-in architecture, many even b...
SOA World Magazine announced today that the polls are now open for the SOA World Magazine Readers' Choice Awards, which recognize excellence in the software, solutions, or services provided by the industry's top vendors. Readers will be casting their votes until November 8, 2008....
JavaScript 2 is becoming increasingly important. Learn how to take advantage of JavaScript 2 while still running in today's browsers. Leverage your current JavaScript and HTML skills to build applications that run in Flash 7-9, DHTML and more with no code changes! OpenLaszlo 4.2 ...
With the rapid evolution that Java and open source frameworks have made since the release of J2EE, enterprise Java IT seems to be producing too many Java dinosaurs. Developers, technical managers, or architects who no longer pursue their technical skills don't understand the evol...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

SPONSORED BY INFRAGISTICS
There are many forces that influence technological evolution. After a decade of building enterprise ...
2008 is going to be an important year for Rich Internet Applications. Most organizations are deliver...
The OpenAjax Alliance is developing an Ajax industry wishlist for future browsers, using a dedicated...
In every field of design one of the first things students do is learn from the work of others. They ...
Infragistics announced the availability of two Community Technology Preview (CTP) User Interface (UI...
The YUI development team has released version 2.5.2; you can download the new release from SourceFor...
ADS BY GOOGLE
BREAKING JAVA NEWS

Sun Microsystems, Inc. (NASDAQ:JAVA) today announced the new SPECjbb2005 world reco...