简体   繁体   English

JSF标记上的onclick事件

[英]onclick event on JSF tag

How to bind JavaScript onclick event to JSF-tag? 如何将JavaScript onclick事件绑定到JSF标签? Here's my JSF tag: 这是我的JSF标签:

<h:commandLink value="Edit" action="#{adminBean.edit}">
<f:param value="#{user.login}" name="login"/>
</h:commandLink>

I've managed to bind click-event on a JSP-tag JavaScript function: 我设法将点击事件绑定到JSP标签JavaScript函数上:

<script type="text/javascript">
function deleteUser(link)
{
    if (confirm("Are you sure?")) {
        window.location = link;
    }

    else {

    }

}
</script>

Here's my link example in JSP-tag. 这是我在JSP-tag中的链接示例。

out.println("<a href=\"#\" onclick=\"deleteUser('deleteUser.htm?userLogin="+user.getLogin()+"');\">Delete</a>");

How can I bind the same on-click function to given above JSF-tag ? 如何将相同的单击功能绑定到上面的JSF-tag中?

Use the onclick attribute in the <h:commandLink> tag component: 使用<h:commandLink>标记组件中的onclick属性:

JSF code JSF代码

<h:commandLink value="Edit" action="#{adminBean.edit}"
    onclick="if (!deleteUser()) return false;">
    <f:param value="#{user.login}" name="login"/>
</h:commandLink>

And change your script to 并将您的脚本更改为

<script type="text/javascript">
    function deleteUser(link) {
        return confirm("Are you sure?");
    }
</script>

By the way, I think you have confused the terms edit and delete , but that's outside the question scope. 顺便说一句,我认为您已经混淆了术语“ 编辑”和“ 删除” ,但这不在问题范围之内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM