Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for 
change notification.

The following page has been changed by DavorHrg:
http://wiki.apache.org/tapestry/Tapestry5HowToAddBindingPrefix

------------------------------------------------------------------------------
      {
          List<Binding> delegates = new ArrayList<Binding>();
          String[] bindingNames = expression.split(",");
+         boolean isInvariant=true;
          
          for (String bindingName : bindingNames){
              String defaultBinding = TapestryConstants.LITERAL_BINDING_PREFIX;
@@ -76, +77 @@

                  }
              }
  
-             delegates.add(_bindingSource.newBinding(description, container, 
component, defaultBinding, bindingName, location));
+             Binding binding = _bindingSource.newBinding(description, 
container, component, defaultBinding, bindingName, location);
+             isInvariant = isInvariant && binding.isInvariant();
+             delegates.add(binding);
          }
-         
+ 
-         return new ListBinding(delegates);
+         return new ListBinding(delegates, isInvariant);
      }
  }
  }}}
@@ -88, +91 @@

  {{{
  public class ListBinding extends AbstractBinding{
      private final List<Binding> delegates;
+     private final boolean _invariant;
  
-     public ListBinding(List<Binding> delegates) {
+     public ListBinding(List<Binding> delegates, boolean invariant) {
          this.delegates = delegates;
+         _invariant = invariant;
      }
  
      public Object get() {
@@ -105, +110 @@

      
      @Override
      public boolean isInvariant() {
-         return false;
+         return _invariant;
      }
      
      @Override
@@ -115, +120 @@

  }
  }}}
  !Notice: although we named this binding "list" the value returned is an 
Object array, but tapestry will easily convert between the two. If you like, 
you can easily change this to return "List"[[BR]]
- !Notice#2: you must override isInvariant and "return false" to avoid value 
being cached 
+ !Notice#2: you must override isInvariant and "return false" to avoid value 
being cached (in this example we return true if all sub expressions are 
invariant)
  
  And that's it, you now have your own binding prefix. It splits the expression 
on "," and each subexpression will be evaluated as it was single binding 
expression (with exception for numeric values and values surrounded with ' ', 
which are prefixed literal).
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to