Call commandlink action from Javascript

10,469

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(); 
Share:
10,469
user1338413
Author by

user1338413

Updated on June 04, 2022

Comments

  • user1338413
    user1338413 almost 2 years

    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?