Hello all, I wrote a post on xwiki-users this morning, because someone told me there is where the questions about "how to" are supposed to go, but nobody answered (and I figured it out by myself, with the help of Sergiu) so I'll try my luck here, as I really need some help. In a velocity script I receive a request and I take the value with #set($input =$request.get("param")). My question is, how can I apply string transformations (i.e to lowercase, split the string etc) to this variable($input) in velocity? I looked everywhere but I guess I miss something. Please help! Thank you, Evelina Slatineanu
Hi Evelyne, On May 10, [email protected] wrote :
My question is, how can I apply string transformations (i.e to lowercase, split the string etc) to this variable($input) in velocity? I looked everywhere but I guess I miss something. Please help!
To split a string you may use xwiki.split(String str, String sep) (see com.xpn.xwiki.api.xwiki). I've never tried it myself but it should do the trick. For "lowercasing" I'm not sure if you can do this without calling a java helper function, but i'm really not a velocity expert. Kind regards, Pablo
Velocity variables are Java objects, on which you can call any (public) method you could call in a Java program. In your case, the $input variable is a String, so you can call $input.toLowerCase(). Whenever you have a variable in Velocity, and don't know what to do with it, here are some tips: 1. Write $myUnknownVar.class and view the result. This will show you the class of that object. 2. Look at the public methods that class offers. 3. Found the method you were looking for? Call it: $myUnknownVar.doSomething() Sergiu. On 5/10/07, [email protected] <[email protected]> wrote:
Hello all, I wrote a post on xwiki-users this morning, because someone told me there is where the questions about "how to" are supposed to go, but nobody answered (and I figured it out by myself, with the help of Sergiu) so I'll try my luck here, as I really need some help. In a velocity script I receive a request and I take the value with #set($input =$request.get("param")). My question is, how can I apply string transformations (i.e to lowercase, split the string etc) to this variable($input) in velocity? I looked everywhere but I guess I miss something. Please help! Thank you, Evelina Slatineanu
Hi Evelina, The jakarta velocity gives you more information related to your question. You could also join the velocity forum in : velocity-user.jakarta.apache.org As for your question, I am using often such kind of transformations: - $input.substring(ind1,ind2).toUpperCase() or $input.toUpperCase() - $input.concat("string") - $input.split("string") - etc... Hope that this answer help you. Cheers ------------ Youcef
Hello all, I wrote a post on xwiki-users this morning, because someone told me there is where the questions about "how to" are supposed to go, but nobody answered (and I figured it out by myself, with the help of Sergiu) so I'll try my luck here, as I really need some help. In a velocity script I receive a request and I take the value with #set($input =$request.get("param")). My question is, how can I apply string transformations (i.e to lowercase, split the string etc) to this variable($input) in velocity? I looked everywhere but I guess I miss something. Please help! Thank you, Evelina Slatineanu
--------------------------------------------------------------------------------
-- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
participants (4)
-
evelyne24@gmail.com -
Pablo Oliveira -
Sergiu Dumitriu -
Youcef BEY