Home » Blog

Paging large data sets with a LazyList

Posted by Roger Keays, 30 April 2007, 6:02 PM

As you might have noticed from reading my previous blogs, I'm a big fan of simple solutions to problems, especially where they reduce the amount of plumbing which needs to be implemented. For some time, my problem has been finding an efficient way to page through large data sets using JPA and JSF UIData components such as <h:dataTable/>.

I had read a lot of difficult ways to solve the problem, and tried using OpenJPA's Large Result Set (LRS) extensions to JPA, but none of these solutions satisfied me in terms of efficiency and simplicity. What I came up with instead, is a basic List implementation which uses the standard JPA API to load the results of a query on-demand.

Read more...

24 comments, post a comment!

CSS Menus

Posted by Roger Keays, 16 April 2007, 10:07 AM

Building menus in HTML can dramatically improve the navigation and useability of your website. Getting it just right can be a very time consuming task though. There are a lot of javascript/dhtml implementations of menus out there but they almost all suffer from excessive bloat, inflexibility and complicated declarations to create the menu.

This blog describes how you can turn any existing HTML unordered list into a dropdown menu that is easily customisable through CSS. No need to call any fancy, indecipherable javascript, hardcode colors or sizes or fiddle with 3rd party library code: just import a single stylesheet and you're done.

We've set the following requirements for our menus:

  1. Require no additional markup (e.g. class names, id's, anchors) other than regular <ul> and <li> tags.
  2. Use no javascript.
  3. Use no browser-dependent code.
  4. Be independent of font size or screen size.

Read more...

9 comments, post a comment!

Ideas for JSF 2.0

Posted by Roger Keays, 1 April 2007, 10:03 AM

So it looks like there is action stirring in the JSF camp, with a draft JSR for JSF 2.0 being released [1]. I know everybody complains about how slowly things move in the JCP, but to be honest, I hadn't expected this so soon. It looks like those guys at Sun have got a pretty clear idea of where they're going with this, but for what its worth, here is a list of things I'd like to see in JSF 2.0 that I've collected over the last year or so.

Read more...

3 comments, post a comment!

Internet Explorer meets the Vary: header

Posted by Roger Keays, 23 March 2007, 1:12 PM

So you've just installed mod_gzip and you're ready to watch you bandwidth usage drop by 50-75%. Problem is, instead of seeing your bandwidth usage go down it actually goes... well.. up. What's going on here? The chances are your problem is caused by yet another obscure bug in Microsoft Internet Explorer. This one prevents the browser caching responses with anything but a mindlessly simple Vary: header.

Let's first have a look at the Vary: header, and what function it is supposed to perform. This header is described in RFC 2616 [1] which describes HTTP 1.1:

A server SHOULD use the Vary header field to inform a cache of what
request-header fields were used to select among multiple
representations of a cacheable response subject to server-driven
negotiation.

Read more...

1 comment, post a comment!

A Simple Alternative to the MyFaces ExtensionFilter

Posted by Roger Keays, 23 March 2007, 10:58 AM

It's great that JSF allows us to build, package and distribute components in such a reusable way. However, one of the shortcomings of the spec (IMHO) is the lack of a common facility to specify external resources that a component may require, such as javascript or CSS files. MyFaces uses a custom ExtensionFilter for it's Tomahawk component library to solve this problem. Unfortunately, this solution isn't without its drawbacks. Here are some of the problems I had with this filter, and my ultimate (very simple) solution.

Read more...

2 comments, post a comment!

TCP Connection Limiting on Sarge

Posted by Roger Keays, 1 March 2007, 7:00 PM

One of the reasons Debian is such a great operating system is because of the huge amount of software tested, ready and available with apt-get. Every now and then though, you have to get your hands dirty and build something yourself and installing connlimit was one of these cases. Here's how I got connlimit working on Sarge.

connlimit, or more correctly ipt_connlimit, is a netfilter module which allows you to add rules to your firewall based on the number of connections a client has made to your server. It's very handy when you get some defective client program making hundreds of requests and unintentionally sapping your server's resources.

Read more...

No comments yet, be the first to comment!

Faking a postback with JSF + Facelets

Posted by Roger Keays, 27 February 2007, 6:11 PM

Have you ever needed to post a form to a different action URL with JSF? How about posting a form from an email or when a session has expired? The JSF spec doesn't allow for these situations because it requires a view to be present in the user's session before the complete lifecycle will be invoked. Here's a handy trick using an extended Facelets ViewHandler that allows you to make a fake postback to a view that doesn't yet exist in the user's session.

Read more...

6 comments, post a comment!

EntityManager per session pattern

Posted by Roger Keays, 28 January 2007, 3:19 PM

A recent webapp I was working on had a fairly simple requirement for a paged table of data from the database. Because of the large amount of data available it couldn't just all be loaded into memory at once, which means a bit more work on the UI side. So rather than write all the plumbing to manage paging and queries I thought I'd give OpenJPA's Large Result Sets (LRS) a try. A LRS is a List which looks and behaves like all the data is already loaded, but is actually fetching it on the fly using database cursors. It all worked wonderfully, except for a few.. erm.. slight problems using the EntityManager-per-session pattern, which is required to keep the LRS open.

Read more...

No comments yet, be the first to comment!

Monitoring the JVM with SNMP

Posted by Roger Keays, 21 January 2007, 4:57 PM

Since Java 1.5, Sun's JVM has included an SNMP agent which is quite handy for keeping an eye on your Java apps using your existing monitoring toolset. Here's how to set up OpenNMS to monitor an app server and produce pretty graphs such as the one below, alongside your other SNMP collected metrics like CPU load and memory usage.

Read more...

18 comments, post a comment!

Why I chose Netbeans

Posted by Roger Keays, 9 January 2007, 5:08 PM

I've been a big fan of vim pretty much since I left high school. I'll admit that it isn't the most welcoming of text editors, but after having grown accustomed to its UI and key bindings I thought I'd never have to look for another editor again. Vim is lightweight, fast, allows you to work without reaching for the mouse, has syntax highlighting for about a billion different languages and can do practically anything you can imagine if you care to check the manual.

Read more...

5 comments, post a comment!