You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by "Paul Stanton (JIRA)" <de...@tapestry.apache.org> on 2008/10/15 06:58:46 UTC

[jira] Commented: (TAPESTRY-2251) ButtonLinkRenderer overwrites onclick event handler

    [ https://issues.apache.org/jira/browse/TAPESTRY-2251?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12639723#action_12639723 ] 

Paul Stanton commented on TAPESTRY-2251:
----------------------------------------

Well, i finally got around to making a patched version.

It's pretty simple, just replace the code between lines 60-66 in ButtonLinkRenderer:

if (!cycle.isRewinding()) {
    String url = link.getURL(component.getAnchor(), true);
    String target = component.getTarget();
    String onclick = (target == null) ? getScript(url) : getScript(url, target);

    writer.attribute("onclick", onclick);
}

with:

if (!cycle.isRewinding()) {
    String url = link.getURL(component.getAnchor(), true);
    String target = component.getTarget();
    String onclick = (target == null) ? getScript(url) : getScript(url, target);

    IBinding onclickBinding = component.getBinding("onclick");
    if (onclickBinding != null) {
	component.getBindings().remove("onclick");
	String onclickBindingValue = onclickBinding.getDescription();
	if (!onclickBindingValue.endsWith(";"))
	    onclickBindingValue += ";";
	onclick = onclickBindingValue + onclick;
    }
    writer.attribute("onclick", onclick);
}

the result is that any script in the informal onclick parameter will precurse the navigation script added by the component eg:

<button jwcid="@PageLink" page="MyPage" renderer="bean:buttonLinkRenderer" onclick="if (!confirm('do you want to?')) return false;">Go To My Page</button>
<button type="button" onclick="if (!confirm('do you want to?')) return false;window.location='/app/MyPage.html'" id="PageLink_0">Go To My Page</button>

> ButtonLinkRenderer overwrites onclick event handler
> ---------------------------------------------------
>
>                 Key: TAPESTRY-2251
>                 URL: https://issues.apache.org/jira/browse/TAPESTRY-2251
>             Project: Tapestry
>          Issue Type: Improvement
>          Components: Contrib
>    Affects Versions: 4.1.5
>            Reporter: Paul Stanton
>            Priority: Minor
>
> i've started using the buttonlinkrenderer and have noticed that a neat trick i use with direct link does not work with buttonlinkrenderer.
> to have the user confirm their action before submitting a request, i add an onclick event hander ie: onclick="return confirm('sure?');" this would be called before the actual direct link href was called, and returning false would cancel the request altogether.
> as buttonlinkrenderer utilises the onclick attribute of the button, this trick is not available with a buttonlinkrenderer.
> is it possible to have buttonlinkrenderer append to any existing onclick handler? so instead of:
> onclick="window.location='/.....'"
> can it render:
> onclick="myscript;window.location='/.....'" where myscript is my onclick hander.
> thx. paul.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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