Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Rapid Java Web Application Development with Tapestry : Page 5

Tapestry is a powerful and innovative framework for developing component-based Web applications. With Tapestry 4, things get even better.


advertisement

Localization

Localization in Tapestry is a remarkably simple task. Each page or component needing to be localized has its own properties file in the WEB-INF directory of your Web application and contains the messages to be displayed. To use them, you can use a special attribute of the span tag as follows:

<span key="title">Online Travel Discounts</span>

The contents of the tag are for previewing purposes only; this text is discarded at runtime and replaced by the localized text.



If you need to use a formatted message, you instead use the Insert component and the special messages object accessible in every page:

<span jwcid="@Insert" value="ognl:messages.format('feature-destination', featureDestination.destination, featureDestination.price)"> A trip to Paris for only $199 </span>

The first parameter is the name of the message key; the following parameters are message-formatting parameters.

The final page template, complete with localization, is presented here:

<html> <head> <title><span key="page-title">Tutorial: Introduction to Tapestry</span></title> </head> <body> <h3><span key="title">Online Travel Discounts</span></h3> <h4> <span key="todays-feature-destination">One of today's feature destinations: </span> </h4> <p> <span jwcid="@Insert" value="ognl:messages.format('feature-destination', featureDestination.destination, featureDestination.price)"> A trip to Paris for only $199 </span> <a href="#" jwcid="@DirectLink" listener="listener:showDetails" parameters="ognl:{ featureDestination }"> <span key="show-details">Show Details</span> </a> </p> <p> <a href="#" jwcid="@PageLink" page="Home"> <span key="show-another">Show another feature destination!</span> </a> </p> <p> <a href="#" jwcid="@PageLink" page="FeatureDestinationList"> <span key="show-all">Show all your feature destinations!</span> </a> </p> </body> </html>

As you can see, it is still quite readable and can still be previewed in a standard Web browser. You can also localize your page templates, which may be useful for pages with a lot of static text that needs to be localized. For example, Home_fr.html would be the French translation of the Home.html template (see Figure 5).

Click to enlarge 
Figure 5. Template Localization

Many More Pros Than Cons

Tapestry is a clean, efficient, and easy-to-use (dare I say "fun"?) framework. In the tradition of Hibernate and Spring, and as opposed to EJB and JSF, it is based on real user needs and experience rather than being designed to a committee-specified standard. Its programming model, although not devoid of a few quirks and idiosyncrasies, is globally clean and elegant. Its architecture (especially where session management and component pooling are concerned) is efficient and highly scaleable. It provides a large number of very useable standard components out of the box, and custom components are relatively easy to develop if necessary. And important Web-development requirements such as localization are also well integrated.

On the negative side, it is less well known than Struts or JSF, and not backed by any industry giants. Documentation is not as abundant as it is for Struts or JSF. And although the Tapestry community is active and growing fast, experienced Tapestry developers are probably relatively hard to find.

Nevertheless, Tapestry is a fine piece of architecture and is well worth consideration for your next Web development project.



John Ferguson Smart is principal consultant at Wakaleo Consulting, a company that provides consulting, training, and mentoring services in Enterprise Java and Agile Development. Well known in the Java community for his many published articles and talks, he is also the author of the book Java Power Tools.
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap