Mar 07

Displaytag is a great tag library for rendering data as a table. As well as handling the generation of the html table, it also provides support for easily exporting the table to a variety of formats including Excel (and CSV).

One problem that can occur is Excel formatting the table cells. When it sees a value that looks like a number then it attempts to format it as a number. This can result in values being displayed in Excel in scientific notation when you really want the data to be displayed as is.

To fix this we can use a displaytag column decorator that quotes the values when exporting to Excel. That way excel will see the quoted value and no longer think it as a number and display it without formatting as you require.

import javax.servlet.jsp.PageContext;
import org.displaytag.decorator.DisplaytagColumnDecorator;

public class QuotedExportDecorator implements DisplaytagColumnDecorator {
    public Object decorate(Object value, PageContext pageContext, MediaTypeEnum media) {
        if (media.equals(MediaTypeEnum.EXCEL) || media.equals(MediaTypeEnum.CSV)) {
            value = "=\"" + value + "\"";
        return value;

written by objects \\ tags: , , , ,

Jan 27

Some times you need to tell the browser not to cache some pages in your web application.

To achieve this we can use META tags that instruct the browser how you would like the page cached. As is too often the case the meta tags required can vary between browsers. The “Pragma” meta seems the most widely supported at the moment:

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

Using the following though will give you better browser coverage:

<META HTTP-EQUIV="Cache-Control" CONTENT="max-age=0">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META http-equiv="expires" content="0">
<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

written by objects \\ tags: , ,

Sep 22

If you’re Java process (eg. Tomcat) is running out of PermGen space then you can increase the available space with the following JVM command line option


That would for example increase the amount of PermGen space to 512 MB.

written by objects \\ tags: , , , ,