You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Markos Charatzas <xa...@forthnet.gr> on 2005/02/09 11:26:05 UTC

Application Resources and TextTool

Hi all,

I get this weird bug(?) with TextTool.
On my struts-config.xml I declare the following message resource

<message-resources parameter="DestinationsResources" key="destinations" />

then in my template I use the textool to retrieve a value from that resource

$text.get('title.img', 'destinations')

and I get a ClassCastException with the following stack trace,
------------------------------------------------------------
java.lang.ClassCastException
 at org.apache.velocity.tools.struts.StrutsUtils.getMessageResources(Unknown 
Source)
 at org.apache.velocity.tools.struts.MessageResourcesTool.getResources(Unknown 
Source)
 at org.apache.velocity.tools.struts.MessageTool.get(Unknown Source)
 at org.apache.velocity.tools.struts.MessageTool.get(Unknown Source)
....
------------------------------------------------------------

changed the "key" of the message resource to "destination" (notice the 's' 
missing)

using the new key value... and it works :/

thats using velocity-tools-1.1

I also have other resources that use the same notation, 
<message-resources parameter="IndexResources" key="index" />

and cause me no problems.

Thanks in advance,
Markos Charatzas

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Application Resources and TextTool

Posted by Nathan Bubna <nb...@gmail.com>.
On Fri, 11 Feb 2005 10:15:20 +0200, Markos Charatzas <xa...@forthnet.gr> wrote:
> On Thursday 10 February 2005 17:50, Nathan Bubna wrote:
> > i only rarely put things directly into the
> > request myself.  i mostly use tools to access my request scoped data.
> > those are easy enough to keep track of in my toolbox.xml file.
> 
> So how do u go on about data that you want to make available to Velocity? You
> have to call "request.setAttribute()"

i use the toolbox support that's built into the VelocityViewServlet to
automatically provide context tools for every request and template.  i
then use these tools to "pull" most of my data, and i only
occasionally use request.setAttribute() and friends to "push" data to
particular templates.

see http://jakarta.apache.org/velocity/tools/view/ for more info.

> > but here's an off-the-top-of-my-head suggestion you could do to help
> > avoid namespace collisions like this:  use different naming
> > schemes/prefixes for different parts of your application.  for
> > instance, you could prefix all your resource bundle keys with "rb_"
> > or something like tha
> 
> Yeah, that's what I did in the end!
> Thanks for your support Nathan.

no prob.  glad to help!

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Application Resources and TextTool

Posted by Markos Charatzas <xa...@forthnet.gr>.
On Thursday 10 February 2005 17:50, Nathan Bubna wrote:
> i only rarely put things directly into the
> request myself.  i mostly use tools to access my request scoped data.
> those are easy enough to keep track of in my toolbox.xml file.

So how do u go on about data that you want to make available to Velocity? You 
have to call "request.setAttribute()"

>
> but here's an off-the-top-of-my-head suggestion you could do to help
> avoid namespace collisions like this:  use different naming
> schemes/prefixes for different parts of your application.  for
> instance, you could prefix all your resource bundle keys with "rb_"
> or something like tha

Yeah, that's what I did in the end!
Thanks for your support Nathan.

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Application Resources and TextTool

Posted by Nathan Bubna <nb...@gmail.com>.
Yep, that's sure to be the problem.  As for keeping record of
everything you put in the request, i'm not sure what the best way to
do this is.  personally, i only rarely put things directly into the
request myself.  i mostly use tools to access my request scoped data. 
those are easy enough to keep track of in my toolbox.xml file.

but here's an off-the-top-of-my-head suggestion you could do to help
avoid namespace collisions like this:  use different naming
schemes/prefixes for different parts of your application.  for
instance, you could prefix all your resource bundle keys with "rb_" 
or something like that.

On Thu, 10 Feb 2005 12:27:25 +0200, Markos Charatzas <xa...@forthnet.gr> wrote:
> Hello Nathan,
> 
> Thank you for your prompt and detailed response.
> 
> Yeah its true that I use request.setAttribute("destinations", destinations) at
> some point before rendering the template so that what is must be causing the
> problem.
> 
> So...does that mean that I have to keep a record of every possible entry made
> to the request? How do I go on about this?
> 
> Thanks in advance,
> Markos Charatzas
> 
> On Wednesday 09 February 2005 19:25, Nathan Bubna wrote:
> > the relevant code (in veltools 1.1's StrutsUtils) is doing the following:
> >
> >         resources = (MessageResources) request.getAttribute(bundle +
> > moduleConfig.getPrefix());
> >
> >         if (resources == null) {
> >             resources = (MessageResources) app.getAttribute(bundle +
> > moduleConfig.getPrefix());
> >         }
> >
> > this seems to indicate that there is something in either your request
> > attributes or servlet context attributes under the key "destinationsX"
> > (where X is your module config prefix) that is not a MessageResources
> > object.  i'm not sure how this would happen, but it is.  for tracking
> > the problem down, you might first try retrieving that object yourself
> > and finding out what it is.  you might also grep your app to find any
> > other place that an object would end up in your request or servlet
> > context attributes with that same key, because something is probably
> > doing so and thus replacing the MessageResources object that should be
> > there.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Application Resources and TextTool

Posted by Markos Charatzas <xa...@forthnet.gr>.
Hello Nathan,

Thank you for your prompt and detailed response.

Yeah its true that I use request.setAttribute("destinations", destinations) at 
some point before rendering the template so that what is must be causing the 
problem.

So...does that mean that I have to keep a record of every possible entry made 
to the request? How do I go on about this?

Thanks in advance,
Markos Charatzas

On Wednesday 09 February 2005 19:25, Nathan Bubna wrote:
> the relevant code (in veltools 1.1's StrutsUtils) is doing the following:
>
>         resources = (MessageResources) request.getAttribute(bundle +
> moduleConfig.getPrefix());
>
>         if (resources == null) {
>             resources = (MessageResources) app.getAttribute(bundle +
> moduleConfig.getPrefix());
>         }
>
> this seems to indicate that there is something in either your request
> attributes or servlet context attributes under the key "destinationsX"
> (where X is your module config prefix) that is not a MessageResources
> object.  i'm not sure how this would happen, but it is.  for tracking
> the problem down, you might first try retrieving that object yourself
> and finding out what it is.  you might also grep your app to find any
> other place that an object would end up in your request or servlet
> context attributes with that same key, because something is probably
> doing so and thus replacing the MessageResources object that should be
> there.

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Application Resources and TextTool

Posted by Nathan Bubna <nb...@gmail.com>.
the relevant code (in veltools 1.1's StrutsUtils) is doing the following:

        resources = (MessageResources) request.getAttribute(bundle +
moduleConfig.getPrefix());

        if (resources == null) {
            resources = (MessageResources) app.getAttribute(bundle +
moduleConfig.getPrefix());
        }

this seems to indicate that there is something in either your request
attributes or servlet context attributes under the key "destinationsX"
(where X is your module config prefix) that is not a MessageResources
object.  i'm not sure how this would happen, but it is.  for tracking
the problem down, you might first try retrieving that object yourself
and finding out what it is.  you might also grep your app to find any
other place that an object would end up in your request or servlet
context attributes with that same key, because something is probably
doing so and thus replacing the MessageResources object that should be
there.


On Wed, 9 Feb 2005 12:26:05 +0200, Markos Charatzas <xa...@forthnet.gr> wrote:
> Hi all,
> 
> I get this weird bug(?) with TextTool.
> On my struts-config.xml I declare the following message resource
> 
> <message-resources parameter="DestinationsResources" key="destinations" />
> 
> then in my template I use the textool to retrieve a value from that resource
> 
> $text.get('title.img', 'destinations')
> 
> and I get a ClassCastException with the following stack trace,
> ------------------------------------------------------------
> java.lang.ClassCastException
>  at org.apache.velocity.tools.struts.StrutsUtils.getMessageResources(Unknown
> Source)
>  at org.apache.velocity.tools.struts.MessageResourcesTool.getResources(Unknown
> Source)
>  at org.apache.velocity.tools.struts.MessageTool.get(Unknown Source)
>  at org.apache.velocity.tools.struts.MessageTool.get(Unknown Source)
> ....
> ------------------------------------------------------------
> 
> changed the "key" of the message resource to "destination" (notice the 's'
> missing)
> 
> using the new key value... and it works :/
> 
> thats using velocity-tools-1.1
> 
> I also have other resources that use the same notation,
> <message-resources parameter="IndexResources" key="index" />
> 
> and cause me no problems.
> 
> Thanks in advance,
> Markos Charatzas
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org