admin管理员组

文章数量:1279175

How to bind JavaScript onclick event to JSF-tag? Here's my JSF tag:

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

I've managed to bind click-event on a JSP-tag JavaScript function:

<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.

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 ?

How to bind JavaScript onclick event to JSF-tag? Here's my JSF tag:

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

I've managed to bind click-event on a JSP-tag JavaScript function:

<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.

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 ?

Share Improve this question edited Nov 11, 2015 at 16:27 BuZZ-dEE 6,94916 gold badges73 silver badges105 bronze badges asked Feb 26, 2013 at 16:29 gabriel angelosgabriel angelos 3591 gold badge9 silver badges23 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Use the onclick attribute in the <h:mandLink> tag ponent:

JSF code

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

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.

本文标签: javascriptonclick event on JSF tagStack Overflow