Ed Ort

Monday Nov 16, 2009

Enterprise Tech Tip: POST-REDIRECT-GET and JSF 2.0

JavaServer Faces co-spec lead, Ed Burns, is in the process of writing a follow up to his popular book JavaServer Faces: The Complete Reference. The new book,co-written with Neil Griffin, is titled JavaServer Faces 2.0, The Complete Reference. It's chock full of excellent tutorials about the latest version of JavaServer Faces (JSF) technology, JSF 2.0.

You can get a sneak peek into one of these tutorials, a tutorial that focuses on support in JSF 2.0 that makes it much easier to implement the POST-REDIRECT-GET pattern, or PRG for short. If you're not familiar with the PRG pattern, in short, it's a pattern described by Michael Jouravlev, in an August 2004 TheServerSide.com article titled Redirect After Post. In the article, Jouravlev described a problem that many web applications present, as follows:

All interactive programs provide two basic functions: obtaining user input and displaying the results. Web applications implement this behavior using two HTTP methods: POST and GET respectively. This simple protocol gets broken when an application returns a web page in response to a POST request. Peculiarities of the POST method combined with idiosyncrasies of different browsers often lead to an unpleasant user experience and may produce an incorrect state of the server application.

To address the problem, Jouravlev described a technique that he called POST-REDIRECT-GET, or the PRG pattern for short. The rules of the pattern are as follows:

  • Never show pages in response to POST.
  • Always load pages using GET.
  • Navigate from POST to GET using REDIRECT.

Burns says that previous versions of JSF technology violated the first of these rules by using POST for every page navigation. In navigating from one page to another in a JSF-enabled application, the JSF framework forwarded a POST request through the Servlet API's RequestDispatcher.forward( ) method. This caused a new Faces page to be rendered and returned to the browser in response to the postback request. However, thanks to a JSF contribution from the Seam team at JBoss, it is now much easier to do PRG with JSF 2.0.

If you want to learn more about this topic, read Burns's Tech Tip POST-REDIRECT-GET and JSF 2.0 The content of the tip is an adaptation of a section on PRG and JSF 2.0 in Burns's upcoming book.

Friday Oct 30, 2009

Enterprise Tech Tip: Using CDI and Dependency Injection for Java in a JSF 2.0 Application

The next release of the enterprise Java platform, Java EE 6 includes a number of powerful new technologies and well as significant enhancements to existing technologies. Two of the new technologies are JSR 299: Contexts and Dependency Injection (CDI) (referred to in earlier times as Web Beans) and JSR 330: Dependency Injection For Java. One of the significantly enhanced technologies is JSR 314: JavaServer Faces 2.0.

CDI defines a set of services for the Java EE environment that makes applications much easier to develop. Perhaps most significantly, CDI unifies and simplifies the Enterprise JavaBeans (EJB) and JavaServer Faces (JSF) programming models. It allows enterprise beans to act as managed beans in a JSF application.

Until now there has not been a standard approach for annotation-based dependency injection. Dependency Injection For Java changes that by introducing a standard set of annotations that can be used for dependency injection.

If you're involved with creating user interfaces (UIs) for web applications, you're probably familiar with JavaServer Faces. It's a technology that provides a server-side component framework that is designed to simplify the development of UIs for Java EE applications. The latest release of the technology, JSR 314: JavaServer Faces 2.0, makes UI development for Java EE applications even easier through support for annotations and the addition of new features such as Facelets and composite components.

You can get a good idea of how these technologies simplify web application development by reading the Tech Tip Using CDI and Dependency Injection for Java in a JSF 2.0 Application, written by Roger Kitain, the JavaServer Faces co-specification lead. Roger presents a JSF 2.0 application and shows in the source code where CDI components and Dependency Injection for Java annotations play a role.

Tuesday Sep 29, 2009

Deep Dive: JDK 7 With Danny Coward

A few months ago, I had a chance to sit down with Danny Coward, the Chief Architect for Client Software at Sun Microsystems, to examine some of the new and cool features in the next release of the Java Development Kit, JDK 7. Some of these features focus on modularizing the JDK, supporting non-Java languages at the VM level, and making developers more productive through various small changes to the Java languages. Danny backed up this discussion with some code examples and demonstrations. It was an educational and enjoyable session. I hope you agree.



Note that the content of this session reflects the state of the project at the time the Deep Dive was taped. Please check the JDK 7 Features project site for the latest information about JDK 7.

Enterprise Tech Tip: Locking and Concurrency in Java Persistence 2.0

One of the real success stories behind Java EE 5 is the Java Persistence API, know informally as JPA. The technology has been widely adopted and is recognized as the enterprise standard for Object/Relational (O/R) persistence.

However, one of the shortcomings of JPA 1.0 is that the only type of locking it supports is optimistic locking. Recall that locking is a technique for handling database transaction concurrency. When two or more database transactions concurrently access the same data, locking is used to ensure that only one transaction at a time can change the data.

There are generally two locking approaches: optimistic and pessimistic. Optimistic locking assumes that there will be infrequent conflicts between concurrent transactions, that is, they won't often try to read and change the same data at the same time. In optimistic locking, the objective is to give concurrent transactions a lot of freedom to process simultaneously, but to detect and prevent collisions. Two transactions can access the same data simultaneously. However, to prevent collisions, a check is made to detect any changes made to the data since the data was last read.

Pessimistic locking assumes that transactions will frequently collide. In pessimistic locking, a transaction that reads the data locks it. Another transaction cannot change the data until the first transaction commits the read.

The next release of JPA, JPA 2.0, which will be offered as part of Java EE 6, adds support for pessimistic locking. Using JPA 2.0, you can lock an entity either optimistically or pessimistically, depending on how often you think transactions will collide.

To learn about the new locking support in JPA 2.0, see the Tech Tip Locking and Concurrency in Java Persistence 2.0 by Carol McDonald.

Tuesday Jul 07, 2009

New JDK 7 Feature: Support for Dynamically Typed Languages in the Java Virtual Machine

Over the years, the Java virtual machine (JVM) has been host to a growing number of languages. Increasingly, JVM implementations of dynamic languages are becoming available, such as JRuby, an implementation of the Ruby programming language, Jython, an implementation of the Python programming language, and the Groovy scripting language.

However, developers of these dynamic languages have faced a troublesome obstacle. When developers write engines for dynamically typed languages that run in the JVM, they have to satisfy the requirements of the Java bytecode that the JVM executes. Until now, that bytecode has been designed exclusively for statically typed languages. This design has been especially painful for developers when generating bytecodes for method invocations.

But help is on the way. JSR 292: Supporting Dynamically Typed Languages on the Java Platform, which is being implemented in JDK 7, introduces a new Java bytecode instruction for the JVM, invokedynamic, and a new method linkage mechanism based on method handles.

Learn more about this new JDK 7 feature in the article Support for Dynamically Typed Languages in the Java Virtual Machine.

Friday Jun 26, 2009

Enterprise Tech Tip: A Sampling of EJB 3.1

Enterprise JavaBeans (EJB) technology has taken a number of knocks in the past. When it was first introduced some, perhaps many, cried that it was too complicated, with a lot of programming overhead that made the technology needlessly difficult to use.

Over time things have improved dramatically. Features such as annotations in EJB 3.0 made the technology much, much easier to use. Those ease-of-use advancements continue with the upcoming release of EJB 3.1, which will be included in Java Platform, Enterprise Edition (Java EE) 6. A preview version of Java EE 6 is currently available for download. The preview version includes a nearly complete implementation of EJB 3.1

If you want to learn about some of the new, cool features in EJB 3.1, see the Tech Tip, A Sampling of EJB 3.1, written by Ken Saks, the EJB 3.1 Specifical Lead.

Friday Jun 12, 2009

Enterprise Tech Tip: A Common Ant Build File for Metro-Based Services and Clients

If you're like most developers, you're always looking for shortcuts that simplify developing and testing code. In this Tech Tip, Metro architect Harold Carr describes just such a helpful shortcut -- a common ant build file that simplifies the task of building and testing Metro-based services. The build file can builds a service from a WSDL description or from a Java class annotated with @WebService. It then either creates a WAR file and deploys the WAR file to a container or it invokes the Endpoint.publish() method to publish the web service endpoint using the HTTP server built into the Java platform.

Read about it in the tip A Common Ant Build File for Metro-Based Services and Clients.

Deep Dive: MySQL Tips For Java Developers

MySQL is the world's most popular open-source database, and there are a lot of Java developers who use MySQL databases in their applications. In this Deep Dive, Mark Matthews, architect for Enterprise Tools Team at Sun Microsystems, demonstrated some of the techniques that can help Java developers get more out of their applications that use MySQL.

Mark has a lot of experience regarding the use of MySQL and Java technologies. Aside from being an architect for MySQL tools at Sun, Mark is the original developer and maintainer of Connector/J, the MySQL JDBC driver.

Mark covered a number of MySQL tips for Java developers including some lesser known configuration options, connection pool settings, and some special MySQL language elements such as ON DUPLICATE KEY UPDATE.



Notes From the 2009 JavaOne Conference

The numbers were a bit down from previous years and perhaps there was a little less buzz, but I found this year's JavaOne Conference to be as interesting and fun as ever. As always, I was part of the Sun Developer Network team that covered the general and technical sessions for the conference web site. I was also host for a number of "Man/Woman on the Street" interviews with conference attendees.

I found the sessions to be uniformly excellent. It seemed that the quality of the presenters and their demonstrations at these sessions was exceptionally high. I hope those of you who went to the conference were equally impressed with the sessions. If you didn't get a chance to attend the conference, you can view video replays of the general sessions.

You can find all of the articles covering the sessions here. I covered the following sessions:

I also had the opportunity to cover the general session for CommunityOne West, a conference focused on communities and open source. CommunityOne West started the day before JavaOne. Cloud computing and a new release of OpenSolaris were the stars of that session. BTW, if you're into cloud computing, there are a lot of good cloud-related sessions that my SDN teammates covered during the JavaOne conference. These include:

Also see the new Sun Cloud Developer Tools site.

You can find a great wrap-up of the conference here. As the wrap-up notes, this may be the final JavaOne Conference. I've had the pleasure to attend the last 10 of them. Covering these conferences always required a lot of preparation work and a goodly amount of toil and sweat. But I always found them educational, even exhilarating. They gave me a chance to learn, a chance to share ideas, and a chance to meet some of the most interesting folks on the planet -- the Java community.

Thursday Apr 30, 2009

Deep Dive: Sun GlassFish Web Space Server 10.0

At the 2008 JavaOne Conference, Sun made an exciting announcement regarding a collaboration agreement it reached with the Liferay open portal community. Both companies agreed to share code and release products from a common codebase. Sun GlassFish Web Space Server is an outgrowth of that common codebase, bringing together features and technologies from Liferay as well as Sun's OpenPortal communities.

In this Deep Dive video, James Falkner, Sun's Product Architect for portal technologies, demonstrates many of the features that Sun GlassFish Web Space Server offers for administrators, developers, and end users. Along the way, he demonstrates some cool features such as hooking portlet events together graphically, and changing the theme for a portal page in Adobe Dreamweaver using Web Space Server's View Designer plugin.

There's so much functionality in the Web Space Server that it was difficult to fit James's demonstrations into one short video. So instead we offer multiple videos -- or a video in multiple parts. Watch it. I think you'll see that Sun GlassaFish Web Space Server 10.0 is a fun and highly functional product.

  • Part 1: Learn about the key features in Sun GlassFish Web Space Server 10.0.


Wednesday Apr 29, 2009

JavaFX App-O-Rama

Although the JavaFX platform is only a few months old -- its initial full release was in December 2009 -- people are already building some really cool applications with it. A new article, titled JavaFX App-O-Rama: Applications From the Community, highlights three community based projects that are producing cool, innovative JavaFX applications.

Here are some other good places to find cool JavaFX applications, sample programs, and demonstrations:

Wednesday Apr 15, 2009

Enterprise Tech Tip: Jersey and Spring

There have been a number of interesting Enteprise Tech Tips about JAX-RS and Jersey. These include Implementing RESTful Web Services in Java, Configuring JSON for RESTful Web Services in Jersey 1.0, and Consuming RESTful Web Services With the Jersey Client API. Recently, another interesting Tech Tip on Jersey made an appearance. This one covers Jersey's support for the Spring Framework.

Spring is a very popular enterprise Java framework, and if you're a Spring user who is also interested in JAX-RS, check out this tip.

Monday Apr 13, 2009

Two new Tech Tips

I'd like to highlight two interesting Enterprise Tech Tips that were added over the last few months to the Enterprise Tech Tips blog. The first, Converged Enterprise Applications, by Prasad Subramanian, is a follow up to an earlier tip on Session Initiation Protocol (SIP) servlets and their use in voice-related applications. The earlier tip introduced the concept of a converged enterprise application -- an enterprise application that has a SIP servlet application bundled within it. The follow-up tip goes into more detail about this concept and provides a working example. Prasad Subramanian is the project lead for the Sailfin project, an open source implementation of a SIP servlet container using the GlassFish application server.

The second tip covers Jersey's support for Spring. The tip is written by Paul Sandoz, co-spec lead and implementation lead for JSR-311, the Java API for RESTful Web Services (JAX-RS). Jersey is an open-source, production-ready reference implementation of JAX-RS. Spring is a popular framework for building and running enterprise Java applications. Jersey has integrated support for Spring. This tip shows you how to take advantage of that support. It shows you how to configure Spring with Jersey and use Jersey's Spring-related features.

And by the way, if your a quiz aficianado, try the Tech Tips quiz.

Monday Feb 23, 2009

Two excellent JavaFX videos

There are two excellent JavaFX -related videos you ought to check out:

  • JavaFX Deep Dive with Jacob Lehrbaum. In this video, Jacob Lehrbaum, the Senior Product Line Manager for JavaFX Marketing at Sun Microsystems, demonstrates some of the exciting features in the JavaFX platform.
  • 15 Minutes or Less - JavaFX. Join Sun Microsystems' Robert Eckstein as he teaches you the fundamentals of the new JavaFX programming language, all in fifteen minutes or less!

2009 JavaOne Conference, June 2-5, San Francisco, CA

Believe it or not, before you know it, it will be time for another JavaOne Conference. This year's conference promises to be bigger and better than ever. The JavaOne Conference is a great way to stay on top of everything new and different, both inside and around Java technology. If you register by April 22, 2009, you can save $200 off a Conference Pass or Conference Plus Pass. So register now at http://java.sun.com/javaone.

Calendar

Feeds

Search

Links

Navigation

Referrers