[ http://issues.apache.org/jira/browse/VELTOOLS-21?page=all ]

Tim Colson moved VELOCITY-320 to VELTOOLS-21:
---------------------------------------------

      Project: VelocityTools  (was: Velocity)
          Key: VELTOOLS-21  (was: VELOCITY-320)
    Component:     (was: Tools)
      Version:     (was: 1.4)

> ActionMessagesTool.get(String,String) returns List of null objects if it 
> can't find the resource key in the resources
> ---------------------------------------------------------------------------------------------------------------------
>
>          Key: VELTOOLS-21
>          URL: http://issues.apache.org/jira/browse/VELTOOLS-21
>      Project: VelocityTools
>         Type: Bug
>  Environment: Operating System: All
> Platform: All
>     Reporter: Thoralf Rickert
>     Priority: Minor

>
> If someone adds a message into the HttpServletRequest as follows
> ActionMessages messages = new ActionMessages();
> ActionMessage message = new ActionMessage("blaa");
> messages.add( ActionMessages.GLOBAL_MESSAGE, message );
> saveMessages( request, messages );
> and uses the VelocityTools ActionMessagesTool to get the messages in a 
> Velocity template with getAll() or whatever the returning list contains null 
> objects, if the resource key (in the example blaa) wasn't found in the 
> resources. That could be okay, but the javadoc says 
> > If the message resources don't contain a message for
> > a particular key, the key itself is used as the message.
> And that doesn't happen. If you look in the code you can see that there is a 
> while loop that looks for every ActionMessage key, if the key is in the 
> resources. If it isn't, the method sends a warn message to the log but adds 
> the null message to the returning list, instead of saying message = msg.getKey
> ().
> The code should be look like this:
> while (msgs.hasNext())
> {
>   ActionMessage msg = (ActionMessage)msgs.next();
>   
>   String message = null;
>   if (res != null)
>   {
>     message = 
>       res.getMessage(this.locale, msg.getKey(), msg.getValues());
>     if (message == null)
>     {
>       Velocity.warn("ActionMessagesTool: Message for key " + 
>                     msg.getKey() + 
>                     " could not be found in message resources.");
>       // BUGFIX HERE!
>       message = msg.getKey();
>     }
>   }
>   else
>   {
>     // if the resource bundle wasn't found, use the key
>     message = msg.getKey();
>   }
>   list.add(message);
> }
> or maybe better:
> while (msgs.hasNext())
> {
>   ActionMessage msg = (ActionMessage)msgs.next();
>   
>   String message = null;
>   if (res != null)
>   {
>     message = 
>       res.getMessage(this.locale, msg.getKey(), msg.getValues());
>     if (message == null)
>     {
>       Velocity.warn("ActionMessagesTool: Message for key " + 
>                     msg.getKey() + 
>                     " could not be found in message resources.");
>     }
>   }
>   
>   if (message == null)
>   {
>     message = msg.getKey();
>   }
>   list.add(message);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to