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

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

问题描述

我试图将id分配给<ui:repeat>内的组件,像这样:

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">

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

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_.

如果我删除硬编码的column_,则会出现异常:

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

java.lang.IllegalArgumentException:组件标识符不能为零长度的String

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

有什么想法吗?

推荐答案

使用渲染时间标记(例如<ui:repeat>)是不可能的.但是,<ui:repeat>本身已经通过在行索引前添加生成的客户ID来确保其唯一性.因此,只需从组件的ID属性中删除EL部件即可.

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">

使用诸如<c:forEach>的视图构建时间标签(它将基本上生成多个<h:panelGroup>组件,而不是仅生成多次的组件),可以指定这样的动态ID.

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}">

(您只应该了解JSTL的方式可在Facelets中使用)

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

一种替代方法是使用静态<div>元素而不是JSF <h:panelGroup layout="block">组件.

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}">

另请参见:

  • JSF2 Facelets中的JSTL ...有意义吗?
  • See also:

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

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