You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by "Michael Allman (JIRA)" <ji...@apache.org> on 2010/07/14 10:08:50 UTC

[jira] Created: (PIVOT-573) Execute script expressions in WTKX component attributes

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


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.


[jira] Commented: (PIVOT-573) Execute script expressions in WTKX component attributes

Posted by "Greg Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIVOT-573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12889144#action_12889144 ] 

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

> Are you suggesting Pivot users stop using factory methods to conform to this limitation of BXML? 

No. I am saying that BXML doesn't cater to it.

Factory methods are static. BXML is a serialization format. Serialization deals with class instances. So static methods are not consistent with the purpose of BXML.


> 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.


[jira] Updated: (PIVOT-573) Execute script expressions in WTKX component attributes

Posted by "Michael Allman (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PIVOT-573?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Allman updated PIVOT-573:
---------------------------------

    Attachment: script_expressions_in_attributes.patch

Patch

> 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.


[jira] Commented: (PIVOT-573) Execute script expressions in WTKX component attributes

Posted by "Michael Allman (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIVOT-573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12889817#action_12889817 ] 

Michael Allman commented on PIVOT-573:
--------------------------------------

Hmmm... this is really about adding support for evaluating script expressions, not adding support for static factory methods.  The latter is just a tiny special case for this and was the motivation for the addition of this feature.

You might have an expression that manipulates a string, for example.  Or computes some arithmetic.

Anyway, I still don't see what the big deal is.  This adds a lot of power at a small price.  Ah well.

> 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.


[jira] Commented: (PIVOT-573) Execute script expressions in WTKX component attributes

Posted by "Greg Brown (JIRA)" <ji...@apache.org>.
    [ 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.


[jira] Commented: (PIVOT-573) Execute script expressions in WTKX component attributes

Posted by "Michael Allman (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIVOT-573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12888996#action_12888996 ] 

Michael Allman commented on PIVOT-573:
--------------------------------------

> The entire point of BXML is to instantiate and configure class instances.

And what I've proposed is a simple and, in my view, elegant solution to this shortcoming.  Factory methods have an established place in OO programming.  Are you suggesting Pivot users stop using factory methods to conform to this limitation of BXML?  Even if not, the fact that BXML does make it so much easier to not use a factory method at least puts pressure on the developer to use a named subclass where a factory method would be more appropriate.

On an aside, I think that the direction BXML is taking is putting the cart before the horse.  It's been moved out of the wtk source tree.  While this simplifies its mission, simple is not always easy.  (Have I said this before?)  For example...

>> 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.

Well, you can say that about a lot of things.  You don't need XML attributes in BXML and they complicate the syntax in the sense that you have to parse them differently than elements.  After all, you can set properties in WTKX using elements.  I'm assuming this holds in BXML.

You don't need BXML at all.  It just adds to the API.  You can just as well build a Pivot app with pure Java.

You don't need scripting support.

You don't need data binding.

You can do all of that with a smaller API.  What is "necessary"?  What does "necessary" mean to you?

So, yeah, there are other ways to do what I want without changing a thing.  But what I propose makes some things (like using factory methods) easier, more natural, and provides backwards compatibility.  I even think you could create a new prefix for these kinds of expressions, like # or whatever, but I think it would be better to expand the capability of $ to keep things simpler.  ;)

> 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.


[jira] Commented: (PIVOT-573) Execute script expressions in WTKX component attributes

Posted by "Greg Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIVOT-573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12889856#action_12889856 ] 

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

There are several reasons that I am not supportive of this suggestion:

1) The syntax used by BXML's '$' operator and the scripting language may not be compatible. For example, "$a.b.c" is currently resolved by JSON.get(). In script, "a.b.c" might not even be resolvable, or might resolve differently. This would be confusing to developers.

2) We'd need to include logic that detects a reference to a script function and invokes the scripting engine rather than the existing code path. This logic could be complicated - it's not valid to assume that all languages call functions using the same syntax. It would also introduce additional processing overhead when handling the '$' operator.

3) The definition of this expression is ambiguous:  ${a.b.c.foo()}. What exactly is being bound to?

The only way I could see adding support for this is via another operator (perhaps '#'), since that would facilitate efficient and non-ambiguous processing of the inline script. However, since there are several other ways to accomplish this using the existing syntax, I don't see a strong use case for adding this feature.


> 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.


[jira] Commented: (PIVOT-573) Execute script expressions in WTKX component attributes

Posted by "Michael Allman (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIVOT-573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12888539#action_12888539 ] 

Michael Allman commented on PIVOT-573:
--------------------------------------

First, the latter two alternatives require a ZipCodeValidator class, no?  I'm avoiding that intentionally, but generally speaking I don't think it's a fair assumption that the user is working with a named class.

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>

So I'm going to go with that as the best alternative.  My primary motivation in promoting this feature was succinctness.  I think it's undeniable that the proposed syntax is more succinct than the alternative—not just in terms of characters but in the sense that no intermediate variable need be defined.  I also think it's a valuable and natural feature in its own right.  Why should "$" expressions be limited to variable references when it's easy to support general expressions?  Also, this is a backwards compatible feature—no harm done there.  In fact, I don't see how this feature does any harm to the status quo.  The only thing I can think of is that this requires more CPU cycles, but first I'm not sure that's really significant given the usage of WTKX and second does that really outweigh the benefits of this feature?

If we keep the status quo, then all expressions used in an attribute have to be assigned to a variable first.  The only reason for that variable's existence is due to a limitation in the status quo.  I think this obfuscates the true intent of the user here—to assign the value of a property to the value of a script expression.

Finally, as regards the patch issue, I didn't mean to suggest this should go into 1.5.x.  That's just what I'm working from and I wanted to get the ball rolling on a discussion of this feature.  If you want to include it, I can work on a patch for trunk.

Hmmm... now I feel like I'm forgetting something else I wanted to say but it's not coming to me.  Oh well.  Maybe in a future comment.

> 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.


[jira] Resolved: (PIVOT-573) Execute script expressions in WTKX component attributes

Posted by "Greg Brown (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PIVOT-573?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Greg Brown resolved PIVOT-573.
------------------------------

    Resolution: Won't Fix

You can achieve the same thing without modifying the serializer by defining a script block:

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

<TextInput validator="$validator"/>

Alternatively, you can do this:

<TextInput>
    <validator>
        <allman:ZipCodeValidator/>
    </validator>
</TextInput>

Or this:

<wtkx:define>
    <allman:ZipCodeValidator wtkx:id="validator"/>
</wtkx:define>

<TextInput validator="$validator">

Note that future patches submitted against the 1.5 branch will probably not be applied (unless they are critical bug fixes). Development is currently focused on the 2.0 branch.


> 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.