Solrj and JSTL EL: java.lang.NumberFormatException

While working with a view of a collection of documents returned from Solr using Solrj earlier today, I was attempting to write out the number of documents found in the search. In pure Java code you’d just request this by just calling .getNumFound() on the SolrDocumentList containing your documents, which whould also mean that they should be available through EL in JSTL by calling ${solrDocumentList.numFound} (which in turn calls getNumFound() in the SolrDocumentList object). The code in question was as simple as:


Which resulted in this error message, which kind of came as a surprise:

java.lang.NumberFormatException: For input string: "numFound"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:447)
        at java.lang.Integer.parseInt(Integer.java:497)

After digging around a bit and reading the error message yet again, it suddenly hit me: $solrDocumentList was being interpreted and casted to a List, and as such, EL expected an index into the List instead of my call to a function. I’ve not been working with JSTL for too long, so I thought a bit about how to solve this. One solution would be to do the calls in the Action and then just map them to separate variables in the template, but this wasn’t really as pretty as it could be. Instead I wrote a simple wrapper around the SolrDocumentList, which is not a list in itself, but exposes all the elements through it’s getDocumentList-method. That way we can access it in the template by calling ${solrDocumentList.documentList…}.

I’ve included the simple, simple wrapper here. It should be expanded with access to Facet fields etc, but this should be a simple indicator of my suggested solution.

public class SolrSearchResult
{
    SolrDocumentList resultDocuments = null;

    public SolrSearchResult(SolrDocumentList results)
    {
        this.resultDocuments = results;
    }

    public long getNumFound()
    {
        return this.resultDocuments.getNumFound();
    }

    public long getStart()
    {
        return this.resultDocuments.getStart();
    }

    public float getMaxScore()
    {
        return this.resultDocuments.getMaxScore();
    }

    public SolrDocumentList getDocumentList()
    {
        return this.resultDocuments;
    }

    public void setDocumentList(SolrDocumentList results)
    {
        this.resultDocuments = results;
    }
}

Any comments and updates are of course as always welcome.

Writing a Custom Validator for Zend_Form_Element

My good friend Christer has written a simple tutorial on how to write a custom validator for a Zend_Form_Element. If you’ve ever laid your hands on Zend_Form, you’ll want to have a look at this for a short and concise introduction to the topic. He’ll show you how to create a “repeat the password”-field by creating a custom validator and hooking it onto the original password field. Neat stuff.

Yay for PDO_MYSQLND!

Just found a post detailing the release of the preview version of the MYSQLND support for PDO! For those of us who have grown fond of PDO during the last years and still uses MySQL, this is great news! The MYSQLND library is a reimplementation of the MySQL library, intended for native PHP usage instead of bridging it with the regular interface to libmysql. This brings a neat speed increase and overall goodness.

All hail MYSQLND! I’ll try to give the preview version a try over the weekend. You can read even more over at The PDO/MYSQLND Annoucement at lists.mysql.com or you can have a look at the installation procedure.

After six years..

The previous version of this site had now been idle for at least six years while I’ve been using other sites to communicate with the intarwebs. Well, no more of that and quite a bit more of this. This will be the location where I keep my notes and probably write a few small articles and other stuff about interesting stuff and stuff. Stuff. You know.

The old pages has been permanently moved to old/, so if that’s what you came for, that’s the place to find it. All old links has been tagged as 301 Moved Permanently, so it should still be indexed in the same manner as it used to be. It’ll take a while before all the search engines are updated however, so if you stumble across this site from somewhere else, you’ll know where to look.