October 24, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

JavaServer Faces and ASP.NET - A Side by Side Look Part 2

  • February 27, 2006
  • By Michael Klaene
  • Send Email »
  • More Articles »

Internationalizing Applications

Internationalization, or i18n, is it as commonly known, refers to supporting diverse language and cultures in your application. This includes providing localized text messages and formats for items such as dates so that users in different parts of the world will view your web page in a format and language they can understand. With the worldwide growth of the web, this type of functionality becomes increasingly important. We will quickly look at how each framework allows you to externalize page text, such as field labels, to provide support for different locales.

JSF applications that support different locales do so in much the same way as other J2EE applications, by storing localized text in a resource bundle properties file. You will have one properties file for each locale that you support, with each locale identified by a language code and a country code, for example 'en-US'. Switching the displayed language becomes a matter of redirecting to another properties file. In previous releases, supporting different locales in an ASP.NET application was no trivial task, however, there have been big improvements in this area with ASP.NET 2.0. For example, recompilation is no longer necessary when switching locales in ASP.NET 2.0.

To enable the JSF application to support different locales, I added a WebReservations.properties file to the application and added a locale for en-US. The title of the reservations page reads 'Make a Reservation for Conference Room.'. I simply added a key/value in this resource bundle properties file:

# Sample ResourceBundle properties file
ReserveRoomTeamLabel=Reservation Team:

I could create any number of locale-specific messages for the same component. Then, I need to tell the application how to use this file by adding the following to the faces-config.xml file:

  <message-bundle>WebReservations.properties</message-bundle>
    <locale-config>
      <default-locale>en</default-locale<
      <!--Add other locales here.-->
    </locale-config>

Referencing a resource bundle, you can substitute literal text in the JSF markup with a reference to this key. Here is an example:

<ui:label binding="#{ReserveRoom.lblReserveTeam}" id="lblReserveTeam" style="left: 48px; top: 96px; position: absolute" text="#{messages.ReserveRoomTeam}"/>

ASP.NET provides support for different locales with resource files. These resource files have an extension of .resx. ASP.NET 2.0 introduces resource expressions that you can put in ASP.NET markup. These expressions look similar to ASP.NET data binding expressions. It is possible to specify both local and global resources for an application. In this example, a local resource file is set up that pertains to only the new reservations page.

Local resources need to be placed in a folder called 'App_LocalResources'. Each file in this folder should have a name like '{aspx page name}].aspx.resx'. I created a file called 'Reservations.aspx.resx'. In it, I added an entry for 'Reservation Team:' just as I did in the JSF application. For the page to access this resource and assign the label the appropriate text at runtime, you could add the following expression:

<asp:Label ID="Tea" runat="server" Text=<%$ Resources:ReservationsTeamLabel %>></asp:Label>
ASP.NET - Adding Localized Text
JSF - Adding Localized Text

If you have yet to develop an application with i18n requirements, there is a strong likelihood that you will in the future. Both JSF and ASP.NET make this task easy.

Additional Topics

Finally, there are some diverse, but important, topics with regards to the JSF and ASP.NET frameworks that should be reviewed. I have attempted to provide some useful links for you where you can learn more.

Application Security

The JSF specification does not address security per say. Instead, the same options available to you when securing J2EE applications can be used with JSF. The possibilities here are numerous, well-documented, and mature. ASP.NET offers numerous security options as well. A lot of ASP.NET security is tied to the Windows platform, as you might have guessed. For example, an ASP.NET application running on an intranet can easily authenticate users based upon their Windows domain logon information. There are a number new 'Login Controls' in ASP.NET 2.0 to enable you to quickly add things like login forms to your applications.

Error Handling and Debugging

Once again, when developing with JSF, all the same error handling and debugging techniques available to all J2EE application developers are available to you. This includes specifying global error pages for applications, specifying specific actions based upon the HTTP error code, and more. You can log application errors and general activity using a logging mechanism such as the standard Java logging package or the popular Apache Log4j package.

ASP.NET allows you configure a lot of an application's error handling details through the IIS server console. Also, ASP.NET provides handy tracing functionality so you can log certain types of information about a page request. Here is a good resource that provides an introduction to ASP.NET error handling.

Templating

It is often advantageous to separate out portions of a web page that are common across several different pages so that content can be reused and markup does not have to be duplicated. Application headers and footers are the best examples of page sections you will reuse across your web site. Templating encourages you to define a 'template' page which you use to substitute only the content that changes from page to page, leaving the rest the same. JSF provides no built in support for templating. A popular approach to templating with J2EE web applications is the Struts Tiles project. Tiles can be used with JSF too. Java Studio Creator, as well as other JSF tools, provides its own support for reusing page content. A tutorial on how to reuse page content with Studio Creator can be found here.

ASP.NET 2.0 introduces its own templating mechanism that you can use to factor out common interface sections. This feature is called Master Pages. Master Pages are a welcome introduction to the framework and I would expect the next major release of JSF to provide something similar.

Styles and Themes

Professional web developers have long used Cascading Style Sheets as a way to separate appearance styles of a page so the look and feel of a web page can be modified without editing the page markup. A 'Theme' can be thought of as a group of related styles. You can continue to use Cascading Style Sheets in JSF and ASP.NET. However, ASP.NET 2.0 introduced support for Themes and Skins. A 'Skin' is a defined style for a particular type of control. While the JSF specification does not address themes, several tools, including Java Studio Creator, provide non-standard support for themes.

About the Author

Michael Klaene is a Senior Consultant with Sogeti LLC. He has spent over 9 years in Information Technology and is an experienced Systems Analyst, delivering solutions that involve numerous technologies, such as J2EE and .NET.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel