The OGNL and the code were not equivalent.  I'll try to be a bit more verbose.  
Suppose the properties file contained this:


title=Hello, {0}!


And, you wanted to format your message.  Let's try it with your code first:


String formatString = getMessages().getMessage("title");
String title = getMessages().format(formatString, "Jim");


Using this, the title would be "[HELLO, Jim!]", but that's not what we want.  
Here's what's going on.  HiveMind (that's what really implements all of this) 
tries to lookup a message using the key you pass it in, then it uses the 
MessageFormat class to format it.  So, what key are we passing it?  We're 
passing it the value of the formatString variable, which contains "Hello, 
{0}!".  So, HiveMind tries to lookup a message with that key.  Since it doesn't 
find it, it returns "[HELLO, {0}!]" (this is just what HiveMind does to let you 
know it couldn't find it rather than returning null and breaking a bunch of 
stuff).  Then, HiveMind uses the MessageFormat class to format your message, 
replacing "{0}" with "Jim", resulting in "[HELLO, Jim!]".  If we do this 
instead:

String title=getMessages().format( "title", "Jim" );


We would get back "Hello, Jim!"  Does that make sense?


-------------------- m2f --------------------

Sent from www.TapestryForums.com

Read this topic online here: <<topic_link>>

http://www.tapestryforums.com/viewtopic.php?p=14689#14689

-------------------- m2f --------------------


Reply via email to