You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Fred Toth <ft...@synernet.com> on 2007/07/07 17:53:43 UTC
Can freemarker use OGNL null value handling?
Hi,
I'm a big fan of struts2 and freemarker, but I'm just now getting around
to using
the struts2 UI tags in freemarker.
It appears that "automatic null value handling" feature of struts2 is
not available from freemarker?
To be more specific: In jsp, you can do this:
<s:textfield name="user.firstName" value="${user.firstName}"/>
This works even when user doesn't exist because of the OGNL null value
handling.
OGNL discovers that user is null and creates a new user. Likewise for
firstName.
However, the same tag in freemarker does not work:
<@s:textfield name="user.firstName" value="${user.firstName}"/>
We get an exception "user is undefined". This is presumably because the
freemarker
expression language is being used, and not OGNL?
So I'm amazed that I have not been able to find a single mention of this
very important issue!
Am I missing a simple work-around?
Can anyone comment?
Thanks,
Fred Toth
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Can freemarker use OGNL null value handling?
Posted by Musachy Barroso <mu...@gmail.com>.
If I'm not wrong (big if there :) ), that ${user.firstName} is evaluated as
a FreeMarker expression (not a JSTL one), and FreeMarker is sensitive about
nulls:
http://freemarker.sourceforge.net/docs/app_faq.html#faq_picky_about_missing_vars
either use %{user.firstName}, or FreeMarker null operators:
http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_missing
musachy
On 7/7/07, Fred Toth <ft...@synernet.com> wrote:
>
> Hi,
>
> I'm a big fan of struts2 and freemarker, but I'm just now getting around
> to using
> the struts2 UI tags in freemarker.
>
> It appears that "automatic null value handling" feature of struts2 is
> not available from freemarker?
>
> To be more specific: In jsp, you can do this:
>
> <s:textfield name="user.firstName" value="${user.firstName}"/>
>
> This works even when user doesn't exist because of the OGNL null value
> handling.
> OGNL discovers that user is null and creates a new user. Likewise for
> firstName.
>
> However, the same tag in freemarker does not work:
>
> <@s:textfield name="user.firstName" value="${user.firstName}"/>
>
> We get an exception "user is undefined". This is presumably because the
> freemarker
> expression language is being used, and not OGNL?
>
> So I'm amazed that I have not been able to find a single mention of this
> very important issue!
>
> Am I missing a simple work-around?
>
> Can anyone comment?
>
> Thanks,
>
> Fred Toth
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
"Hey you! Would you help me to carry the stone?" Pink Floyd
Re: Can freemarker use OGNL null value handling?
Posted by Fred Toth <ft...@synernet.com>.
Thanks. That was it! I must have been through the doc a dozen times, but I
missed the '$' vs '%' issue.
Thanks again.
Fred
Dale Newfield wrote:
> Fred Toth wrote:
>> To be more specific: In jsp, you can do this:
>>
>> <s:textfield name="user.firstName" value="${user.firstName}"/>
>>
>> This works even when user doesn't exist because of the OGNL null
>> value handling.
>
> If you use ${}, you're not using ognl, but rather el.
>
> Try replacing your $'s with %'s.
>
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Can freemarker use OGNL null value handling?
Posted by Dale Newfield <Da...@Newfield.org>.
Fred Toth wrote:
> To be more specific: In jsp, you can do this:
>
> <s:textfield name="user.firstName" value="${user.firstName}"/>
>
> This works even when user doesn't exist because of the OGNL null value
> handling.
If you use ${}, you're not using ognl, but rather el.
Try replacing your $'s with %'s.
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org