Class:
public class Booking {
String foo1;
String foo2;
}
Converter:
@FacesConverter(forClass = Booking.class)
public class BookingDisplayConverter implements Converter {
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
Booking booking = (Booking) arg2;
return (booking.getFoo1() +" ("+ booking.getFoo2() +")");
}
@Override
public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
This works fine:
<h:outputText value="#{ViewReservation.booking}"/>
This does not (it uses toString()):
<h:commandButton value="Email" onclick="location.href = 'mailto:me@example.com?subject=Reservation: #{ViewReservation.booking})'; return false;"/>
Is there a way to get the converter to work in the 2nd example?
EDIT: I'm aware that I could create a ApplicationBean scoped formatter that could do something like #{ApplicationBean.formatBooking(booking)} but I'm looking for something a little more elegant.