Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call commandlink action from Javascript

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?

like image 861
user1338413 Avatar asked Jul 13 '26 23:07

user1338413


1 Answers

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(); 
like image 197
Daniel Avatar answered Jul 15 '26 13:07

Daniel