admin管理员组文章数量:1336660
I have the following code.
<h:form id="Form">
<div class="pageBody">
<h:outputLabel id="lbl" styleClass="formLabel" value="#{messages['lable.email']}:" />
<s:button id="login" label="#{messages['login.button']}" actionBean="#{account}" actionMethod="login" />
</div>
</h:form>
Here is the javascript
var obj = document.getElementById("Form:lbl"); //This works
var obj1 = document.getElementById("Form:login"); //This doesnt work
Keep in mind that <s:button>
is a custom JSF Component.
Any help is appreciated
I have the following code.
<h:form id="Form">
<div class="pageBody">
<h:outputLabel id="lbl" styleClass="formLabel" value="#{messages['lable.email']}:" />
<s:button id="login" label="#{messages['login.button']}" actionBean="#{account}" actionMethod="login" />
</div>
</h:form>
Here is the javascript
var obj = document.getElementById("Form:lbl"); //This works
var obj1 = document.getElementById("Form:login"); //This doesnt work
Keep in mind that <s:button>
is a custom JSF Component.
Any help is appreciated
Share Improve this question edited Aug 12, 2011 at 14:40 BalusC 1.1m376 gold badges3.6k silver badges3.6k bronze badges asked Aug 12, 2011 at 14:36 user891935user891935 251 silver badge4 bronze badges1 Answer
Reset to default 5It should work fine with custom ponents. Is it a custom ponent or a posite ponent? The problem you're having and the presence of JSF 2.0 tag indicates that it's actually a ponsite ponent. For the difference between custom tags, custom ponents and posite ponents, check When to use <ui:include>, tag files, posite ponents and/or custom ponents?
In this answer, I'll assume that it's indeed a posite ponent.
First of all, JavaScript works with HTML DOM tree, not with JSF ponent tree. JavaScript namely runs on webbrowser, not on webserver. JSF runs on webserver, produces a bunch of HTML and sends it to webbrowser. The document.getElementById()
accepts only HTML DOM element ID's.
So, to find out which HTML DOM element ID the <s:button>
has generated, you should open the JSF page in your webbrowser, do a rightclick and then View Source and locate the generated HTML element in the HTML source.
In case of your <s:button id="login">
posite ponent which in turn uses for example <h:mandButton id="button">
in the implementation, then it'll look like something like this:
<input type="submit" id="Form:login:button" />
A posite ponent by itself namely an NamingContainer
ponent, which prepends the IDs like that. The <h:form>
is also such a ponent. This enables you to use multiple posite ponents inside the same parent container.
You should use exactly that ID in your JavaScript function.
var button = document.getElementById("Form:login:button");
本文标签: jsf 2How to access custom JSF tags through javascript getElementByIdStack Overflow
版权声明:本文标题:jsf 2 - How to access custom JSF tags through javascript getElementById - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742418726a2471223.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论