You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by st...@spamgourmet.com on 2011/07/13 00:11:27 UTC

Using string literals or references to objects in @s.url?

Which of these is more correct when using Struts2 freemarker tag dynamic attributes for @s.url:

	<@s.url action="viewitem" itemid="${item.itemid?c}"  />
or
	<@s.url action="viewitem" itemid=item.itemid />

I've been favoring the second example, since it doesn't require me to remember to do "?c" for my integer arguments, and appears to properly exclude parameters that have null values from the resulting URL.

This is common enough that I believe the "Attribute Types" section of the freemarker tags document should include an example for an integer.   It could mention that you might prefer to pass the freemarker variable instead of passing the argument as a string, where you'll be required to remember to use "?c" for numbers to avoid a comma being passed resulting in ognl.MethodFailException for the integer-only setter.
	http://struts.apache.org/2.2.3/docs/freemarker-tags.html

Or maybe it's "obvious."

-rgm

Re: Using string literals or references to objects in @s.url?

Posted by Dave Newton <da...@gmail.com>.
On Tuesday, July 12, 2011,  <st...@spamgourmet.com> wrote:
> Which of these is more correct when using Struts2 freemarker tag dynamic attributes for @s.url:
>
>         <@s.url action="viewitem" itemid="${item.itemid?c}"  />
> or
>         <@s.url action="viewitem" itemid=item.itemid />
>
> I've been favoring the second example, since it doesn't require me to remember to do "?c" for my integer arguments, and appears to properly exclude parameters that have null values from the resulting URL.

I wouldn't have guessed it'd render the value, actually. I guess the
tag itself is doing the eval, and not FreeMarker, in the second case,
maybe?

> This is common enough that I believe the "Attribute Types" section of the freemarker tags document should include an example for an integer. [...] Or maybe it's "obvious."

I don't know if it "obvious" or not, but it is a well-known FreeMarker
function and is documented pretty well. Like you said, it's common
enough, and the FreeMarker docs reflect this. No reason /not/ to have
an example, though.

Dave

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