Facelets 重复标签索引

发布于 2024-10-30 08:09:48 字数 268 浏览 1 评论 0原文

有谁知道如何获取 ui:repeat Facelets 标记中元素的索引?

<ui:repeat id="topTenGrd" var="dream" value="#{dreamModifyBean.topDreams}">
    <h:outputText class="dream-title uppercase" value="#{dream.number}. #{dream.title}" />
</ui:repeat>

Does anyone know a way to get the index of the element in a ui:repeat facelets tag?

<ui:repeat id="topTenGrd" var="dream" value="#{dreamModifyBean.topDreams}">
    <h:outputText class="dream-title uppercase" value="#{dream.number}. #{dream.title}" />
</ui:repeat>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帅哥哥的热头脑 2024-11-06 08:09:48

为“varStatus”属性指定一个值:

<ui:repeat id="..." var="..." value="..." varStatus="myVarStatus">

然后可以通过 EL 访问循环索引:

#{myVarStatus.index}

此外,varStatus 还可以使用以下属性:

  • begin 类型 Integer
  • end 类型
  • int 类型的整数索引
  • step 类型的 Integer
  • Even 类型布尔
  • 类型的奇数 布尔类型的
  • 第一个 布尔类型的
  • 最后一个

有关更多详细信息,请参阅:

https://docs.oracle.com/javaee/7/javaserver-faces-2-2/vdldocs-facelets/ui/repeat.html

Specify a value for the "varStatus" attribute:

<ui:repeat id="..." var="..." value="..." varStatus="myVarStatus">

You can then access the loop index via EL:

#{myVarStatus.index}

Additionally, the following properties are available to the varStatus:

  • begin of type Integer
  • end of type Integer
  • index of type int
  • step of type Integer
  • even of type boolean
  • odd of type boolean
  • first of type boolean
  • last of type boolean

For more details, see:

https://docs.oracle.com/javaee/7/javaserver-faces-2-2/vdldocs-facelets/ui/repeat.html

赢得她心 2024-11-06 08:09:48

布莱恩的回答很好,但我认为它可能对信息更具描述性。

我们创建 UI:Repeat

<ui:repeat id="repeatOne" var="listofValues" varStatus="myVarStatus"> </ui:repeat>

使用 UI Repeat 我们可以访问与列表“listofValues”关联的变量中的值。

使用 varStatus 我们可以创建另一个保存不同类型信息的变量。例如,在列表中使用 #{myVarStatus.index} 创建一个表,我们可以使用此信息作为列表上的索引。

1.

2.

3.

当然,如果您指定数组从 0 开始,那么您的列表也会如此,除非您为每个数组添加 1。 #{myVarStatus.index + 1}

这些在需要使用 2 个嵌套的 UI:Repeat 的 2D 数组中也非常有用。

属性 ___Getter_____描述

current     getCurrent()    The item (from the collection) for the current round of iteration
index       getIndex()      The zero-based index for the current round of iteration
count       getCount()      The one-based count for the current round of iteration
first       isFirst()       Flag indicating whether the current round is the first pass through the iteration
last        isLast()        Flag indicating whether the current round is the last pass through the iteration
begin       getBegin()      The value of the begin attribute
end         getEnd()        The value of the end attribute
step        getStep()       The value of the step attribute

带有链接的其他文档:

  1. UI 的属性:可以找到重复 此处

The answer by Brian is good but I think it could be a bit more descriptive for information.

We create UI:Repeat

<ui:repeat id="repeatOne" var="listofValues" varStatus="myVarStatus"> </ui:repeat>

Using UI Repeat we can access the values from the variable we associated with the list 'listofValues'.

Using varStatus we can create another variable that holds different type of information. For example using #{myVarStatus.index} in our list to create a table we can use this information for our index on our list.

1.

2.

3.

Of course if you specify your array to start at 0 then so will your list unless you add 1 to each. #{myVarStatus.index + 1}

These are also very useful in 2D arrays that need to use 2 UI:Repeat that are nested.

Property ___Getter_________Description

current     getCurrent()    The item (from the collection) for the current round of iteration
index       getIndex()      The zero-based index for the current round of iteration
count       getCount()      The one-based count for the current round of iteration
first       isFirst()       Flag indicating whether the current round is the first pass through the iteration
last        isLast()        Flag indicating whether the current round is the last pass through the iteration
begin       getBegin()      The value of the begin attribute
end         getEnd()        The value of the end attribute
step        getStep()       The value of the step attribute

Additional Documentation with links:

  1. Attributes for the UI:Repeat can be found here.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文