0

In my JSF 1.2 application, I'm using trinidad extended service addscript functionality to invoke a javascript function.

I can see from the following javascript console logs that js method is being called. But POST request is not being generated. There're many other(normal)buttons in the page which are working without any issues. There are no JS errors in my console. I've ensured that all my included pages don't have any forms and this is the only form.

And my biggest headache is, it is working fine in my local workspace and I've problems only while hitting my application URL directly. This is happening across all IE versions.

Can someone suggest what could be the issue?

In Bean:

FacesContext facesContext = FacesContext.getCurrentInstance();
                      ExtendedRenderKitService service = Service.getRenderKitService(
                                  facesContext, ExtendedRenderKitService.class);
                      service.addScript(facesContext, “clickHiddenButton();”);

Javascript:

function clickHiddenButton () {
      if(null != console)
            console.log('before calling hidden button for close');
      document.getElementById('hiddenButton').click();
      if(null != console)
            console.log('after calling hidden button for close'); 
}

My Page Hidden Button Component:

<tr:commandButton id="hiddenButton" action="#{bean.actionHidden}" immediate="true"></tr:commandButton>                                                                                                                                                                  
prakashb
  • 160
  • 1
  • 8
  • Have you excluded all of http://stackoverflow.com/questions/2118656/commandlink-commandbutton-ajax-backing-bean-action-listener-method-not-invoked/? – BalusC Jun 19 '15 at 11:08
  • Yes the first thing I did!! – prakashb Jun 19 '15 at 11:08
  • You seem to be implying that it happens in IE only and not in other browsers (Chrome, Firefox, etc). Is this true? – BalusC Jun 19 '15 at 11:09
  • No actually our application doesn't support any other browsers , so I have the possibility to check only in all IE versions. – prakashb Jun 19 '15 at 11:10
  • Your JavaScript implies that you're using `prependId="false"` on the form. Is this true? – BalusC Jun 19 '15 at 11:11
  • My JS file is stand alone, I tried using trh:script and kept my code in standalone file as well - both are not working. I'm not using prependId, please correct me if I'm not understanding your question correctly. – prakashb Jun 19 '15 at 11:14
  • And an FYI, like If I keep alert or breakpoint in IE developer tools, it is working. – prakashb Jun 19 '15 at 11:15
  • Oh? So `document.getElementById('hiddenButton')` actually didn't return anything? Tell the generated HTML output of that ``. – BalusC Jun 19 '15 at 11:30
  • That will return the hiddenbutton, for the rest of my buttons I'm just giving the absolute id's only. – prakashb Jun 19 '15 at 11:34
  • The ID still suggests it actually isn't inside a form, or that you're using `prependId="false"` on the form, but alas, I don't do Trinidad, it may do things differently from the standard. – BalusC Jun 19 '15 at 12:04
  • Actually I've a pop up, after the choice per the pop up, I've to do some business logic(that I'm doing in return listener provided by trinidad framwork) and then I have to navigate to next page(for which I'm relying on hidden button). Is there any better way to do this? I referred some of your answers, you suggested to use h:ouputscript(but my applicaiton is JSF 1.2). Can you help? – prakashb Jun 19 '15 at 13:06

1 Answers1

0

It's working after I made the method pause for 500 milliseconds before clicking the hidden button by the following code. Probably, this is not the right approach(that's why I haven't accepted this answer). I believe someone could explain the issue clearly.

function clickHiddenButton () {
      setTimeout('clickHiddenButtonAfterDelay()',500) 
}



 function clickHiddenButtonAfterDelay() {
          if(null != console)
                console.log('before calling hidden button for close');
          document.getElementById('hiddenButton').click();
          if(null != console)
                console.log('after calling hidden button for close'); 
    }
prakashb
  • 160
  • 1
  • 8