public static final ILinkRenderer RENDERER = new FormLinkRenderer();
public void renderLink(IMarkupWriter writer, IRequestCycle cycle,
ILinkComponent linkComponent)
{
IMarkupWriter wrappedWriter = null;
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);
String formName = cycle.getUniqueId("LinkForm");
boolean hasBody = getHasBody();
boolean disabled = linkComponent.isDisabled();
if (!disabled && !cycle.isRewinding())
{
ILink l = linkComponent.getLink(cycle);
String anchor = linkComponent.getAnchor();
Body body = (Body) TapestryUtils.getPageRenderSupport(cycle, linkComponent);
String function = generateFormFunction(formName, l, anchor);
body.addBodyScript(linkComponent, function);
if (hasBody)
writer.begin(getElement());
else writer.beginEmpty(getElement());
writer.attribute(getUrlAttribute(), "javascript: document."
+ formName + ".submit();");
beforeBodyRender(writer, cycle, linkComponent);
// Allow the wrapped components a chance to render.
// Along the way, they may interact with this component
// and cause the name variable to get set.
wrappedWriter = writer.getNestedWriter();
}
else wrappedWriter = writer;
if (hasBody) linkComponent.renderBody(wrappedWriter, cycle);
if (!disabled && !cycle.isRewinding())
{
afterBodyRender(writer, cycle, linkComponent);
linkComponent.renderAdditionalAttributes(writer, cycle);
if (hasBody)
{
wrappedWriter.close();
// Close the <element> tag
writer.end();
}