Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Changing Struts' bean:message to JSTL's fmt:message

I converted AppFuse to use JSTL's <fmt:message> tag instead of Struts' <bean:message> tags this morning. It was pretty easy. Here's the steps I took:

1. First, I added the following to metadata/web/seb-settings.xml:

<!-- Define the basename for a resource bundle for I18N -->
<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>ApplicationResources</param-value>
</context-param>

2. Then I added the format tag to web/common/taglibs.jsp:

<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

3. Finally, I did find/replace with <bean:message/<fmt:message.

4. I also had to change my title and header keys in web/WEB-INF/tiles-config.xml to remove the . from the bean names. In other words, I converted title.key and heading.key to titleKey and headingKey and also made the appropriate changes in web/layouts/baseLayout.jsp.

Easy as Pie!

Posted in Java at Jul 10 2003, 07:59:29 AM MDT 35 Comments
Comments:

Any indexed properties in "appfuse"? (or struts-resume? ) I'm having trouble and James Turner's powerpoint is proving to be inadequate without sample code.

Posted by Kevin on July 10, 2003 at 08:58 AM MDT #

AppFuse has simple indexed properties. By this, I mean that the indexed properties are just String arrays, rather than objects. I do plan on adding indexed properties with objects to Struts Resume, I just haven't done it yet. For String arrays, check out UserFormEx.java. This sets a user's roles based on a multi-select box of roles.

Posted by Matt Raible on July 10, 2003 at 09:39 AM MDT #

This begs the question: Why? Why use the JSTL tag in lieu of the Struts one?

Posted by Pratik Patel on July 10, 2003 at 04:48 PM MDT #

2 reasons I can think of:

1. Future compatibility - it's likely the Struts' tag will be deprecated someday. The JSTL tag is a standard, and most likely here to stay.

2. The other tags that format offers - namely <fmt:formatNumber> and <fmt:formatDate> - both of which are locale-sensitive.

Other than that - just because... ;0)

Posted by Matt Raible on July 10, 2003 at 04:53 PM MDT #

Sweet, this means I can remove another non-jstl tag library since I was only keeping bean around for the messages. Quick question, you define the context param in web.xml as ApplicationResources. Does that have to correspond with the name of the file from struts-config.xml or does that have to be the actual name of the properties file? I figure the answer is (b). Is there anyway to do multiple files? Does this mean we can remove the message-resources from the struts-config.xml? Maybe a wiki page would be best.

Posted by Dan Allen on July 11, 2003 at 05:16 AM MDT #

The name, in both web.xml and struts-config.xml refers to the filename minus the ".properties" portion. So ApplicationResources.properties is the name of the file, and is located directly under WEB-INF/classes. You can have multiple files, but you'd have to specify a "bundle" attribute or configure it for the request. This was actually discussed yesterday on the struts-user mailing list. I don't think you can get rid of the entry in struts-config.xml b/c you will still need that for errors/messages in your actions.

Posted by Matt Raible on July 11, 2003 at 05:33 AM MDT #

Thanks Matt, a month later and this is exactly what I needed today. I was like "I remember Matt saying something about this... where was that?" :-) (Wow. 2 comments in a few days... I'm on a roll).

Posted by Russ on August 10, 2003 at 05:47 AM MDT #

Matt! Thank you a lot! I was desperately trying on my own to get fmt:message to work. It was realy hard to find a solution. I found an other more flexible way you might now already: You can use fmt:setBundle in your jsp to specifiy the i18n property file. Sven alias wunderkind

Posted by wunderkind on September 04, 2003 at 09:46 AM MDT #

Dear Sir: I came from China,and when i try to local ApplicationResources.properties files to Chinese, but Appfuse can not show page correctly. I did not know the reason. Would you like to help me to solve this problem. Thank a lot.

Posted by minikiller on February 10, 2004 at 07:52 PM MST #

I got this "???webapp.prefix???" on my title instead of "Appfuse ~ Main Menu".
Apparently fmt isn't working properly. Any clue? What am I doing wrong.

Posted by YY on March 25, 2004 at 05:18 PM MST #

Try reverting back to <bean:message> for i18n - or looking into the <fmt> tag for more properties to set. These kind of issues are best addressed to [email protected].

Posted by Matt Raible on March 25, 2004 at 05:45 PM MST #

What I could not understand how can I specify the Locale. When I was using Struts I did it in the Logon action
    if (lang.equals("RUS"))  userLocale=new Locale("ru","RU");
    else
    if (lang.equals("ENG"))  userLocale=new Locale("en","US");
    else
    userLocale=getLocale(request);

    //set user locale
    setLocale(request,userLocale);
But it does not work right now. It always uses ENGLISH. By the way in JWSDP tutorial there is a mistake. They set bundle as
<context-param>	
   <param-name>	
      javax.servlet.jsp.jstl.i18n.basename	
   </param-name>	
   <param-value>messages.BookstoreMessages</param-value>	
</context-param>
but name of paramter should be as written above javax.servlet.jsp.jstl.fmt.localizationContext

Posted by Stas Sakalou on April 19, 2004 at 09:42 PM MDT #

Does somebody know if it's possible to replace runtime an allready set ResourceBundle? I want to use the standard jstl:fmt tags.... but I want to derive the values for the ResourceBundle from a database. And furthermore I want an action to refresh (or replace) the allready set ResourceBundle when I update data in the tables! Help appreciated.

Posted by Marcel Overdijk on May 05, 2004 at 12:21 PM MDT #

Just curious, what was the reason for change 4? If you're worried about fmt handling . in msg property keys, I use it like that all the time (title.key looks much better than titleKey in a resource bundle) and it works fine.

Posted by Tim Chen on June 07, 2004 at 12:19 PM MDT #

Sorry to answer a post on your blog Matt but Marcel, you can use fmt:bundle and a basename to use any bundles you want. It doesn't even have to be defined by ur web.xml. Just has to be visible to your application.

Posted by Tim Chen on June 07, 2004 at 12:32 PM MDT #

Hello, When I tried the AppFuse demo on http://demo.raibledesigns.com/appfuse, I got the "???webapp.prefix???" syndrome. After some "locale" searches, I found the issue: - my browser is with French localisation - there are only 4 language files: en, nl, pt_BR & zh_CN In such a case, "fmt" doesn't found any "closest" match. Some actual default language should be better. At least to avoid a broken demo :-) Regards Pierre Raoul

Posted by Pierre Raoul on September 06, 2004 at 04:59 PM MDT #

Hi I was doing some tests with fmt tag instead of bean:message The thing is, if I let my users to explicitly choose their languages and then use struts local to chage it in the session (action.setLocal(newLocal)) the fmt tags do not reflect the change Is there a way to achieve this? Thanks in advance A.

Posted by Andrea on March 01, 2005 at 07:52 PM MST #

aaa

Posted by 66.46.58.82 on April 01, 2005 at 01:20 PM MST #

Hi I am very new to JSTL and currently i am trying to use <fmt:message> tag instead of <bean:message>. It works fine. Suppose i have my own customized MessageResources class and one factory class to load it. How can i make use of these for JSTL also. When i tried to give the factory attribute of <message-resources> in struts-config.xml, it failed. Anybody can tell me how can do this ?

Posted by poornima on May 09, 2005 at 05:37 AM MDT #

aaa

Posted by 203.123.162.82 on August 03, 2005 at 12:50 AM MDT #

Hi, I have been using jstl fmt tags to format currency and date values in my jsp code. My colleagues want me to remove this code and move it to the Java presentation logic. An example: I use <fmt:formatNumber value="${myBean.amount}" type="currency"/> they want this to change to <c:out value="${myBean.formattedAmount}"/> They reason that this makes it more flexible to maintain code, if we decide to have a different view (instead of a jsp) in future. Since the logic for formatting is in java side and not part of the view itself, they say it is easier to maintain and use the same java code to support multiple views. I am not sure there is a significant advantage as they mention. Would appreciate comments/thoughts on this. Regards Prabhakar

Posted by Prabhakar Thopa on November 30, 2005 at 10:25 AM MST #

Hi,

I have been using jstl fmt tags to format currency and date values in my jsp code. My colleagues want me to remove this code and move it to the Java presentation logic.

An example: I use fmt:formatNumber value="${myBean.amount}" type="currency"
they want this to change to
c:out value="${myBean.formattedAmount}"


They reason that this makes it more flexible to maintain code, if we decide to have a different view (instead of a jsp) in future. Since the logic for formatting is in java side and not part of the view itself, they say it is easier to maintain and use the same java code to support multiple views.
I am not sure there is a significant advantage as they mention. Would appreciate comments/thoughts on this.

Regards

Prabhakar

Posted by 12.188.33.13 on November 30, 2005 at 10:26 AM MST #

d

Posted by 193.231.107.60 on January 13, 2006 at 03:06 AM MST #

Matt,
Please correct your typo :
Change
1. First, I added the following to metadata/web/seb-settings.xml:
to
1. First, I added the following to metadata/web/web-settings.xml:

Yes, the "w" key is just above the "s" key...and for someone as busy as you, you must have typed very fast. :)


Toh Beng Wooi
Malaysia.

Posted by Toh Beng Wooi on September 14, 2006 at 07:56 PM MDT #

Hi All, I need urgent help. I am using <html:select> box using jstl. My screen auto refreshed in every 2 seconds. So, it is almost immposible to open the select box and select a desired value from that drop down box. Is there any way to know that dropdown box (select box) is open (expanded) or not? So that I can make a check in autorefresh. Waiting for your help. Regards, Mayank

Posted by Mayank on December 27, 2006 at 09:11 AM MST #

Hi All,

I need one urgent help. In one of my screen there is autor refresh screen. When I clcick box create by select tag of struts, When I click on select box it should not, screen shuld not reshresh.

How do know, whether my list box is vibike or not.

Regards,
Mayank

Posted by mayank on January 02, 2007 at 08:53 AM MST #

I need a clear explanation of fmt tag in jstl custom tag library what do u mean by <fmt:message key="confirmation.edit.message" bundle="${resource}" can u tell me quickly

Posted by madhuri on April 12, 2007 at 06:50 AM MDT #

Hi, Can you please let me know how can I round to 3 decimal places and show a float in <html:text> tag ? I am doing :- <fmt:formatNumber var = "tempvar" minFractionDigits="0" maxFractionDigits="3" groupingUsed="false" value="${val}" /> <h:text name="abc" property="value" value="${tempvar}" indexed="true"/> What's wrong in this? Please help!

Posted by Bucchi on June 13, 2007 at 01:51 AM MDT #

Hi, Can you please let me know how can I round to 3 decimal places and show a float in <html:text> tag ? I am doing :- <fmt:formatNumber var = "tempvar" minFractionDigits="0" maxFractionDigits="3" groupingUsed="false" value="${val}" /> <h:text name="abc" property="value" value="${tempvar}" indexed="true"/> What's wrong in this? Please help!

Posted by Bucchi on June 13, 2007 at 01:51 AM MDT #

Hi, Can you please let me know how can I round to 3 decimal places and show a float in <html:text> tag ? I am doing :- <fmt:formatNumber var = "tempvar" minFractionDigits="0" maxFractionDigits="3" groupingUsed="false" value="${val}" /> <h:text name="abc" property="value" value="${tempvar}" indexed="true"/> What's wrong in this? Please help!

Posted by Bucchi on June 13, 2007 at 02:01 AM MDT #

<h1>CACA</h1>

Posted by Cagador sin ley on August 22, 2008 at 10:12 AM MDT #

Article explains about the product : http://www.thepatentmagicplant.com/message-bean.php

for more Information, videos, pictures Enter Site - message bean

magic bean | magic beans | magic bean whishes | message bean | message plant

Posted by message bean on March 01, 2011 at 11:09 AM MST #

Article explains about the product : http://www.thepatentmagicplant.com/message-bean.php

for more Information, videos, pictures Enter Site - message bean

magic bean | magic beans | magic bean whishes | message bean | message plant

Posted by message bean on March 01, 2011 at 11:10 AM MST #

Article explains about the product : http://www.thepatentmagicplant.com/message-bean.php

for more Information, videos, pictures Enter Site - message bean

magic bean | magic beans | magic bean whishes | message bean | message plant

Posted by message bean on March 01, 2011 at 11:10 AM MST #

Article explains about the product : http://www.thepatentmagicplant.com/message-bean.php

for more Information, videos, pictures Enter Site - message bean

is a gift that can match any moment.

magic bean | magic beans | magic bean whishes | message bean | message plant

Posted by message bean on March 01, 2011 at 11:11 AM MST #

Post a Comment:
  • HTML Syntax: Allowed