Geek Lair

Archive for December 2008

Zebra striping tables with JSTL and CSS

with 6 comments

Zebra striping is giving adjacent rows in a table different colors and alternate rows the same color:

Zebra Striped Table

Zebra Striped Table

One way to do it is using JavaScript and CSS. There are a lot of articles describing how to do so. This method has one disadvantage – if the user disables JavaScript in the browser, the table will not be striped. The only way is to hard code the style for each row. This is easily done using JSTL.

If we have a list of objects of type Person, then we can iterate over them using the JSTL <c:forEach> action and render a row for each item. Even and odd rows can be determined from the loop counter:

<table>
    <thead>
	<tr>
	    <td>Sno</td>
	    <td>First Name</td>
	    <td>Last Name</td>
	    <td>Age</td>
	    <td>Gender</td>
	</tr>
    </thead>

    <tbody>
	<c:forEach var="person" items="${persons}" varStatus="i">
	    <c:choose>
		<c:when test="${(i.count) % 2 == 0}">
		    <tr class="even">
		</c:when>
		<c:otherwise>
		    <tr class="odd">
		    </c:otherwise>
		</c:choose>
		<td>${i.count}</td>
		<td>${person.firstName}</td>
		<td>${person.lastName}</td>
		<td>${person.age}</td>
		<td>${person.gender}</td>
	    </tr>
	</c:forEach>
    </tbody>
</table>

 
Even rows will have the style “even” and odd rows “odd”. Here are the CSS styles I used:

<style type="text/css">
    table {
	border-collapse: collapse;
	text-align: center;
    }
    td {
	border: 1px solid #000;
    }
    thead {
	background-color: #000;
	color: #fff;
	font-weight: bold;
    }
    thead td {
	padding: 0 .5em;
    }
    .odd {
	background-color: #E6E6E6;
    }
    .even {
	background-color: #fff;
    }
</style>

Written by anonir

December 16, 2008 at 20:07

Posted in JEE, Web

Tagged with ,

Replace normal double quote with Latex double quote

with 3 comments

By default Latex formats " as an end quote. If you have a  document with sentences which start with ", the formatted document can look awkward with sentences starting with end quotes.

To replace them with `` so that Latex formats them as opening quotes, you can use sed. Save the following code in a text file:

# This is for lines which start with double quotes, but do not end with them
s/^"\([^"][^"]*$\)/``\1/g

# This is for sentences which both start and end with double quotes
s/"\([^"]*"\)/``\1/g

 
Save the file as dblQtReplacer. Now run your Latex file through sed:

sed -f dblQtReplacer latex_file.tex > new_latex_file.tex

Written by anonir

December 15, 2008 at 12:46

Posted in Linux

Tagged with ,

Amarok 2 – First Impressions

leave a comment »

Installed Amarok 2 following this link: http://www.kubuntu.org/news/amarok-2.0

There is no last.fm integration. The earlier versions had this feature of submitting tracks listened to last.fm. It seems support for mp3 players like ipods was also removed. The interface too looks very minimalistic  and is kind of surprising since KDE apps normally have a lot options.

One improvement is the speed of scanning your collection. It is significantly faster in Amarok 2. Other than this improvement, there is nothing noteworthy in Amarok 2 to warrant an upgrade from 1.4.

Written by anonir

December 13, 2008 at 09:53

Posted in Linux

Tagged with ,