how to conform deleting in jsf
I am pretty new to jsf.
I am using commandLink and doing deleting from database.But before deleting I want to let user conform his/her behaviour. I don't want to create another form and bean for this. So I use java scirpt here.
I post relevant code:
<SCRIPT LANGUAGE=JAVASCRIPT>
function verify(){
msg = "Are you absolutely sure that you want to submit this form?";
//all we have to do is return the return value of the confirm() method
return confirm(msg);
}
</SCRIPT>
......
<h:commandLink actionListener="{ViewUicLookupBean.uicLookupDeleted}" immediate="false" value="Delete" onmouseup=verify() >
<f:param name="uicLookupId" value="#{currentRow.uic}"/>
</h:commandLink>
.....
I test my program. When I don't add "onmouseup=verify()" in commandLink it works fine. But after adding it displays the conform dialog firstly and in this dialog if you select "OK" it don't delete record.
Anyone know sth about it?
[1048 byte] By [
xlia] at [2007-10-2 3:25:40]

You can try use the example to add confirm prompt to wrap around the original onclick functon.
<html>
<head>
<script>
function addConfirmPrompt(c,msg){
var tempFunc = c.onclick;
var newFunc = function(){ if(confirm(msg)) return tempFunc(); }
c.onclick = newFunc;
}
function init(){
addConfirmPrompt(document.getElementById('c'),'Are you sure you want to delete this item?');
}
</script>
<head>
<body onload="init();">
<a id="c" href="#" onclick="alert('ok1'); alert('ok2');">click here</a>
</body>
</html>
normally, when you use javascript to validate a click, you'd have script that looks something like:
<a href="#" onclick="return confirm('are you sure?');">delete</a>
But, since that will stop the execution of any javascript that occurs after the ; and the JSF commandLink button adds the javascript necessary for submission after, you need to only return if the outcome is false. What I've gotten to work is this:
onclick="if(!confirm('are you sure?')){ return; }"
It's a little ugly, and a little verbose. But it shoud work.
jcerna at 2007-7-15 22:35:05 >
