JSF 2 - show value of object, instead of key
I'm sitting at the moment on a legacy system. I've got some domain objects which are holding only the key of some entities, now开发者_如何学Python I was wondering what would be the best approach to display the value of the entity instead of the given key.
Could this be done by a converter for the <h:outputText />
tag?
E.g.
DomainObject
public class DomainObject {
private String keyOfEntityA;
// getter/setter
}
EntityA
public class EntityA {
private String key;
private String value;
// getter / setter
}
JSF
<h:outputText value="#{controller.domainObject.keyOfEntityA}" />
I don't want to show the key in this case, I want the object and the value
property should be shown.
Is there an elegant way to achieve this or do I have to extend my DomainObject by a wrapper class, which provides the needed objects?
Either replace EntityA
by a Map<String, String>
so that you can use
<h:outputText value="#{controller.map[controller.domainObject.key]}" />
or get hold of them all in a Map<String, EntityA>
with EntityA
's key as map key so that you can do
<h:outputText value="#{controller.entities[controller.domainObject.key].value}" />
I have the impression that EntityA
should really have been a Map<String, String>
from the beginning on or a java.util.Properties
object if they hold applicationwide configuration settings, or perhaps a ResourceBundle
with a bunch of properties files if they represent localized content.
精彩评论