[ 
https://issues.apache.org/jira/browse/PIVOT-573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12888585#action_12888585
 ] 

Greg Brown commented on PIVOT-573:
----------------------------------

> First, the latter two alternatives require a ZipCodeValidator class, no? 

Yes. 

> generally speaking I don't think it's a fair assumption that the user is 
> working with a named class

WTKX/BXML wouldn't work very well if we couldn't make this assumption.  :-)  

The entire point of BXML is to instantiate and configure class instances. 
Static methods (like your factory method) are not associated with class 
instances, so they don't map well to BXML.

> With that out of the way, let me get to the meat of my argument. First, I 
> like the following alternative even better: 

<TextInput validator="$validator"> 
  <wtkx:script> 
    var validator = Packages.ms.allman.pivot.Validators.getZipCodeValidator(); 
  </wtkx:script> 
</TextInput> 

The problem with this is that the "validator" variable does not exist when it 
is dereferenced in the validator attribute. The script block needs to come 
before the <TextInput> tag. This would also be slightly more concise, since it 
eliminates the need for the closing </TextInput> tag.

Your suggestion implies that you might think the "validator" variable is scoped 
to the <TextInput> element, which it is not. All variables are local to the 
BXML file in which they are declared. So you wouldn't get any benefit by 
nesting it anyway.

It really is best to think of a BXML file as a shortcut to executing a bunch of 
"new" and "add()" operations yourself. It is a linear flow that is processed in 
almost exactly the same way that the code in a method or function is executed.

> Why should "$" expressions be limited to variable references when it's easy 
> to support general expressions?

Because it isn't necessary and it complicates the syntax. As I demonstrated in 
my previous comment, there are plenty of other ways you can accomplish this 
without needing to change the definition of the operator.


> Execute script expressions in WTKX component attributes
> -------------------------------------------------------
>
>                 Key: PIVOT-573
>                 URL: https://issues.apache.org/jira/browse/PIVOT-573
>             Project: Pivot
>          Issue Type: New Feature
>          Components: wtk-wtkx
>    Affects Versions: 1.5
>         Environment: Using patched Pivot 1.5
>            Reporter: Michael Allman
>         Attachments: script_expressions_in_attributes.patch
>
>
> The attached patch allows users to put arbitrary script expressions in wtkx 
> component attributes.  This provides a superset of existing functionality, 
> which allows the user to reference an object by its wtkx:id.
> For example, I have a Java class ms.allman.pivot.Validators with a static 
> method getZipCodeValidator() that returns a Validator.  Then the following 
> WTKX fragment sets a zip code validator on the given TextInput:
> <TextInput 
> validator="$Packages.ms.allman.pivot.Validators.getZipCodeValidator()"/>
> (This example assumes the use of the JavaScript engine for scripting.)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to