You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Russell Neufeld <ru...@hds.com> on 2009/04/17 19:58:19 UTC
Comparing a request parameter to a string literal
Hi all,
I'm still coming up the learning curve on Struts2, and I've come
across something I can't explain. Hopefully you guys out there can help
me understand this. I have a request parameter "status" set to
"invalid" which I'd like to access from within a JSP. If I use the
following line:
<s:property value="#parameters.status"/>
I see "invalid" written to the HTML, which is what I expect.
However, if I try to use that in an expression, like this:
<s:if test='#parameters.status == "invalid"'>
this always evaluates to false. Similarly, this:
<s:property value="#parameters.status == 'invalid'"/>
prints out "false" to the HTML output. However, if I do the following:
<s:set var="foo">bar</s:set>
<s:property value="#foo == 'bar'"/>
that prints out "true" to the HTML output. Yet this:
<s:set var="status" value="#parameters.status"/>
<s:property value="#status == 'invalid'"/>
prints out "false" to the HTML output.
Can someone help me understand this behaviour please? Any ideas on
how to compare a request parameter to a string literal? Thanks,
Russ
Re: Comparing a request parameter to a string literal
Posted by Russell Neufeld <ru...@hds.com>.
Thanks. Yeah, that's good practice. Didn't seem to fix my problem
though. That still evaluated to false.
Pierre Lavignotte wrote:
> Hi,
>
> you should consider comparing strings with the equals() method :
>
> "invalid".equals(#parameters.status)
>
>
>
> Cordialement,
> Pierre Lavignotte
> Ingénieur Conception & Développement
> http://pierre.lavignotte.googlepages.com
>
>
> On Fri, Apr 17, 2009 at 8:01 PM, Terry Gardner <Te...@sun.com>wrote:
>
>
>> try <s:if test='%{#parameters.status == "invalid"}'>
>>
>>
>> On Apr 17, 2009, at 1:58 PM, Russell Neufeld wrote:
>>
>> Hi all,
>>
>>> I'm still coming up the learning curve on Struts2, and I've come across
>>> something I can't explain. Hopefully you guys out there can help me
>>> understand this. I have a request parameter "status" set to "invalid" which
>>> I'd like to access from within a JSP. If I use the following line:
>>>
>>> <s:property value="#parameters.status"/>
>>>
>>> I see "invalid" written to the HTML, which is what I expect. However, if
>>> I try to use that in an expression, like this:
>>>
>>> <s:if test='#parameters.status == "invalid"'>
>>>
>>> this always evaluates to false. Similarly, this:
>>>
>>> <s:property value="#parameters.status == 'invalid'"/>
>>>
>>> prints out "false" to the HTML output. However, if I do the following:
>>>
>>> <s:set var="foo">bar</s:set>
>>> <s:property value="#foo == 'bar'"/>
>>>
>>> that prints out "true" to the HTML output. Yet this:
>>>
>>> <s:set var="status" value="#parameters.status"/>
>>> <s:property value="#status == 'invalid'"/>
>>>
>>> prints out "false" to the HTML output.
>>>
>>> Can someone help me understand this behaviour please? Any ideas on how
>>> to compare a request parameter to a string literal? Thanks,
>>>
>>> Russ
>>>
>>>
>> ---------------------------------------------------------------------
>> 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: Comparing a request parameter to a string literal
Posted by Pierre Lavignotte <pi...@gmail.com>.
Hi,
you should consider comparing strings with the equals() method :
"invalid".equals(#parameters.status)
Cordialement,
Pierre Lavignotte
Ingénieur Conception & Développement
http://pierre.lavignotte.googlepages.com
On Fri, Apr 17, 2009 at 8:01 PM, Terry Gardner <Te...@sun.com>wrote:
> try <s:if test='%{#parameters.status == "invalid"}'>
>
>
> On Apr 17, 2009, at 1:58 PM, Russell Neufeld wrote:
>
> Hi all,
>>
>> I'm still coming up the learning curve on Struts2, and I've come across
>> something I can't explain. Hopefully you guys out there can help me
>> understand this. I have a request parameter "status" set to "invalid" which
>> I'd like to access from within a JSP. If I use the following line:
>>
>> <s:property value="#parameters.status"/>
>>
>> I see "invalid" written to the HTML, which is what I expect. However, if
>> I try to use that in an expression, like this:
>>
>> <s:if test='#parameters.status == "invalid"'>
>>
>> this always evaluates to false. Similarly, this:
>>
>> <s:property value="#parameters.status == 'invalid'"/>
>>
>> prints out "false" to the HTML output. However, if I do the following:
>>
>> <s:set var="foo">bar</s:set>
>> <s:property value="#foo == 'bar'"/>
>>
>> that prints out "true" to the HTML output. Yet this:
>>
>> <s:set var="status" value="#parameters.status"/>
>> <s:property value="#status == 'invalid'"/>
>>
>> prints out "false" to the HTML output.
>>
>> Can someone help me understand this behaviour please? Any ideas on how
>> to compare a request parameter to a string literal? Thanks,
>>
>> Russ
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: Comparing a request parameter to a string literal
Posted by Russell Neufeld <ru...@hds.com>.
Thanks for the suggestion. That did not work. Evaluates to false.
Terry Gardner wrote:
> try <s:if test='%{#parameters.status == "invalid"}'>
>
> On Apr 17, 2009, at 1:58 PM, Russell Neufeld wrote:
>
>
>> Hi all,
>>
>> I'm still coming up the learning curve on Struts2, and I've come
>> across something I can't explain. Hopefully you guys out there can
>> help me understand this. I have a request parameter "status" set to
>> "invalid" which I'd like to access from within a JSP. If I use the
>> following line:
>>
>> <s:property value="#parameters.status"/>
>>
>> I see "invalid" written to the HTML, which is what I expect.
>> However, if I try to use that in an expression, like this:
>>
>> <s:if test='#parameters.status == "invalid"'>
>>
>> this always evaluates to false. Similarly, this:
>>
>> <s:property value="#parameters.status == 'invalid'"/>
>>
>> prints out "false" to the HTML output. However, if I do the
>> following:
>>
>> <s:set var="foo">bar</s:set>
>> <s:property value="#foo == 'bar'"/>
>>
>> that prints out "true" to the HTML output. Yet this:
>>
>> <s:set var="status" value="#parameters.status"/>
>> <s:property value="#status == 'invalid'"/>
>>
>> prints out "false" to the HTML output.
>>
>> Can someone help me understand this behaviour please? Any ideas
>> on how to compare a request parameter to a string literal? Thanks,
>>
>> Russ
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: Comparing a request parameter to a string literal
Posted by Terry Gardner <Te...@Sun.COM>.
try <s:if test='%{#parameters.status == "invalid"}'>
On Apr 17, 2009, at 1:58 PM, Russell Neufeld wrote:
> Hi all,
>
> I'm still coming up the learning curve on Struts2, and I've come
> across something I can't explain. Hopefully you guys out there can
> help me understand this. I have a request parameter "status" set to
> "invalid" which I'd like to access from within a JSP. If I use the
> following line:
>
> <s:property value="#parameters.status"/>
>
> I see "invalid" written to the HTML, which is what I expect.
> However, if I try to use that in an expression, like this:
>
> <s:if test='#parameters.status == "invalid"'>
>
> this always evaluates to false. Similarly, this:
>
> <s:property value="#parameters.status == 'invalid'"/>
>
> prints out "false" to the HTML output. However, if I do the
> following:
>
> <s:set var="foo">bar</s:set>
> <s:property value="#foo == 'bar'"/>
>
> that prints out "true" to the HTML output. Yet this:
>
> <s:set var="status" value="#parameters.status"/>
> <s:property value="#status == 'invalid'"/>
>
> prints out "false" to the HTML output.
>
> Can someone help me understand this behaviour please? Any ideas
> on how to compare a request parameter to a string literal? Thanks,
>
> Russ
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Comparing a request parameter to a string literal
Posted by Russell Neufeld <ru...@hds.com>.
Ahh! It's an array! So instead of
<s:if test='#parameters.status == "invalid"'>
I need to do this:
<s:if test='#parameters.status[0] == "invalid"'>
Thank you!
Russ
Dave Newton wrote:
> Russell Neufeld wrote:
>
>> I'm still coming up the learning curve on Struts2, and I've come
>> across something I can't explain. Hopefully you guys out there can help
>> me understand this. I have a request parameter "status" set to
>> "invalid" which I'd like to access from within a JSP. If I use the
>> following line:
>>
>> <s:property value="#parameters.status"/>
>>
>> I see "invalid" written to the HTML, which is what I expect.
>> However, if I try to use that in an expression, like this:
>>
>> <s:if test='#parameters.status == "invalid"'>
>>
>> this always evaluates to false.
>>
>
> It might be interesting to see what the #parameters.status type is.
>
> (That's a hint.)
>
> Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: Comparing a request parameter to a string literal
Posted by Dave Newton <ne...@yahoo.com>.
Russell Neufeld wrote:
> I'm still coming up the learning curve on Struts2, and I've come
> across something I can't explain. Hopefully you guys out there can help
> me understand this. I have a request parameter "status" set to
> "invalid" which I'd like to access from within a JSP. If I use the
> following line:
>
> <s:property value="#parameters.status"/>
>
> I see "invalid" written to the HTML, which is what I expect.
> However, if I try to use that in an expression, like this:
>
> <s:if test='#parameters.status == "invalid"'>
>
> this always evaluates to false.
It might be interesting to see what the #parameters.status type is.
(That's a hint.)
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org