<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Safetygoat &#187; jsp last in a loop</title>
	<atom:link href="http://www.safetygoat.co.uk/tag/jsp-last-in-a-loop/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.safetygoat.co.uk</link>
	<description>The goat loves the water</description>
	<lastBuildDate>Tue, 24 May 2011 08:55:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Replace pseudo-class :last-child using JSTL by determining the loop status</title>
		<link>http://www.safetygoat.co.uk/2008/10/replace-pseudo-class-last-child-using-jstl-by-determining-the-loop-status/</link>
		<comments>http://www.safetygoat.co.uk/2008/10/replace-pseudo-class-last-child-using-jstl-by-determining-the-loop-status/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 10:17:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[determining last in a list in jsp]]></category>
		<category><![CDATA[jsp last in a loop]]></category>
		<category><![CDATA[JSTL loop status]]></category>

		<guid isPermaLink="false">http://www.safetygoat.co.uk/?p=119</guid>
		<description><![CDATA[I wanted to know how you&#8217;d figure out when you&#8217;d come to the last in a list of items when coding in a jsp.  When the number of items vary, there&#8217;s no way you can hard code this in.
I wanted to add a :last-child in my webpage so that  my list&#8217;s last element [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to know how you&#8217;d figure out when you&#8217;d come to the last in a list of items when coding in a jsp.  When the number of items vary, there&#8217;s no way you can hard code this in.<br />
I wanted to add a :last-child in my webpage so that  my list&#8217;s last element wouldn&#8217;t have a border-bottom, but the rest of the list would. I&#8217;m all for progressive enhancement, but sometimes things look so shocking in ie7 and ie6 that you just need to find another (non-css) way to take the border off.</p>
<p>In css, it&#8217;s</p>
<p><code>.keyContact li{border-bottom: 1px solid #000;}</code><br />
<code>.keyContact li:last-child{border-bottom: none;}</code><br />
<br />
But this doesn&#8217;t work in IE7 or IE6.  Without it, I get a crappy double line thing, and looks shocking.  In my jsp, I&#8217;m not sure how many key contacts I&#8217;m going to have as it&#8217;s running through a loop.  But for each item we determine their status:<br />
<code>&lt; c:forEach items="${contacts} var="contact" varStatus="status"&gt;</code><br />
	<code>&lt;li class="contact ${status.last ? 'noBorder':">Contact info&lt;/li&gt;  </code><br />
<code>&lt;/c:forEach&gt;</code><br />
<br />
Of course, you still need to define what noBorder is in the css&#8230;</p>
<p><code> .noBorder{border-bottom: none;}</code><br />
<br />
Now you can delete your li:last-child class in order to keep your css tidy.<br />
<br />
This sets a variable so each time it goes through the loop, it knows which is the first, last etc. And when it determines that it is the last element, it will add the class â€œnoBorderâ€, otherwise it will add nothing. (Read it as &#8220;is the status last ? (question mark).  If yes, add noBorder, otherwise (:) add nothing). FYI this is called a JSTL loop status. Hope that helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.safetygoat.co.uk/2008/10/replace-pseudo-class-last-child-using-jstl-by-determining-the-loop-status/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

