Interesting behavior of use-when fields

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Interesting behavior of use-when fields

Jacopo Cappellato-3
Today, while Anil and I were testing some new Ajax enhancements for  
the form widgets that Anil is working on I have realized that the use-
when attribute works in this way:

use-when="example==null"

is evaluated to:

TRUE if the example variable is declared and null
FALSE  if the example variable is declared and not null
FLASE if the example variable is NOT declared

In fact for the Beanshell interpreter (by the way... should we  
consider to use Groovy instead of Beanshell for the use-when scripts  
too?) an undeclared variable is void but not null.

There may be situations where the variable is not declared; it seems  
natural to me to use, in these situations, the field with use-
when="example==null".

However, there is a solution for this:

use-when="example==void || example==null"

but it is extra code (especially because we have to escape the |  
symbol with the & notation).
Or we may just remove the use-when attribute for the default field; I  
mean:

instead of:

<field name="statusId" use-when="example==null">...</field>
<field name="statusId" use-when="example!=null">...</field>

use the equivalent version (that works also if the example variable is  
not declared):

<field name="statusId">...</field>
<field name="statusId" use-when="example!=null">...</field>

Should we introduce this pattern?

Jacopo

Reply | Threaded
Open this post in threaded view
|

Re: Interesting behavior of use-when fields

Scott Gray
Hi Jacopo

I just ran a quick test and Groovy seems to throw an error when an
undeclared variable is used.

Scott

2008/6/5 Jacopo Cappellato <[hidden email]>:

>
> In fact for the Beanshell interpreter (by the way... should we consider to
> use Groovy instead of Beanshell for the use-when scripts too?) an undeclared
> variable is void but not null.
>
Reply | Threaded
Open this post in threaded view
|

Re: Interesting behavior of use-when fields

Ashish Vijaywargiya
Jacopo,

I liked the second option i.e

<field name="statusId">...</field>
<field name="statusId" use-when="example!=null">...</field>

--
Ashish


On Thu, Jun 5, 2008 at 6:06 AM, Scott Gray <[hidden email]> wrote:

> Hi Jacopo
>
> I just ran a quick test and Groovy seems to throw an error when an
> undeclared variable is used.
>
> Scott
>
> 2008/6/5 Jacopo Cappellato <[hidden email]>:
>
> >
> > In fact for the Beanshell interpreter (by the way... should we consider
> to
> > use Groovy instead of Beanshell for the use-when scripts too?) an
> undeclared
> > variable is void but not null.
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Interesting behavior of use-when fields

Jacques Le Roux
Administrator
I like it too, but what about Groovy from Scott's experience ?

Jacques

From: "Ashish Vijaywargiya" <[hidden email]>

> Jacopo,
>
> I liked the second option i.e
>
> <field name="statusId">...</field>
> <field name="statusId" use-when="example!=null">...</field>
>
> --
> Ashish
>
>
> On Thu, Jun 5, 2008 at 6:06 AM, Scott Gray <[hidden email]> wrote:
>
>> Hi Jacopo
>>
>> I just ran a quick test and Groovy seems to throw an error when an
>> undeclared variable is used.
>>
>> Scott
>>
>> 2008/6/5 Jacopo Cappellato <[hidden email]>:
>>
>> >
>> > In fact for the Beanshell interpreter (by the way... should we consider
>> to
>> > use Groovy instead of Beanshell for the use-when scripts too?) an
>> undeclared
>> > variable is void but not null.
>> >
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Interesting behavior of use-when fields

David E Jones
In reply to this post by Scott Gray

Does the groovy "?" operator thrown in different places solve this  
problem?

It seems like it's kind of like the "?if_exists" in FTL, and may help  
with things like this.

-David


On Jun 5, 2008, at 4:06 AM, Scott Gray wrote:

> Hi Jacopo
>
> I just ran a quick test and Groovy seems to throw an error when an
> undeclared variable is used.
>
> Scott
>
> 2008/6/5 Jacopo Cappellato <[hidden email]>:
>
>>
>> In fact for the Beanshell interpreter (by the way... should we  
>> consider to
>> use Groovy instead of Beanshell for the use-when scripts too?) an  
>> undeclared
>> variable is void but not null.
>>

Reply | Threaded
Open this post in threaded view
|

Re: Interesting behavior of use-when fields

Jacques Le Roux
Administrator
Yes, it should I guess.

BTW (and a bit OS) I don't think there is a default operator in Groovy like ! in freemarker
http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_missing_default

Jacques

From: "David E Jones" <[hidden email]>

>
> Does the groovy "?" operator thrown in different places solve this  problem?
>
> It seems like it's kind of like the "?if_exists" in FTL, and may help  with things like this.
>
> -David
>
>
> On Jun 5, 2008, at 4:06 AM, Scott Gray wrote:
>
>> Hi Jacopo
>>
>> I just ran a quick test and Groovy seems to throw an error when an
>> undeclared variable is used.
>>
>> Scott
>>
>> 2008/6/5 Jacopo Cappellato <[hidden email]>:
>>
>>>
>>> In fact for the Beanshell interpreter (by the way... should we  consider to
>>> use Groovy instead of Beanshell for the use-when scripts too?) an  undeclared
>>> variable is void but not null.
>>>
>

Reply | Threaded
Open this post in threaded view
|

Re: Interesting behavior of use-when fields

Scott Gray
In reply to this post by David E Jones
I can't see a standalone "?" operator but there is the safe navigation
operator "?." for accessing properties/methods, so I guess you could do
this:
use-when="context?.example==null"

Scott

2008/6/7 David E Jones <[hidden email]>:

>
> Does the groovy "?" operator thrown in different places solve this problem?
>
> It seems like it's kind of like the "?if_exists" in FTL, and may help with
> things like this.
>
> -David
>
>
>
> On Jun 5, 2008, at 4:06 AM, Scott Gray wrote:
>
>  Hi Jacopo
>>
>> I just ran a quick test and Groovy seems to throw an error when an
>> undeclared variable is used.
>>
>> Scott
>>
>> 2008/6/5 Jacopo Cappellato <[hidden email]>:
>>
>>
>>> In fact for the Beanshell interpreter (by the way... should we consider
>>> to
>>> use Groovy instead of Beanshell for the use-when scripts too?) an
>>> undeclared
>>> variable is void but not null.
>>>
>>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Interesting behavior of use-when fields

Scott Gray
In reply to this post by Jacques Le Roux
Hi Jacques

The shortcut ternary operator (?:) would work:
productTypeId = null;
if ("FINISHED_GOOD" == productTypeId ?: "FINISHED_GOOD")

Scott

2008/6/7 Jacques Le Roux <[hidden email]>:

> Yes, it should I guess.
>
> BTW (and a bit OS) I don't think there is a default operator in Groovy like
> ! in freemarker
> http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_missing_default
>
> Jacques
>
> From: "David E Jones" <[hidden email]>
>
>
>> Does the groovy "?" operator thrown in different places solve this
>>  problem?
>>
>> It seems like it's kind of like the "?if_exists" in FTL, and may help
>>  with things like this.
>>
>> -David
>>
>>
>> On Jun 5, 2008, at 4:06 AM, Scott Gray wrote:
>>
>>  Hi Jacopo
>>>
>>> I just ran a quick test and Groovy seems to throw an error when an
>>> undeclared variable is used.
>>>
>>> Scott
>>>
>>> 2008/6/5 Jacopo Cappellato <[hidden email]>:
>>>
>>>
>>>> In fact for the Beanshell interpreter (by the way... should we  consider
>>>> to
>>>> use Groovy instead of Beanshell for the use-when scripts too?) an
>>>>  undeclared
>>>> variable is void but not null.
>>>>
>>>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Interesting behavior of use-when fields

Ashish Vijaywargiya
Scott ,

In groovy we call it Elvis Operator (?:)   :-)

--
Ashish

On Fri, Jun 6, 2008 at 7:43 PM, Scott Gray <[hidden email]> wrote:

> Hi Jacques
>
> The shortcut ternary operator (?:) would work:
> productTypeId = null;
> if ("FINISHED_GOOD" == productTypeId ?: "FINISHED_GOOD")
>
> Scott
>
> 2008/6/7 Jacques Le Roux <[hidden email]>:
>
> > Yes, it should I guess.
> >
> > BTW (and a bit OS) I don't think there is a default operator in Groovy
> like
> > ! in freemarker
> >
> http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_missing_default
> >
> > Jacques
> >
> > From: "David E Jones" <[hidden email]>
> >
> >
> >> Does the groovy "?" operator thrown in different places solve this
> >>  problem?
> >>
> >> It seems like it's kind of like the "?if_exists" in FTL, and may help
> >>  with things like this.
> >>
> >> -David
> >>
> >>
> >> On Jun 5, 2008, at 4:06 AM, Scott Gray wrote:
> >>
> >>  Hi Jacopo
> >>>
> >>> I just ran a quick test and Groovy seems to throw an error when an
> >>> undeclared variable is used.
> >>>
> >>> Scott
> >>>
> >>> 2008/6/5 Jacopo Cappellato <[hidden email]>:
> >>>
> >>>
> >>>> In fact for the Beanshell interpreter (by the way... should we
>  consider
> >>>> to
> >>>> use Groovy instead of Beanshell for the use-when scripts too?) an
> >>>>  undeclared
> >>>> variable is void but not null.
> >>>>
> >>>>
> >>
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Interesting behavior of use-when fields

Jacques Le Roux
Administrator
In reply to this post by Scott Gray
Hi Scott,

Yes, so true, thanks.

Jacques

From: "Scott Gray" <[hidden email]>

> Hi Jacques
>
> The shortcut ternary operator (?:) would work:
> productTypeId = null;
> if ("FINISHED_GOOD" == productTypeId ?: "FINISHED_GOOD")
>
> Scott
>
> 2008/6/7 Jacques Le Roux <[hidden email]>:
>
>> Yes, it should I guess.
>>
>> BTW (and a bit OS) I don't think there is a default operator in Groovy like
>> ! in freemarker
>> http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_missing_default
>>
>> Jacques
>>
>> From: "David E Jones" <[hidden email]>
>>
>>
>>> Does the groovy "?" operator thrown in different places solve this
>>>  problem?
>>>
>>> It seems like it's kind of like the "?if_exists" in FTL, and may help
>>>  with things like this.
>>>
>>> -David
>>>
>>>
>>> On Jun 5, 2008, at 4:06 AM, Scott Gray wrote:
>>>
>>>  Hi Jacopo
>>>>
>>>> I just ran a quick test and Groovy seems to throw an error when an
>>>> undeclared variable is used.
>>>>
>>>> Scott
>>>>
>>>> 2008/6/5 Jacopo Cappellato <[hidden email]>:
>>>>
>>>>
>>>>> In fact for the Beanshell interpreter (by the way... should we  consider
>>>>> to
>>>>> use Groovy instead of Beanshell for the use-when scripts too?) an
>>>>>  undeclared
>>>>> variable is void but not null.
>>>>>
>>>>>
>>>
>>
>