开发者

how execute a ajax after some js function in jsf2.0

i often use but i have this problem. if there is a whose action is delete some entity ,but i want notif开发者_如何学JAVAy user who click this commandLink a javascript function confirm(str); if the confirm() answer is false, it doesnot trigger a ajax function. So i begin to use jsf.ajax.request function;my code like this .

<h:commandLink  value="ajax"  onclick="return ask(this,event,null,'page');" actionListener="#{test.ajax}"/>
<h:inputText value="#{test.page}" id="page"/>

this is my javascript code

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;
}

,but it can execute it successfully,but i found it not a ajax.other value for backing bean is updated too! if sb can tell me ! Be grateful!


You don't need to take over <f:ajax>'s job. Just return in the 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"/>

And use action instead of actionListener. You can return null or void there.


I have solved my problem. It was because I did not understand jsf.ajax.request well. If I want the actionListener to invoke in the backing, I also take the actionListener whose owner--dom object is to be executed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜