velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Wilson" <andrew.wil...@db.com>
Subject RE: Usage question.
Date Tue, 18 Jan 2005 23:29:07 GMT
Thanks, that's great!

OK, so the problem is that it doesn't work with static members eg.

public static final String ID = "ID"

When I change this to 

public String getID() { return "ID" }

It does work.

Is there any way the static version could be made to work?  

Many thanks,
Andrew.

-----Original Message-----
From: shinobu.kawai@gmail.com [mailto:shinobu.kawai@gmail.com] 
Sent: Wednesday, 19 January 2005 12:54 AM
To: velocity-user@jakarta.apache.org
Subject: Re: Usage question.

Hi Andrew,

> ie the definition is (with package etc)
> 
> public static final String com.foo.Request.ID = "ID";
> 
> Then I use this to put things in a HashMap.
> 
> I can get this to work using
> 
> ${request.getProperty("ID")};
> 
> But I wanted the compile time safety of :
> 
> ${request.getProperty(Request.ID")};

Don't know much about WebMacro, but I can think of a couple ways.

1. Put Request.ID in the context.
Let's say, $id.  Then you can do:
   ${request.getProperty($id)}

2. Put Request in the context, and make a getter method.
Let's say $req and #getId().  Then you can do:
   ${request.getProperty($req.id)}

3. Haven't tried it with static fields, but the PublicFieldUberspect.
   http://wiki.apache.org/jakarta-velocity/PublicFieldUberspect
## You'll still need an instance of Request in the Context.

4. Haven't tried it, but I found a tool here:
 
http://jakarta.apache.org/velocity/api/org/apache/velocity/app/FieldMethod
izer.html

Hope that helps.  :)

Best regards,
-- Shinobu

--
Shinobu "Kawai" Yoshida <shinobu.kawai@gmail.com>

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

RE:

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


Mime
View raw message