Facelets repeat Tag Index

后端 未结 2 399
不知归路
不知归路 2020-12-13 01:55

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



        
2条回答
  •  时光说笑
    2020-12-13 02:49

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

    We create 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.

提交回复
热议问题