Re: Combining default! and ?number

Jonathan Revusky <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Klotz, Leigh wrote:
> In FM 2.3.12, I'd like to assign a variable to be a number which is
> either parsed from a string parameter (perhaps from a query string), or
> default it to a fixed constant.  I'm not sure if there's a concise
> syntax for doing this.
> 
> The first code I saw to do this was like this:
>  <#assign page>${pageArg!1}</#assign>			[1]
> 
> But then all users from then on had to do
>     page?number + 1
> to refer to it.  Unfortunately, that fails because page is now a number,
> and next time, page?number will fail.
> 
> So I changed it to this:
> 
> <#assign page = pageArg!1 />
> 
> This works when pageArg isn't specified, as does this
>    page + 1
> work properly on every iteration.
> 
> However, when pageArg it specified, it turns page into a string, so it
> fails again.

Hold on a sec. You're running into a bug in 2.4. I just checked and

${12?number}

works in 2.3 but fails in 2.4 because somehow, it thinks the lhs has to 
be a string, which is kind of true, but actually, if the lhs is already 
a number, it should just return the number.

So the above should work, it's a bug.

JR


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.