You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Peter Ledbrook <p....@cacoethes.co.uk> on 2003/06/22 10:30:20 UTC
Buttons with Action/DirectLink behaviour
Hi,
Is it possible to embed an HTML form button into a Tapestry page that
has the same behaviour as an ActionLink or a DirectLink? On one
particular page I have a list of users, and each item has a "More info"
link implemented as an ActionLink. The list is generated using a
@Foreach component. Ideally, I would like to use a button for the "More
info" link rather than a hyperlink. If it's not possible, it's hardly a
big problem, though.
Many thanks,
Peter
Re: Buttons with Action/DirectLink behaviour
Posted by Peter Ledbrook <p....@cacoethes.co.uk>.
Thanks for the reply.
1) Does a normal form submit work in the same way as an ActionLink? I
have the following in my html template:
<tr jwcid="@Foreach" source="ognl:allStaff" value="ognl:staffMember"
element="tr">
<td class="summaryItem">
<p class="small">
<span jwcid="@Insert" value="ognl:staffMember.name" />
</p>
</td>
<td class="summaryItem">
<p class="small" align="center">
<span jwcid="@Insert" value="ognl:staffMember.shortName" />
</p>
</td>
<td class="summaryItem">
<p class="small">
<span jwcid="@ActionLink"
listener="ognl:listeners.showStaffMember">More >></span>
</p>
</td>
</tr>
If I use a normal form submit, the 'staffMember' property always
contains the last item of the list, irrespective of which button/link I
click on. Or am I missing something?
2) Probably the best way of doing it.
Cheers,
Peter
Bryan Lewis wrote:
>(1) One way is the ImageSubmit component:
>
>html:
> <form jwcid="@Form">
> <input jwcid="anImageButton" alt="Powered by Tapestry"/>
> </form>
>
>page:
> <component id="anImageButton" type="ImageSubmit">
> <binding name="listener" expression="listeners.someMethod"/>
> <binding name="image" expression="assets.tapestrygif"/>
> </component>
> <context-asset name="tapestrygif" path="images/Tapestry.gif"/>
>
>The Component Reference has a different ImageSubmit example.
>
>(2) Another way is an ActionLink with an image:
>
>html:
> <a jwcid="@ActionLink" listener="ognl:listeners.someMethod">
> <img src='images/Tapestry.gif' alt='Powered by Tapestry'>
> </a>
>
>This works even when not embedded in a form.
>
>Occasionally I've needed an image button that _looked_ like a standard
>submit button but without a form submission. I used a link with an _image_
>of a submit button.
>
>
>
Re: Buttons with Action/DirectLink behaviour
Posted by Bryan Lewis <br...@maine.rr.com>.
(1) One way is the ImageSubmit component:
html:
<form jwcid="@Form">
<input jwcid="anImageButton" alt="Powered by Tapestry"/>
</form>
page:
<component id="anImageButton" type="ImageSubmit">
<binding name="listener" expression="listeners.someMethod"/>
<binding name="image" expression="assets.tapestrygif"/>
</component>
<context-asset name="tapestrygif" path="images/Tapestry.gif"/>
The Component Reference has a different ImageSubmit example.
(2) Another way is an ActionLink with an image:
html:
<a jwcid="@ActionLink" listener="ognl:listeners.someMethod">
<img src='images/Tapestry.gif' alt='Powered by Tapestry'>
</a>
This works even when not embedded in a form.
Occasionally I've needed an image button that _looked_ like a standard
submit button but without a form submission. I used a link with an _image_
of a submit button.
----- Original Message -----
From: "Peter Ledbrook" <p....@cacoethes.co.uk>
To: <ta...@jakarta.apache.org>
Sent: Sunday, June 22, 2003 4:30 AM
Subject: Buttons with Action/DirectLink behaviour
> Hi,
>
> Is it possible to embed an HTML form button into a Tapestry page that
> has the same behaviour as an ActionLink or a DirectLink? On one
> particular page I have a list of users, and each item has a "More info"
> link implemented as an ActionLink. The list is generated using a
> @Foreach component. Ideally, I would like to use a button for the "More
> info" link rather than a hyperlink. If it's not possible, it's hardly a
> big problem, though.
>
> Many thanks,
>
> Peter
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
Re: Buttons with Action/DirectLink behaviour
Posted by Denis Ponomarev <oz...@romsat.ua>.
PL> Is it possible to embed an HTML form button into a Tapestry page that
PL> has the same behaviour as an ActionLink or a DirectLink? On one
PL> particular page I have a list of users, and each item has a "More info"
PL> link implemented as an ActionLink. The list is generated using a
PL> @Foreach component. Ideally, I would like to use a button for the "More
PL> info" link rather than a hyperlink. If it's not possible, it's hardly a
PL> big problem, though.
Since 3.0 I am using custom ILinkRenderer for this purposes:
public class ButtonLinkRenderer extends DefaultLinkRenderer {
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);
cycle.setAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME, linkComponent);
writer.begin("button");
writer.attribute(getUrlAttribute(),
constructURL(linkComponent.getLink(cycle),
linkComponent.getAnchor(),
cycle));
writer.attribute("onclick", "window.location.href = this.href");
if (linkComponent.isDisabled()) {
writer.attribute("disabled", 1);
}
IMarkupWriter wrappedWriter = writer.getNestedWriter();
linkComponent.renderBody(wrappedWriter, cycle);
linkComponent.renderAdditionalAttributes(writer, cycle);
wrappedWriter.close();
writer.end();
cycle.removeAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME);
}
}
Then you can use it in spec-file:
<bean name="buttonRenderer" class="com.corp.my.ButtonLinkRenderer"/>
<component id="infoButton" type="DirectLink">
<binding name="listener" expression="listeners.info"/>
<binding name="renderer" expression="beans.buttonRenderer"/>
</component>