You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paul Ferraro <pa...@softhome.net> on 2003/09/02 18:48:40 UTC

RE: string bug in OGNL?

Rather than use an inline component, you might want to move the embedded
component definition to your page/component specification (.page/.jwc
file) to avoid quote issues.  The v3.0 of Tapestry allows the following:

<component id="insertFoo" type="Insert">
	<binding name="value">value.foo == "Y" ? "Yes" : "No"</binding>
</component>

Check out this page for details:
http://jakarta.apache.org/tapestry/doc/TapestryUsersGuide/spec.binding.html

Hope this helps,

Paul

On Fri, 2003-08-29 at 18:42, Dustin Frazier wrote:
> Yeah, it just silently failed.  The expression to the left of the ? always
> evaluates to false, so the second option after the : is returned.  I guess I
> thought since the field on the left was of type java.lang.String, it would
> know to treat 'Y' as a string.  Actually, I wasn't thinking about this stuff
> at all, which is why it was really tricky thing to debug!  Now that I know
> what's going on, I'm surprised that foo.equals('Y') fails when foo = "Y" (in
> Java), but maybe there are subtle i18n issues that I'm not thinking about.  It
> is Friday at 6:45pm... :)
> 
> I'll stick with double quotes around single-character strings for now...
> 
> Dustin
> 
> -----Original Message-----
> From: Drew Davidson [mailto:drew@ognl.org] 
> Sent: Friday, August 29, 2003 5:15 PM
> To: Dustin Frazier
> Cc: tapestry-user@jakarta.apache.org; ognl-interest@lists.ognl.org
> Subject: Re: string bug in OGNL?
> 
> 
> Dustin Frazier wrote:
> 
> >Posting this to both the OGNL interest list and the Tapestry user list 
> >only because I've never seen any traffic on the OGNL list (I'm new, 
> >though)...
> >  
> >
> Mostly that's because OGNL is bug-free. :-)
> 
> >I found what I think is a bug in either Tapestry or (more likely) OGNL.  
> >The following bit of code works as expected (foo on value is a string):
> >
> ><span jwcid="@Insert" value='ognl:value.foo == "Y" ? "Yes" : "No"'/> 
> >[works great!]
> >
> >However, swapping the single and double quotes in the value attribute 
> >doesn't
> >work:
> >
> ><span jwcid="@Insert" value="ognl:value.foo == 'Y' ? 'Yes' : 'No'"/> 
> >[doesn't work]
> >  
> >
> You are getting an exception or it just fails?  I presume it fails 
> (String.equals(Character) will always fail).
> 
> >I'm using the latest OGNL (2.6.3) along with Tapestry 3.0b2.  Do I 
> >misunderstand how quoting works in OGNL and/or Tapestry?  I thought 
> >single and double quotes were interchangeable in the latest OGNL...
> >  
> >
> Well, the problem here is that the 'Y' is being turned into a single 
> Character.  The ' quote character does double duty as character quote 
> and as String quote.  You might have to encase this in new 
> java.lang.String(new char[]{'Y'}) to get your desired results (boy 
> that's ugly).
> 
> I know it's a pain but there is currently no way of telling if you want 
> a string or a character just by the quoting, so it makes an assuption.
> 
> - Drew