3

im trying to call a bean from a javascript, using a h:commandLink.

i have a commandLink

                <h:commandLink action="#{bean.go()}"
                    styleClass="simple-submit-button" id="uLink">
                    <f:param name="userId" value="#{param['userId']}" />
                </h:commandLink>

which calls my bean.

and want to call this commandLink from javascript, like this:

document.getElementById('uLink').click();

but i m always getting the error: document.getElementById('uLink') is null.

I tried this:

  • setting h:commandLink immediate="false" and instead of document.getElementById('uLink').click() i used document.getElementById('uLink').immediate=true;
  • usinng h:commandButton instead.
  • using document.getElementById('formId:uLink').click();

Has anyone an idea how i get this work?

user1338413
  • 2,471
  • 8
  • 29
  • 36
  • Show the resulting HTML. It's likely that the HTML id is not simply `uLink`. – Paul Grime May 16 '12 at 15:00
  • do view source and see the id of the button , it might look like someContainerID:uLink or someFormID:uLink and not just uLink so you might need to use document.getElementById('someFormID:uLink').click(); – Daniel May 16 '12 at 15:05
  • you're righ the id is 'formId:uLink'(checked with firebug), so now i dont get the error anymore. but it still doesnt work. – user1338413 May 16 '12 at 15:14
  • 1
    That's a different problem :) – BalusC May 16 '12 at 15:16
  • its not really a different problem. the question is still unsolved: why does the link not calling the action? Or is the script not calling the link? dont know how to find it out. already checked this link http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked any help is appreciated. – user1338413 May 18 '12 at 07:54

1 Answers1

5

do view source in you browser and look on the exact the id of the button , it might look like someContainerID:uLink or someFormID:uLink and not just uLink so you might need to use

document.getElementById('someFormID:uLink').click(); 

OR

document.getElementById('someContainerID:uLink').click(); 
Daniel
  • 36,833
  • 10
  • 119
  • 200
  • @Hitesh, than improve your selector, make unique class for your button/use jquery "ends with selector" etc... You always should have a known selector for your button. – Daniel Jan 22 '14 at 10:27