3 May 2009

Screen Tweaks on Ubuntu Jaunty

Screen is a must-have tool for anyone that spends time at the command line. I move my .screenrc file around with me whenever I move machine, and hadn't thought about it much for a while, but when I started screen on a Ubuntu Jaunty box with no .screenrc, I noticed that the system-wide screen config in /etc/screenrc is now quite useful.

The screenshot below shows the status line from the default config.


Using two whole lines for status messages seems a bit much but I'm a little old school when it comes to preserving display space. So you get load, CPU, free memory, a clock and named screens without any effort now.

I copied the /etc/screenrc to ~/.screenrc and added a few options

bind x
bind ^x
ignorecase on


The bind options stop C-ax, which normally detaches the terminal from screen, from working. I tend to type that keystroke by accident fairly frequently. The last option ignores case during history searches.

If you use lots of gnome-terminal windows or even tabs to manage your terminal sessions you should try screen, it will speed you up a lot once the keystrokes get wired into your muscle memory.

16 February 2009

MyFaces NoSuchMethodError

java.lang.NoSuchMethodError - org.apache.myfaces.component.html.ext.HtmlDataTable.refresh(Ljavax/faces/context/FacesContext;)V

This exception can be thrown by MyFaces when the page backing bean doesn't return a String that is mapped in the navigation-rules in faces-config.xml (or wherever you have your mapping file).

Check for typos or a missing entry in the navigation rules.

Hibernate gotcha: in clause with positional and named query parameters

Here's a gotcha that can break JPA QL queries with an IN clause when using Hibernate as the persistence provider. The problem happens when you use positional parameters rather than named parameters.

Code such as the following will break with positional parameters:
List states = widgetService.findSomeWidgetStates();
Query q = entityManager.createQuery("select count(w) from Widget w where w.state in (?)");
q.setParameter(1, states);
with the error message:
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Integer field example.Widget.id to....
But if you change to named parameters, as in:
Query q = entityManager.createQuery("select count(w) from Widget w where w.state in (:widgetStates)");
q.setParameter("widgetStates", states);
Everything just works. So it seems named parameters are worth a little extra typing.