jsf - Will Primefaces not automatically generate ID for html tag JSF?
问题描述
Today I found out an interesting thing with tag in JSF. I got this point from a BalusC's comment:
<h:form>
<h:outputText value="#{bean.text1}" styleClass="myClass" />
<p:commandButton value="Update" update="@(.myClass)" />
</h:form>
But the following example will work (note that assigning the form an ID is not necessary):
<h:form>
<h:outputText id="myText" value="#{bean.text1}" styleClass="myClass" />
<p:commandButton value="Update" update="@(.myClass)" />
</h:form>
It seems Primefaces will not generate an ID for plain HTML tag. I tried with several components, but still not sure. So, Is my conclusion correct? If so, why is this behaviour?
解决方案
<span>
假设您要问为什么您的元素上没有 ID 属性,由<h:outputText value="#{bean.text1}" styleClass="myClass" />
:
默认情况下,h:outputText
由com.sun.faces.renderkit.html_basic.TextRenderer
(在 Mojarra 的情况下)渲染的组件不渲染 ID。是否呈现 ID 由com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.shouldWriteIdAttribute(UIComponent)
此处确定:
/** * @param component * the component of interest * * @return true if this renderer should render an id attribute. */ protected boolean shouldWriteIdAttribute(UIComponent component) { // By default we only write the id attribute if: // // - We have a non-auto-generated id, or... // - We have client behaviors. // // We assume that if client behaviors are present, they // may need access to the id (AjaxBehavior certainly does). String id; return (null != (id = component.getId()) && (!id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) || ((component instanceof ClientBehaviorHolder) && !((ClientBehaviorHolder) component).getClientBehaviors().isEmpty()))); }
所有这些都是纯 JSF,与 primefaces 没有任何关系。
推荐阅读
- java - 尝试创建新对象并将其添加到 Arraylist 时出现 Java JPA LazyInitializationException
- php - 如何修复“警告:mysqli_stmt::bind_param():类型定义字符串中的元素数与绑定变量数不匹配”
- android - Kotlin-Android-Extension 不能跨模块工作?
- angular - 如何在 nrgx 8 单元测试中模拟选择器?
- html - Bootstrap 3 'Fixed Navbar' 仅扩展了大约 55-60% 的屏幕高度
- npm - Ext.ux 与 extjs 开放工具
- gitlab - GitLab:推送到 gitlab 后无法访问 API
- python - raise err.ProgrammingError("execute() first") pymysql.err.ProgrammingError: execute() first
- security - 从 i3lock 唤醒时,在请求密码之前允许进行一些交互
- spring-kafka - 消费者如何绑定到指定线程