JSF生成的ID是否保证在不同的版本和实现中是相同的? [英] Is the ID generated by JSF guaranteed to be the same across different versions and implementations?

查看:116
本文介绍了JSF生成的ID是否保证在不同的版本和实现中是相同的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将使用Selenium为我们的一个JSF应用程序编写全套测试.

We are about to write a full set of tests for one of our JSF applications using Selenium.

到目前为止,似乎有两种首选的方法可以唯一地标识每个元素:通过ID或使用唯一的类名.后者实际上是一个hack,在语义上没有任何意义.前者是正确的方法,但是元素ID由JSF生成.

So far, it seems that there are two preferred approaches to uniquely identify each element: by ID or using a unique class name. The later is really a hack and doesn't make sense semantically. The former is the right approach, but the element IDs are generated by JSF.

我见过的所有不同的JSF实现似乎都使用相同的方法:将父元素用作名称空间,然后使用冒号将元素ID串联起来.足够公平.

All the different JSF implementations I've seen seem to be using the same approach: use the parent element as the namespace and then concatenate the element ID using a colon. Fair enough.

问题是:您知道在JSF规范的某些部分是否可以保证?后来发现,由于JSF x.y更改了其生成ID名称的方式,我们需要重写测试中的所有组件选择器,这将是一个真正的问题.

The question is: do you know if this is guaranteed in some part of the JSF specification? It'd be a real problem to find out later that we need to rewrite all the component selectors in the tests just because JSF x.y changed the way it generates the ID names.

谢谢!

推荐答案

如果未明确提及ID属性,JSF通常会生成组件的ID. 它将以j_idXXX (XXX will be number incremented)

JSF usually generated the ID of components, if ID attribute is not explicitly mentioned. It will be generated in the format j_idXXX (XXX will be number incremented)

<h:form id="LoginForm">
    <h:inputText id="userName" .../>
</h:form>

对于此inputText,id将形成为LoginForm:userName,如果未明确提及id,则它将形成类似LoginForm:j_id15

for this inputText the id will be formed as LoginForm:userName and if id is not mentioned explicitly,then it will be formed something like LoginForm:j_id15

这在JSF规范的第3.1.6节中有所提及,但是没有指定确切的格式. 使用此方法UIComponent.getClientId();生成clientId.单击此链接

This is mentioned in JSF specification in section 3.1.6, But the exact format is not specified though. The clientId is generated using this method UIComponent.getClientId(); Follow this link UIComponent

这篇关于JSF生成的ID是否保证在不同的版本和实现中是相同的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆