this is my first post in the forum. I have a Java enum class with identifier (value) and description (text).
CriteriExlusio.java:
public enum CriteriExclusio{
C1(1, "< 10"),
C2(2, "Low grade"),
C3(3, "Medium grade"),
C4(4, "High grade"),
C5(5, "> 250"),
private final int value;
private final String text;
private CriteriExclusio(int value, String text) {
this.value = value;
this.text = text;
}
public int getValue() { return value; }
public String getText() { return text; }
}
And the controller:
@Named(value = "auxCriteriExclusioController")
@ApplicationScoped
public class AuxCriteriExclusioController {
public CriteriExclusio[] getCriteriExclusio(){
return CriteriExclusio.values();
}
}
I load values-text in selectonemenu properly and stored in the table (values-int) when I submit the form.
.xhtml
<h:selectOneMenu value="#{mbVCriteriExclusio.criteriExclusio.idCriteriExclusio}" id="cmbCriteriExclusio" required="true">
<f:selectItem itemLabel="" itemValue=""></f:selectItem>
<f:selectItems value="#{auxCriteriExclusioController.criteriExclusio}" var="respuestaCriterisExclusio" itemValue="#{respuestaCriterisExclusio.value}" itemLabel="#{respuestaCriterisExclusio.text}" />
</h:selectOneMenu>
The problem is when a page retrieve the data in the table I want to display the text (text) in a outputlabel which corresponds to the value (value) that is stored in the database. It is much more user friendly and need to show the text not the numerical value.
I have searched and tried several options but I can not retrieve the text. Only recover the C1, C2....etc of java enum.
<p:outputLabel value="#{auxCriteriExclusioController.criteriExclusio[itemCriterisExclusio.idCriteriExclusio]}" />
For example if in the table is saved the value 3, the label to be displayed is "Medium grade"
UPDATE. datatable code
<h:form id="frmExclos">
<p:growl id="mensajeGeneral3" sticky="false" showDetail="true"/>
<p:panel id="pnlCriteriExclusio" style="width: 425px" header="Criteris d'exclusió del pacient" widgetVar="pnlCriterisE">
<p:dataTable id="tblCriterisExclusioNia" var="itemCriterisExclusio" value="#{mbRCriteriExclusio.getCriterisExclusioNia(mbVMalignitatNia.personaAmbMalignitatNia.id)}" editable="true">
<p:ajax event="rowEdit" listener="#{mbRCriteriExclusio.onRowEdit}" update=":frmExclos:mensajeGeneral3" />
<p:ajax event="rowEditCancel" listener="#{mbRCriteriExclusio.onRowCancel}" update=":frmExclos:mensajeGeneral3" />
<p:column headerText="Criteri">
<p:cellEditor>
<f:facet name="output">
<p:outputLabel value="#{itemCriterisExclusio.idCriteriExclusio}">
<f:converter converterId="criteriExclusioConverter"/>
</p:outputLabel>
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{itemCriterisExclusio.idCriteriExclusio}" id="cmbCriteriExclusioEditat" required="true">
<f:selectItem itemLabel="" itemValue=""></f:selectItem>
<f:selectItems value="#{auxCriteriExclusioController.criteriExclusio}" var="respuestaCriterisExclusioEditar" itemValue="#{respuestaCriterisExclusioEditar.value}" itemLabel="#{respuestaCriterisExclusioEditar.text}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Observacions">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{itemCriterisExclusio.comentaris}"></h:outputText></f:facet>
<f:facet name="input"><p:inputText value="#{itemCriterisExclusio.comentaris}" label="Observacions"></p:inputText></f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px">
<p:rowEditor />
</p:column>
<f:facet name="footer" >
<p:commandButton update="@this" icon="ui-icon-plusthick" value="Afegir criteri" oncomplete="PF('dlgAddCriterisExclusio').show()"/>
</f:facet>
</p:dataTable>
</p:panel>
</h:form>