You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Joe Germuska <jo...@germuska.com> on 2007/01/21 04:14:18 UTC
[S2] Freemarker Confusion
I've ran into an odd problem of my own and while I'm troubleshooting it, I'm
hitting some problems or confusion with Freemarker as it is used for the S2
UI tags. Can anyone help me understand this better?
I was getting a big yellow and red Freemarker trace in my rendered page
because an ${error} expression yielded null when using <s:actionerror>.
I'm assuming this is the result of an uncaught NullPointerException being
caught by Struts2, as the message for NPEs is often itself null. I actually
haven't yet figured out where this logic is, so question 1 is "which class
is actually catching my exception and routing to an 'error' page?"
Then, it seems like our templates should be prepared for the possibility of
a null message, especially if they are being invoked when an unexpected NPE
is caught -- a not unlikely scenario.
So I found this page of Freemarker documentation explaining how to deal with
empty values:
http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_missing
except that it doesn't seem to apply to the version of Freemarker (2.3.4)
that we're using. They're only up to 2.3.8 and they make a big fuss about
nulls -- can this be new just in those minor releases? Or is there
something I should understand about why those rules don't apply to
Freemarker as it is used in S2? I get an error when I try to use the syntax
for handling missing values
${error!"null"}
and the syntax for testing for nulls
${error??}
What am I missing?
After I get all that cleared up, the last question is whether or not we
ought to make a change to template/simple/actionerror.ftl so that it handles
this gracefully. I guess I already think the answer is "yes", and I'd do it
myself, except apparently I haven't found Freemarker syntax documentation
which is right for our environment.
Thanks
Joe
--
Joe Germuska
Joe@Germuska.com * http://blog.germuska.com
"The truth is that we learned from João forever to be out of tune."
-- Caetano Veloso
Re: [S2] Freemarker Confusion
Posted by Tom Schneider <sc...@gmail.com>.
No, not overkill at all. I like that better than my empty string. (The
select tag should probably be updated to output something like that for
null keys and null values)
Tom
Joe Germuska wrote:
> Tom:
>
> Thanks for your help... I see now that the syntax I was trying to use
> was
> added in Freemarker 2.3.7
>
> http://freemarker.sourceforge.net/docs/versions_2_3_7.html
>
> Now... is an empty string the right result? maybe ${error?default("<!--
> null error -->")} ?
>
> is that overkill?
>
> Joe
>
> On 1/20/07, Tom Schneider <sc...@gmail.com> wrote:
>>
>> Joe,
>> ${error} being null would imply that you have an item in the action
>> errors Collection that is null. (e.g. {"Error1", "Error2", null,
>> "Error4}) It seems like that would be an issue that occurs as the
>> errors are being populated. (I can't think of a valid use case where
>> you would have a null error message.)
>>
>> In spite of that, you could modify the template to handle this more
>> gracefully using the default function:
>> <li><span class="errorMessage">${error?default("")}</span></li>
>>
>> In general, I think there is room for improvement in the UI tags error
>> handling/reporting. I've already submitted patches for null handling in
>> the select tags--this is just another instance were nulls slip through
>> the cracks.
>> Tom
>>
>> Joe Germuska wrote:
>> > I've ran into an odd problem of my own and while I'm troubleshooting
>> > it, I'm
>> > hitting some problems or confusion with Freemarker as it is used for
>> > the S2
>> > UI tags. Can anyone help me understand this better?
>> >
>> > I was getting a big yellow and red Freemarker trace in my rendered
>> page
>> > because an ${error} expression yielded null when using
>> <s:actionerror>.
>> > I'm assuming this is the result of an uncaught NullPointerException
>> being
>> > caught by Struts2, as the message for NPEs is often itself null. I
>> > actually
>> > haven't yet figured out where this logic is, so question 1 is "which
>> > class
>> > is actually catching my exception and routing to an 'error' page?"
>> >
>> > Then, it seems like our templates should be prepared for the
>> > possibility of
>> > a null message, especially if they are being invoked when an
>> > unexpected NPE
>> > is caught -- a not unlikely scenario.
>> >
>> > So I found this page of Freemarker documentation explaining how to
>> > deal with
>> > empty values:
>> >
>> >
>> http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_missing
>>
>> >
>> >
>> > except that it doesn't seem to apply to the version of Freemarker
>> (2.3.4
>> )
>> > that we're using. They're only up to 2.3.8 and they make a big fuss
>> > about
>> > nulls -- can this be new just in those minor releases? Or is there
>> > something I should understand about why those rules don't apply to
>> > Freemarker as it is used in S2? I get an error when I try to use the
>> > syntax
>> > for handling missing values
>> > ${error!"null"}
>> > and the syntax for testing for nulls
>> > ${error??}
>> >
>> > What am I missing?
>> >
>> > After I get all that cleared up, the last question is whether or
>> not we
>> > ought to make a change to template/simple/actionerror.ftl so that it
>> > handles
>> > this gracefully. I guess I already think the answer is "yes", and I'd
>> > do it
>> > myself, except apparently I haven't found Freemarker syntax
>> documentation
>> > which is right for our environment.
>> >
>> > Thanks
>> > Joe
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
>> For additional commands, e-mail: dev-help@struts.apache.org
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: [S2] Freemarker Confusion
Posted by Joe Germuska <jo...@germuska.com>.
Tom:
Thanks for your help... I see now that the syntax I was trying to use was
added in Freemarker 2.3.7
http://freemarker.sourceforge.net/docs/versions_2_3_7.html
Now... is an empty string the right result? maybe ${error?default("<!--
null error -->")} ?
is that overkill?
Joe
On 1/20/07, Tom Schneider <sc...@gmail.com> wrote:
>
> Joe,
> ${error} being null would imply that you have an item in the action
> errors Collection that is null. (e.g. {"Error1", "Error2", null,
> "Error4}) It seems like that would be an issue that occurs as the
> errors are being populated. (I can't think of a valid use case where
> you would have a null error message.)
>
> In spite of that, you could modify the template to handle this more
> gracefully using the default function:
> <li><span class="errorMessage">${error?default("")}</span></li>
>
> In general, I think there is room for improvement in the UI tags error
> handling/reporting. I've already submitted patches for null handling in
> the select tags--this is just another instance were nulls slip through
> the cracks.
> Tom
>
> Joe Germuska wrote:
> > I've ran into an odd problem of my own and while I'm troubleshooting
> > it, I'm
> > hitting some problems or confusion with Freemarker as it is used for
> > the S2
> > UI tags. Can anyone help me understand this better?
> >
> > I was getting a big yellow and red Freemarker trace in my rendered page
> > because an ${error} expression yielded null when using <s:actionerror>.
> > I'm assuming this is the result of an uncaught NullPointerException
> being
> > caught by Struts2, as the message for NPEs is often itself null. I
> > actually
> > haven't yet figured out where this logic is, so question 1 is "which
> > class
> > is actually catching my exception and routing to an 'error' page?"
> >
> > Then, it seems like our templates should be prepared for the
> > possibility of
> > a null message, especially if they are being invoked when an
> > unexpected NPE
> > is caught -- a not unlikely scenario.
> >
> > So I found this page of Freemarker documentation explaining how to
> > deal with
> > empty values:
> >
> >
> http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_missing
> >
> >
> > except that it doesn't seem to apply to the version of Freemarker (2.3.4
> )
> > that we're using. They're only up to 2.3.8 and they make a big fuss
> > about
> > nulls -- can this be new just in those minor releases? Or is there
> > something I should understand about why those rules don't apply to
> > Freemarker as it is used in S2? I get an error when I try to use the
> > syntax
> > for handling missing values
> > ${error!"null"}
> > and the syntax for testing for nulls
> > ${error??}
> >
> > What am I missing?
> >
> > After I get all that cleared up, the last question is whether or not we
> > ought to make a change to template/simple/actionerror.ftl so that it
> > handles
> > this gracefully. I guess I already think the answer is "yes", and I'd
> > do it
> > myself, except apparently I haven't found Freemarker syntax
> documentation
> > which is right for our environment.
> >
> > Thanks
> > Joe
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>
--
Joe Germuska
Joe@Germuska.com * http://blog.germuska.com
"The truth is that we learned from João forever to be out of tune."
-- Caetano Veloso
Re: [S2] Freemarker Confusion
Posted by Tom Schneider <sc...@gmail.com>.
Joe,
${error} being null would imply that you have an item in the action
errors Collection that is null. (e.g. {"Error1", "Error2", null,
"Error4}) It seems like that would be an issue that occurs as the
errors are being populated. (I can't think of a valid use case where
you would have a null error message.)
In spite of that, you could modify the template to handle this more
gracefully using the default function:
<li><span class="errorMessage">${error?default("")}</span></li>
In general, I think there is room for improvement in the UI tags error
handling/reporting. I've already submitted patches for null handling in
the select tags--this is just another instance were nulls slip through
the cracks.
Tom
Joe Germuska wrote:
> I've ran into an odd problem of my own and while I'm troubleshooting
> it, I'm
> hitting some problems or confusion with Freemarker as it is used for
> the S2
> UI tags. Can anyone help me understand this better?
>
> I was getting a big yellow and red Freemarker trace in my rendered page
> because an ${error} expression yielded null when using <s:actionerror>.
> I'm assuming this is the result of an uncaught NullPointerException being
> caught by Struts2, as the message for NPEs is often itself null. I
> actually
> haven't yet figured out where this logic is, so question 1 is "which
> class
> is actually catching my exception and routing to an 'error' page?"
>
> Then, it seems like our templates should be prepared for the
> possibility of
> a null message, especially if they are being invoked when an
> unexpected NPE
> is caught -- a not unlikely scenario.
>
> So I found this page of Freemarker documentation explaining how to
> deal with
> empty values:
>
> http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_missing
>
>
> except that it doesn't seem to apply to the version of Freemarker (2.3.4)
> that we're using. They're only up to 2.3.8 and they make a big fuss
> about
> nulls -- can this be new just in those minor releases? Or is there
> something I should understand about why those rules don't apply to
> Freemarker as it is used in S2? I get an error when I try to use the
> syntax
> for handling missing values
> ${error!"null"}
> and the syntax for testing for nulls
> ${error??}
>
> What am I missing?
>
> After I get all that cleared up, the last question is whether or not we
> ought to make a change to template/simple/actionerror.ftl so that it
> handles
> this gracefully. I guess I already think the answer is "yes", and I'd
> do it
> myself, except apparently I haven't found Freemarker syntax documentation
> which is right for our environment.
>
> Thanks
> Joe
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org