1

i often use but i have this problem. if there is a whose action is delete some entity ,but i want notify 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!

1
  • Please show your markup and code as it is sent to the browser (use ‘View Source’), so we don't have to figure out what the resulting HTML will look like. After all, this is what JavaScript will see. Commented May 21, 2011 at 14:55

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you! you are right,but it seems that not is "@page" but is "page" in the render .And execute you should also add 'page' dom object,or you can only execute ajax once.
Yes, sorry, I meant to type page instead of @page.
can i ask you a question about JSF composite component.i write a composite component which include a <f:ajax/> and it has a render value from i gave it a composite:attribute args .but when i use this component.the console gave me a result that javax.faces.FacesException: <f:ajax> contains an unknown id 'tableview'.i am sure that i have a id which call tableview in the outside page.coutd you tell me solution?thank you!
0

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.

1 Comment

i also want to konw in this situation;can we user <f:ajax/> to solve this problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.