You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jason Weinstein <JW...@SeeBeyond.com> on 2002/08/24 01:50:13 UTC
unexpected output with example
I am using Velocity 1.2. I am experiencing unexpected output. The example
follows. I am wondering if this bug? is resolved in more current revisions
or perhaps if I am doing something incorrectly. Any feedback would be
helpful.
Example
#set( $package = "com.hello" )
${package}
${package.replace('.','_')}
Actual Output
com.hello
${package.replace('.','_')}
Expected Output
com.hello
com_hello
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: unexpected output with example
Posted by Damian Gajda <dg...@ngo.pl>.
Once again...
I've noticed some c'n'p problems :)
> public class StringTool
> {
> public String replace(String inputStr, String oldChar, String
> newChar)
^^^
> {
> if(inputStr == null || oldChar == null || newChar == null)
^^^
> {
> return null;
> }
>
> return inputStr.replace(oldChar.charAt(0), newChar.charAt(0));
> }
>
> }
>
Greetings,
--
Damian Gajda
Web Application Design and Consultancy
dgajda@ngo.pl
mobile +48 501 032 506
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: unexpected output with example
Posted by Damian Gajda <dg...@ngo.pl>.
Welcome,
<snip>
>
> Example
>
> #set( $package = "com.hello" )
>
> ${package}
>
> ${package.replace('.','_')}
Your problem comes from introspection. Replace takes two characters
(char) as parameters, and when You write '.' in Velocity, it is treated
as String. Introspection looks for replace(String, String) and does not
find it.
Maybe You can try with creating a tool with a followng API:
${stringTool.replace($package, '.', '_')}
Implementation would be:
public class StringTool
{
public String replace(String inputStr, String oldChar, String
oldChar)
{
if(inputStr == null || oldChar == null || oldChar == null)
{
return null;
}
return inputStr.replace(oldChar.charAt(0), newChar.charAt(0));
}
}
Greetings,
--
Damian Gajda
Web Application Design and Consultancy
dgajda@ngo.pl
mobile +48 501 032 506
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>