java left logo
java middle logo
java right logo
 

Home arrow Java Tutorials arrow Introduction to JSTL using NetBeans
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4091
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
Introduction to JSTL using NetBeans E-mail
User Rating: / 162
PoorBest 

Image

 

Again follow the same steps we create another properties file. This time name it resource_bundle_[language].properties where the language is actually the language codes for our translations. For this tutorial, let’s name it resource_bundle_id.properties. Please notice that the suffix is “id” which means that this is the resource bundle for Indonesian language. You may use any suffix as you prefer at this stage i.e. resource_bundle_es.properties (Spanish) or resource_bundle_zh.properties (Mandarin) and etc.

The new properties file, the one with suffix will be automatically nested under our default “resource_bundle.properties” file.

Put some keys in our default properties file.

title=My Company

welcome=Welcome!

And the translated version of keys for our suffixed properties file.

title=Perusahaanku

welcome=Selamat Datang!

 

Image

 

We are done with the resource bundle properties files. Let’s see how they are working. Back to our Jstl_Fmt_Tags.jsp, add below codes to test our internationalization support from JSTL tag.

<fmt:setBundle basename="resource_bundle" />

<fmt:message key="title" />

<fmt:message key="welcome" />

<fmt:bundle basename="resource_bundle_id" >

<fmt:message key="title" />

<fmt:message key="welcome" />

</fmt:bundle>

The first and second paragraph does the same thing. The first paragraph, we are using <fmt:setBundle> while the second we are using <fmt:bundle> tag. They are doing the same thing except <fmt:bundle> works only within its tag. The <fmt:message> outside of the <fmt:bundle> should not be able to access the properties files. Therefore we need to define the opening and closing tag for <fmt:bundle> tag. While <fmt:setBundle> works in higher level and we can specify it in what scope the tag <fmt:setBundle> will have an effect.

The basename attribute in the <fmt:bundle> and <fmt:setBundle> are the name of the specific properties file while <fmt:message> is used to look up for matching available keys message in our properties file.

Next part is about date time parsing and formatting. Continue with our current JSP. Put this code.

<jsp:useBean id="now" class="java.util.Date" />

This tag is to get to java.util.Date class.

<fmt:setLocale value="en_GB" /><strong>U.K :</strong>

<br>

<fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="default" />

<br>

<fmt:timeZone value="GMT">

<fmt:formatDate value="${now}" type="both" pattern="EEEE, dd/MMMM/yyyy, HH:mm:ss z" />

</fmt:timeZone>

<br>

<fmt:formatNumber value="${now.time}" />

<br>

<fmt:formatNumber value="8000" type="currency" minFractionDigits="2" maxIntegerDigits="10" />

How do the above codes work? First we set the locale value to desired value (in this case, UK). Simply refer to Language Preference in our browser for some locale values.

The tag <fmt:formatDate> will format the date value which retrieved via “now” bean id. The type could be date, time or both. The dateStyle and timeStyle could be in short, medium, long, full or default. The default value for this is “short”. Pattern is used if we want the date time format to be in our specific way. Pattern will always override dateStyle and timeStyle.

The tag <fmt:timeZone> will adjust the current time to GMT based time. We may want to use <fmt:setTimeZone> in certain conditions. The value attribute for this tag could be in standard abbreviation (e.g., "PST," "GMT"), a full name (e.g.,"Europe/Stockholm"), or a GMT offset (e.g., "GMT+1").

The tag <fmt:formatNumber> is to format the numerical given values. The type could be number, currency or percentage. Here are more details about it. minFractionDigits is a minimum number of digits in fractional portion. maxIntegerDigits is a maximum number of digits in integer portion. Other attributes are currencyCode and currencySymbol. These 2 are valid while the type is currency. This can be useful when you need to show prices expressed in a fixed currency, but you want the amount to be formatted according to the selected locale.

<fmt:parseDate value="25-12-2006" pattern="dd-MM-yyyy"/>

<fmt:parseNumber value="$8,000.00" pattern="$#,###.##" />

<fmt:parseDate> and <fmt:parseNumber> is to get the actual value from unparsed string. These tags are useful in the situation where we need to get users’ input from a User Interface (UI) form. We can parse the values in form of what we want before inserting or updating to a database.

Now build and run the project. We will get something like this.

 

Image

 

And this is what we get when we click the “JSTL Formatting Tags”.

 

Image



 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.