tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Howard Lewis Ship" <hls...@gmail.com>
Subject [T5] If component / else
Date Sat, 13 Jan 2007 01:10:37 GMT
A new concept in Tapestry:  parameters in the templates for a content
range.  Example:

<t:comp type='If" test="loggedIn">
  Welcome to the show, ${userName}!
  <t:parameter name="else">
    Click <a t:type="ActionLink" t:id="login">here</a> to log in.
  </t:parameter>
</t:comp>

The <parameter> element binds the "else" parameter of the If
component, passing it a Block instance.

Here's the revised If component:

package org.apache.tapestry.corelib.components;

import org.apache.tapestry.Block;
import org.apache.tapestry.annotations.ComponentClass;
import org.apache.tapestry.annotations.Parameter;

/**
 * Conditionally renders its body.
 */
@ComponentClass
public class If
{
    @Parameter(required = true)
    private boolean _test;

    @Parameter
    private Block _else;

    /**
     * Returns null if the test parameter is true, which allows normal
rendering (of the body). If
     * the test parameter is false, returns the else parameter (this
may also be null).
     *
     */
    Object beginRender()
    {
        return _test ? null : _else;
    }

    /**
     * If the test parameter is true, then the body is rendered,
otherwise not. The component does
     * not have a template or do any other rendering besides its body.
     */
    boolean beforeRenderBody()
    {
        return _test;
    }
}


Anyway, this replaced a lot of stuff from Tapestry 4:  The Block and
RenderBlock components. It's easier and more typesafe.  There's also a
<t:block> element and the @Inject annotation can inject a Block.   We
could have gotten by with just <block> and maybe  a block: binding
prefix, but this reflects how the block is used, not what it does.

These are all the key things necessary for more complex components
such as T4's Table, Palette and BeanForm.  All of these should make
new appearences in T5 in the coming weeks or months.


-- 
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Mime
View raw message