从 Javascript 调用命令链接操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10621209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call commandlink action from Javascript
提问by user1338413
im trying to call a bean from a javascript, using a h:commandLink.
我正在尝试使用 ah:commandLink 从 javascript 调用 bean。
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:
并想从 javascript 调用此 commandLink,如下所示:
document.getElementById('uLink').click();
but i m always getting the error: document.getElementById('uLink') is null.
但我总是收到错误:document.getElementById('uLink') 为空。
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();
- 设置 h:commandLinkimmediate="false" 而不是 document.getElementById('uLink').click() 我使用了 document.getElementById('uLink').immediate=true;
- 使用 h:commandButton 代替。
- 使用 document.getElementById('formId:uLink').click();
Has anyone an idea how i get this work?
有谁知道我是如何得到这份工作的?
回答by Daniel
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
做view source
你该按钮的确切的ID浏览器和外观,它可能看起来像someContainerID:uLink
或someFormID:uLink
不只是uLink
这样,你可能需要使用
document.getElementById('someFormID:uLink').click();
OR
或者
document.getElementById('someContainerID:uLink').click();