如何在 ui:repeat 中设置组件/标签的 id [英] How can I set id of a component/tag inside ui:repeat

查看:22
本文介绍了如何在 ui:repeat 中设置组件/标签的 id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 id 分配给 <ui:repeat> 内的组件,如下所示:

<h:panelGroup layout="block" id="column_#{column.id}"styleClass="#{column.id} dashboard_column">

问题是 #{column.id} 值被正确放置在 styleClass 值内,但它没有被设置在 id 内> 属性.在 id 属性中设置的所有内容是 JSF 自动生成的 id + 我的硬编码值 column_.

如果我删除硬编码的column_,我会得到一个异常:

<块引用>

java.lang.IllegalArgumentException: 组件标识符不能是零长度字符串在

有什么想法吗?

解决方案

这对于诸如 的渲染时标记是不可能的.然而, 本身已经通过在其前面加上行索引来确保生成的客户端 ID 的唯一性.所以只要把组件的ID属性中的EL部分去掉即可.

<h:panelGroup layout="block" id="column">

使用视图构建时间标记,例如 (这将基本上生成多个 组件,而不是只有一个多次渲染),可以像这样指定动态 ID.

<h:panelGroup layout="block" id="column_#{column.id}">

(您应该非常了解 JSTL适用于 Facelets)

另一种方法是使用静态

元素而不是 JSF 组件.

<div id="column_#{column.id}">

另见:

I'm trying to assign an id to a component inside a <ui:repeat> like that:

<ui:repeat value="#{bean.columns}" var="column">
    <h:panelGroup layout="block" id="column_#{column.id}" 
        styleClass="#{column.id} dashboard_column">

The thing is that #{column.id} value is being placed properly inside the styleClass value but its not being set inside the id attribute. All that is being set inside the id attribute is the automatically generated id by the JSF + my hard coded value column_.

If I remove the hard coded column_ I get an exception:

java.lang.IllegalArgumentException: component identifier must not be a zero-length String at

Any Ideas?

解决方案

This is not possible with a render-time tag such as <ui:repeat>. The <ui:repeat> will however by itself already ensure the uniqueness of the generated client ID by prepending it with the row index. So just remove the EL part from the ID attribute of the component.

<ui:repeat value="#{bean.columns}" var="column">
    <h:panelGroup layout="block" id="column">

With a view build time tag such as <c:forEach> (which will basically generate multiple <h:panelGroup> components instead of only one which is rendered multiple times), it is possible to specify a dynamic ID like that.

<c:forEach items="#{bean.columns}" var="column">
    <h:panelGroup layout="block" id="column_#{column.id}">

(you should only be well aware of how JSTL works in Facelets)

An alternative is to use a static <div> element instead of a JSF <h:panelGroup layout="block"> component.

<ui:repeat value="#{bean.columns}" var="column">
    <div id="column_#{column.id}">

See also:

这篇关于如何在 ui:repeat 中设置组件/标签的 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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