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 NickWestgate:
http://wiki.apache.org/tapestry/Tapestry5AnyComponent

The comment on the change is:
Enhanced to replace element body via supplied attribute.

------------------------------------------------------------------------------
- "Any" does nothing (by default) but still evaluates attributes using binding 
prefixes (default is literal) and can use mixins etc. The results can almost 
always be duplicated by expansions, but Any is sometimes the only solution or 
simply less intrusive - see the examples.[[BR]]
+ Note: This has now been enhanced to allow replacement of an element's body. 
Please see the examples.
+ 
+ "Any" does nothing (by default) but still evaluates attributes using binding 
prefixes (default is literal) and can use mixins etc. The results can often be 
duplicated by expansions, but Any is sometimes the only solution for 
browser-previewable/editable HTML, or simply less intrusive - see the 
examples.[[BR]]
  
  Example use: (Please add more examples if you use Any)
  {{{
  <!-- a static class for preview; a dynamic class at runtime -->
  <span t:type="Any" t:class="prop:someMethodToGetTheClass" 
class="previewDisplayClass">${message:someText}</span>
+ 
+ <!-- *NEW* demo body for preview; dynamic body at runtime -->
+ <h3 t:type="Any" t:body="${item.itemName}" class="itemClass">Example Item</h3>
  
  <!-- using a mixin -->
  <div t:type="Any" t:mixins="myLayout">My layout</div>
@@ -21, +26 @@

  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
- //     http://www.apache.org/licenses/LICENSE-2.0
+ // http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
@@ -41, +46 @@

  import org.apache.tapestry.annotations.SupportsInformalParameters;
  
  /**
-  * The Any component is a swiss-army knife that emulates any arbitary 
element. Renders an element
+  * The Any component is a swiss-army knife that emulates any arbitrary 
element. Renders an
-  * tag including an id attribute and any informal parameters. The id is 
provided by
+  * element tag including an id attribute and any informal parameters. The id 
is provided by
-  * [EMAIL PROTECTED] PageRenderSupport#allocateClientId(String)} (so it will 
be unique on the client side) and
+  * [EMAIL PROTECTED] PageRenderSupport#allocateClientId(String)} (so it will 
be unique on the client side)
-  * is available after the component renders as [EMAIL PROTECTED] 
#getClientId()}. The Any component has no
+  * and is available after the component renders as [EMAIL PROTECTED] 
#getClientId()}. The Any component
-  * template but does render its body.
+  * has no template but does render its body (unless the body attribute is 
supplied).
   */
  @SupportsInformalParameters
  public class Any implements ClientElement
@@ -58, +63 @@

      private String _element;
  
      /**
-      * The base value for the id attribute. If non-null, then a 
<em>unique</em> value is obtained,
+      * The base value for the id attribute. If non-null, then a 
<em>unique</em> value is
-      * and the <code>id</code> attribute is added to the element. The actual 
unique id is
+      * obtained, and the <code>id</code> attribute is added to the element. 
The actual unique
-      * available via the [EMAIL PROTECTED] #getClientId() clientId property}.
+      * id is available via the [EMAIL PROTECTED] #getClientId() clientId 
property}.
       */
      @Parameter(defaultPrefix = "literal")
      private String _id;
+ 
+     /**
+      * Optional body attribute which will replace the element body from the 
template.
+      */
+     @Parameter
+     private String _body;
  
      @Inject
      private ComponentResources _resources;
@@ -89, +100 @@

          _resources.renderInformalParameters(writer);
      }
  
+     boolean beforeRenderBody()
+     {
+         return (_body == null);
+     }
+ 
      /** Ends the element. */
      void afterRender(MarkupWriter writer)
      {
+         if (_body != null)
+         {
+             /** Replace the body. */
+             writer.write(_body);
+         }
+ 
          writer.end();
      }
  
      /**
-      * The page-unique id, rendered out as the <code>id</code> attribute of 
the tag. This will be
+      * The page-unique id, rendered out as the <code>id</code> attribute of 
the tag. This will
-      * null if the component's id parameter is unbound or otherwise null.
+      * be null if the component's id parameter is unbound or otherwise null.
       */
      public String getClientId()
      {

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

Reply via email to