I'm having trouble using a selectOneRadio component. I get a NullPointerException in my Converter's getAsString. That exception is thrown before I even get to see that component.
This is how it looks like:
<h:selectOneRadio id="bookA"
value="#{bookHandler.compareBookA}">
<f:converter converterId="bookConverter" />
<f:selectItems value="#{bookHandler.selectedBooks}"
var="book" itemLabel="#{book.shortname}" itemValue="#{book}" />
</h:selectOneRadio>
The property compareBookA is an object of type Book.
This is the method that throws the NPE:
@Override
public String getAsString(FacesContext fc, UIComponent uic, Object value)
throws ConverterException {
Book book = (Book) value;
if (book == null ) {
throw new ConverterException("NPE...");
}
return book.getShortname();
}
I have also overwritten toString().
For some reason the component is rendered if I change it to selectManyCheckbox (and leave the rest like it is).
I'm using JSF 2 (MyFaces implementation) with Tomahawk on Tomcat.
Bonus question: Why do I need a converter in the first place? If I leave the converter away, the component is rendered, but I want to pass the chosen book to some action method and it won't be a Book then.
Any ideas? Thanks!