Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conditionally set a style class when last item of ui:repeat is reached?

Tags:

css

jsf-2

I want to have a class on a div, if it is the last one in my repeat.

I have now:

<ui:repeat value="#{myCollection}" var="item"  varStatus="status">
<div class="last">#{item.text}</div>
</ui:repeat>

but I want the class last just on the last div...

#{status.last}

is true, if it is the last div. But how can I get the class to the div?

like image 959
MaxiNet Avatar asked Oct 05 '12 15:10

MaxiNet


1 Answers

Solution 1 if you may afford not to be compatible with IE8 :

Don't do this in JSF, this breaks the purpose of having a CSS to isolate the style from the data.

You may do this in your CSS file :

.normalClass:last-child {

}

Solution 2 :

<ui:repeat value="#{myCollection}" var="item"  varStatus="status">
<div class="#{status.last?'last':''}">#{item.text}</div>
</ui:repeat>
like image 116
Denys Séguret Avatar answered Oct 03 '22 02:10

Denys Séguret