4

We are migrating from JSF 1.2 to JSF 2.2.6 along with RichFaces 4.5.2. Facing issues with the oncomplete not getting called. The JS function during onclick gets called, but JS in oncomplete does not get called. How is this caused and how can I solve it?

<h:commandLink ... onclick="ed();" oncomplete="cEd(#{rowIndex});">
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
jsflearner
  • 53
  • 1
  • 1
  • 6

1 Answers1

7

There is indeed no such attribute in <h:commandLink>. You're most likely confusing with <a4j:commandLink> which does have that attribute.

You've basically 2 options:

  1. Just replace <h:commandLink> by <a4j:commandLink>.

    <a4j:commandLink ... oncomplete="oncompleteFunction()" />
    
  2. Nest a <f:ajax> with an event handler inside <h:commandLink>.

    <h:commandLink ...>
        <f:ajax onevent="oneventFunction" /><!-- No parenthesis! -->
    </h:commandLink>
    
    function oneventFunction(data) {
        if (data.status === "success") {
            oncompleteFunction();
        }
    }
    

Hint for the future: just read the tag documentation. Links are in 1st paragraph.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • we actually tried using f:ajax and a4j:commandlink as well.It works fine for the first time. We faced a unique issue of the link itself not working the second time when we do this. actionlistener only doesn't get called the secondtime when we use a4j:commandlink or f:ajax – jsflearner Jul 07 '15 at 11:36
  • That's a different problem which is unrelated to the current question. That problem has already been asked and answered long before. – BalusC Jul 07 '15 at 11:38
  • 1
    ok..Agreed. can you share your inputs here or should I post as a new question pls? We did try searching and could find posts where issue of first click not working is only discussed. – jsflearner Jul 07 '15 at 11:41
  • my situation is inverse to above one. First click only works fine. not the second and further.hope my query is right. – jsflearner Jul 07 '15 at 11:43
  • That will happen if the first click did not update the form afterwards. – BalusC Jul 07 '15 at 11:46
  • Tried to update the form using render="@form" and also render="actualformname" in a4j:commandlink. Doesn't work..suspected this could be an issue of conditionally rendering the form and removed the "rendered" attribute of the form. still, no results :( – jsflearner Jul 07 '15 at 13:20
  • Sounds like candidate for a new question ([make sure you prepare a good MCVE](http://stackoverflow.com/tags/jsf/info)). – BalusC Jul 07 '15 at 13:25