Descripción de enumeración en JSP
Frecuentes
Visto 1,118 veces
0
I have a Enum with Key and description like below. In JSP I will be getting the value and I want to display the description.
public enum STATUS {
ACTIVE("A", "Active"),
INACTIVE("I","Inactive"),
PENDING("PND","Pending");
private final String value;
private final String description;
public String getValue() {
return value;
}
public String getDescription() {
return description;
}
STATUS(String value, String description) {
this.value=value;
this.description = description;
}
public static STATUS fromValue(String value) {
if (value != null) {
for (STATUS status : values()) {
if (status.value.equals(value)) {
return status;
}
}
}
return getDefault();
}
}
1 Respuestas
2
As you've there a valid Javabean-compliant getter method, you can just access it the usual Javabean way.
${status.description}
Or if it's referenced as a property of una alternativa, javabean, then do so
${order.status.description}
Respondido 24 ago 12, 21:08
I will get the value as "A" from other object (Aobj) and STATUS enum is other object, I don't have any reference of STATUS in the object (Aobj). - changeme
Por qué tienes un String
"A"
en lugar de Status
ACTIVE
en tu Aobj
? You've got some design mistakes there. Just replace that String
by Status
and this problem will disappear and everything else will instantly become so much easier. - BalusC
I surely agree, after you said it is design issue, then I corrected myself and could able to get the description. - changeme
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas java jsp enums or haz tu propia pregunta.
Define precisely "¿Cómo proceder con esto?"- Lion
What exactly do you mean by "getting the value"? - Samuel Edwin Ward