[英]how execute a ajax after some js function in jsf2.0
我经常使用,但是我有这个问题。 如果有一个动作是删除某些实体,但我想通知用户单击此命令,则链接一个javascript函数Confirm(str); 如果confirm()答案为假,则不会触发ajax函数。 所以我开始使用jsf.ajax.request函数;我的代码是这样的。
<h:commandLink value="ajax" onclick="return ask(this,event,null,'page');" actionListener="#{test.ajax}"/>
<h:inputText value="#{test.page}" id="page"/>
这是我的JavaScript代码
function ask(element,event,exec,target){
if(confirm("are you ready to delete it"))
{
try{
jsf.ajax.request(element,event,{execute:exec,render:target});
}catch(ex){
alert(ex);
return false;
}
}else
return false;
}
,但是它可以成功执行,但是我发现它不是ajax。backingbean的其他值也被更新了! 如果某人能告诉我! 非常感激!
您无需接管<f:ajax>
的工作。 只需返回onclick。
<h:commandLink value="ajax" action="#{test.ajax}" onclick="return confirm('Are you sure?')">
<f:ajax execute="@this" render="page" />
</h:commandLink>
<h:inputText value="#{test.page}" id="page"/>
并使用action
代替actionListener
。 您可以在那里返回null
或void
。
我已经解决了我的问题。 这是因为我不太了解jsf.ajax.request
。 如果我想在actionListener
调用actionListener
,我还要获取要执行其所有者actionListener
对象的actionListener
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.