Is it possible to have a converter display some non-id value of an entity?
I need to display a fraction in an edit field that is represented as a separate numerator and denominator back in the entity.
EL: <h:inputText value="#{myEntity}" converter="fractionConverter"> Entity: MyEntity { Integer num; Integer den; ... } Converter: @Name("fractionConverter") @Scope(ScopeType.CONVERSATION) @Converter @BypassInterceptors public class FractionConverter implements javax.faces.convert.Converter { public String getAsString(FacesContext ctx, UIComponent component, Object o) { MyEntity myEntity = (MyEntity) o; return myEntity.getNum() + "/" + myEntity.getDen(); } public Object getAsObject(FacesContext context, UIComponent component, String value) { 'value' is some fraction, so there is no way to find out what myEntity I should use???? I have no identity key for the entity. }
Would anyone have any idea about this? I need to display some non-primary key values back in a single JSF UI component.