tapestry-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Ferraro <p...@columbia.edu>
Subject Re: PageLink with button
Date Thu, 01 Sep 2005 17:49:23 GMT
The ButtonLinkRenderer is new to Tapestry 4.0.  Also, as of beta-5, it 
has been refactored to org.apache.tapestry.contrib.link along with the 
other link renderers.
Here is the ButtonLinkRenderer class retrofitted for Tapestry 3.0.  Note 
that since ILinkComponent.getTarget() was not added until 4.0, the 
target property will not render correctly.

public class ButtonLinkRenderer extends DefaultLinkRenderer
{
    public static final ILinkRenderer SHARED_INSTANCE = new 
ButtonLinkRenderer();
   
    /**
     * @see 
org.apache.tapestry.link.ILinkRenderer#renderLink(org.apache.tapestry.IMarkupWriter, 
org.apache.tapestry.IRequestCycle, 
org.apache.tapestry.components.ILinkComponent)
     */
    public void renderLink(IMarkupWriter writer, IRequestCycle cycle, 
ILinkComponent linkComponent)
    {
        if (cycle.getAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME) 
!= null)
        {
            throw new 
ApplicationRuntimeException(Tapestry.getMessage("AbstractLinkComponent.no-nesting"), 
linkComponent, null, null);
        }
       
        cycle.setAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME, 
linkComponent);
       
        ILink link = linkComponent.getLink(cycle);
       
        writer.begin("button");
        writer.attribute("type", "button");
       
        if (linkComponent.isDisabled())
        {
            writer.attribute("disabled", "disabled");
        }
       
        // String target = linkComponent.getTarget();
        String target = null;
        String url = constructURL(link, linkComponent.getAnchor(), cycle);
        String pattern = (target == null) ? "window.location=''{0}''" : 
"window.open(''{0}'', ''{1}'')";
        String onclick = MessageFormat.format(pattern, new Object[] { 
url , target });
       
        writer.attribute("onclick", onclick);
       
        linkComponent.renderAdditionalAttributes(writer, cycle);
       
        beforeBodyRender(writer, cycle, linkComponent);
       
        IMarkupWriter wrappedWriter = writer.getNestedWriter();
       
        linkComponent.renderBody(wrappedWriter, cycle);
       
        wrappedWriter.close();
       
        afterBodyRender(writer, cycle, linkComponent);
       
        writer.end();
       
        cycle.removeAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME);
    }
}

Paul

Alexandr Kundirenko wrote:

>Yes, it is for 4.0 version.
>Not sure that it works for 3.0.3, try with 3x syntax
>Use  replace "value" attribute "expression", don't use binding
>prefixes "literal" and "bean", etc
>
>WY> I get the following exception:
>WY> Attribute "value" must be declared for element type "binding"
>
>WY> Is the following implementation for Tapestry 4? I am using 3.03. And
>WY> also, I think it should be beans.buttonRenderer.
>
>
>
>WY> On 9/1/05, Alexandr Kundirenko <akundirenko@gmail.com> wrote:
> >> There is simpler way:
> >>
> >> <bean name="buttonRenderer" 
>WY> class="org.apache.tapestry.link.ButtonLinkRenderer"/>
> >>
> >> <component id="cancel" type="PageLink">
> >>     <binding name="page" value="literal:TargetPage"/>
> >>     <binding name="renderer" value="bean:buttonRenderer"/>
> >> </component>
> >>
> >> --
> >> aku
> >>
> >> wctc> With CSS,
> >> wctc> you can make a <a> look like a button ...
> >>
> >> wctc> -----Original Message-----
> >> wctc> From: Waimun Yeow [mailto:waimun@dev.java.net]
> >> wctc> Sent: donderdag 1 september 2005 12:27
> >> wctc> To: tapestry-user@jakarta.apache.org
> >> wctc> Subject: PageLink with button
> >>
> >> wctc> Hi,
> >>
> >> wctc> How do I create a PageLink with a button instead of the regular
>WY> <a>
> >> wctc> href?
> >>
> >> wctc> If there's anyone who have done it, please advise....
> >>
> >>
> >> wctc> Tks,
> >>
> >>
> >> wctc> waimun
> >>
> >>
> >> wctc> 
>WY> ---------------------------------------------------------------------
> >> wctc> To unsubscribe, e-mail:
> >> wctc> tapestry-user-unsubscribe@jakarta.apache.org
> >> wctc> For additional commands, e-mail:
> >> wctc> tapestry-user-help@jakarta.apache.org
> >>
> >>
> >> wctc> 
>WY> ---------------------------------------------------------------------
> >> wctc> To unsubscribe, e-mail:
> >> wctc> tapestry-user-unsubscribe@jakarta.apache.org
> >> wctc> For additional commands, e-mail:
> >> wctc> tapestry-user-help@jakarta.apache.org
> >>
> >>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> >> tapestry-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail:
> >> tapestry-user-help@jakarta.apache.org
> >>
> >>
>
>
>WY> ---------------------------------------------------------------------
>WY> To unsubscribe, e-mail:
>WY> tapestry-user-unsubscribe@jakarta.apache.org
>WY> For additional commands, e-mail:
>WY> tapestry-user-help@jakarta.apache.org
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>  
>


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


Mime
View raw message