How to bind JavaScript onclick
event to JSF-tag? Here's my JSF tag:
<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:
<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 ?
Use the onclick
attribute in the <h:commandLink>
tag component:
JSF code
<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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.