You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Tuyen Truong <tu...@gmail.com> on 2006/01/20 07:29:51 UTC

Suggestion for improving For and If components

Hi guys,

Congrats to the team on releasing version 4.0. I have been using it for a
couple of months now and find it to be a vast improvement from version 3.

I'm writing to suggest an improvement to the For and If components.
Currently, you have to explicitly bind the element parameter to both the If
and For component for the element tag to be rendered. I have frequently had
errors because I forget to bind the parameter (i.e the element doesn't get
rendered so the class attribute doesn't get applied correctly to the
enclosed text). I'd like to see the two components modified so that the
template tag gets used if the element has informal parameters or if the
element tag is not "span". This would make the two components less prone to
errors and save on a little typing.

The change would require the following addition to the ForBean and IfBean
class:

    public abstract String getElementParameter();
    public abstract void setElementParameter(String elementParameter);

    public abstract String getTemplateTag();
    public abstract void setTemplateTag(String templateTag);

    public String getElement() {
        if (getElementParameter() != null)
            return getElementParameter();
        return !"span".equals(getTemplateTag()) ||
getHasInformalParameters() ? getTemplateTag() : null;
    }

    private boolean getHasInformalParameters() {
        if (getBindings() == null)
            return false;

        for (Object o : getBindings().entrySet()) {
            Map.Entry entry = (Map.Entry) o;
            String name = (String) entry.getKey();

            if (getSpecification().getParameter(name) != null)
                continue;
            return true;
        }
        return false;
    }

The component specification would have to change as follows:

    <parameter name="element" property="elementParameter">
        <description>
            If provided, the component wraps its content with the requested
element.
            Informal parameters become attributes of that element.
        </description>
    </parameter>

    <parameter name="templateTag">
        <description>
            The tag used to add this component in a template.
        </description>
    </parameter>


What do you think?

Thanks,

Tuyen