Posted by: Ivko | March 14, 2010

Choice of the week – 10/2010

JSF 2 navigation upon POST

When writing a multi-page web applications, very often we give the user the possibility to enter some data in a form. When submitting the form, a POST HTTP request is generated from the browser to the server. If the web app just returns as a response the result page, and for some reason the user clicks the refresh button of the browser, then the POST request will be re-submitted. Which may not be what the intent of both the user and the developer are. That is why the web application developers usually do a redirect to the result page, which actually makes the browser to do a new (GET) request to it.

The author of the above short article shows how this POST-REDIRECT-GET pattern is implement in JSF 2. However, the current state of the implementation may be sometimes quite tedious and error prone – the URI to redirect to together with all the parameters are returned as a single string by the action method.

The author applies another common pattern for building the URI and the parameters. It uses the builder pattern together with a fluent interface. This integrates very well with the JSF pages as well through the NamedBean concept. For more details on the exact implementation, you may check the article.

The foundation of an OSGi-based application

Developer.com has started a series of articles on one of the most interesting topics in the industry – OSGi. The authors start with a very brief and short introduction on what OSGi is, how it emerged and what are its strengths. Then they introduce us to a case study for presenting how OSGi can be used in the practice.

The actual sample application performs user login to a certain user store (LDAP server in our case). In this installment you can see how it is all designed. The authors create two bundles – one for the user credential validation and one for the UI. They contain two and three services respectively and will be developed in the Eclipse Equinox environment. Thus the UI bundle will also use two eclipse plug-in extension points: splash screen and preference page.

This article contains just the requirements and design part of the application. In the next one we will hopefully read more on the implementation of the services and their integration with OSGi.

Class generation in Velocity

The Apache Velocity series on the InformIT Java Reference Guide continues this week with a more interesting example. After last week we were introduced into the project and created our first sample application, now we can see how can we generate all sorts of Java Beans.

The author creates an application that initializes a bean model class containing the package where our target bean resides and also its name and its fields together with their types.  Next he creates a utility class with one helper method that will be later used by the template. These both classes are put into the velocity context. Finally comes the template itself. There you can see how you can do conditional logic (if and else) in Velocity template language (VTL), how to implement cycles, how to define and access local variables, how to access model data and call methods of classes that are put in the context.

Declarative hyperlinking in Jersey

When working with a REST-ful web service, sometimes you may need to code inside your app a link to a restful resource class in the form of a URI. For that you would use the UriBuilder class.

The author of this article provides us with some insight on what’s going on in the Jersey development these days. Jersey is the JAX-RS reference implementation so this blog post might be interesting for all of you who are developing or using RESTful web services.

So instead of using the UriBuilder to build a URI variable, the author proposes to annotate it with a new annotation. It is supposed to support all kinds of resource paths and parameters. Remember, it is a work in progress, but it’s worth taking a minute to look at it.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: