Yep. I tried passing 5 instead of 2 and it worked.
Thanks for your responses.
--- Shawn Church <shawn@boxity.com> wrote:
> Looking at the source, looks like a maxlen of <3 will fail. I didn't
> try to
> reproduce it, but it looks like a bug. As a test, please try a
> length of 3
> or greater. The 3 max results since the default suffix in this case
> is the
> String "...".
>
> You could also try invoking this method directly, specifying your own
> suffix
> having a shorter length, as in:
> $formatter.limitLen(2, $thingie.getStuff(), ":")
>
>
> public String limitLen(int maxlen,
> String string,
> String suffix)
> {
> String ret = string;
> if (string.length() > maxlen)
> {
> ret = string.substring(0, maxlen - suffix.length()) +
> suffix;
> }
> return ret;
> }
>
>
> Shawn
>
> ----- Original Message -----
> From: "Dhruva B. Reddy" <sledgehammer2010@yahoo.com>
> To: <velocity-user@jakarta.apache.org>
> Sent: Tuesday, July 01, 2003 11:41 AM
> Subject: Can't figure out VelocityFormatter
>
>
> > I am trying to use the VelocityFormatter class. I have the
> following
> > in my Java code:
> >
> > context.put("formatter", new VelocityFormatter(context));
> > context.put("thingie", stuff);
> >
> > In the template, I have the following:
> >
> > $formatter.limitLen(2, $thingie.getStuff())
> >
> > This method call throws a StringIndexOutOfBoundsException. Yet,
> when I
> > just have the following in the template:
> >
> > $thingie.getStuff()
> >
> > I get the expected output.
> >
> > Can someone tell me what I'm doing wrong?
> >
> > Thanks,
> > Dhruva
> >
> > __________________________________
> > Do you Yahoo!?
> > SBC Yahoo! DSL - Now only $29.95 per month!
> > http://sbc.yahoo.com
> >
> >
> ---------------------------------------------------------------------
> > 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
>
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
|