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 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.

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.

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 Nov 05, 2008

GlassFish and MySQL: The Series

With more than 100 million downloads, MySQL is the world's most popular open-source database. MySQL's popularity is indicative of the growing adoption of open-source software. Developers are using open-source software because it offers them a reliable and low-cost alternative for developing their applications. This adoption trend extends to middleware too. For example, open-source servers are replacing proprietary servers in many enterprises. Case in point: GlassFish, an open-source, enterprise-quality, Java EE 5-compliant application server, enjoys significant popularity. With more than seven million downloads since its release in May 2005 and more than half a million downloads a month, GlassFish has a widespread and growing community of users.

Read the article GlassFish and MySQL, Part 1: A Perfect Combination for Web Applications and learn about the advantages of using MySQL with GlassFish and why the combination is a perfect choice for developing and deploying web applications.

This article is the first in a series of articles about the use MySQL with GlassFish. The second article in the series, GlassFish and MySQL, Part 2: Building a CRUD Web Application With Data Persistence, shows you how to use the NetBeans IDE with GlassFish and MySQL to build a create, read, update, and delete (CRUD) web application that accesses persistent data.




« July 2016