How to display the contents of a list that comes with numeric fields in String in java?

0

I have the following list, and I pass a find, which returns a list of Access Registry

private List<RegistroAcceso> listRegistroAcceso;
       listRegistroAcceso = registroAccesoService.findRegistroAccesoByNuserid(cvePersona);

Within that list there are 3 fields: NREADERIDN, NEVENTIDN and NDATETIME, each of them has numerical values, for example for the NREADERIDN field, if the values of that field are 52739, 52731 and 52733, then the value corresponds to it INDEPENDENCE, but if its values are 3320, and 3321, it corresponds INDEPENDENCE1

for example for the NEVENTIDN field, if its value is 55, 40 and 41 then it corresponds to SUCCESSFUL, if not corresponds ERRONEO then I want to convert those numerical values that the fields bring, in String type values, and that I can show that list, but with its value in text as well as in the image

I have this table, but right now it only shows me the value of the fields in numeric

<p:dialog header="Análisis de Registros" widgetVar="modalIntentos" modal="true" height="200" width="600px" appendTo="@(body)">
  <h:form>
    <p:dataTable styleClass="columns" style="max-width:3000px;max-height:770px;" var="biometrico" value="#{RegistroAccesoComponent.listRegistroAcceso}">

      <p:column headerText="DISPOSITIVO" style="width:150px;">
        <h:outputText value="#{biometrico.nreaderidn}" />
      </p:column>
      <p:column headerText="EVENTO" style="width:150px;">
        <h:outputText value="#{biometrico.neventidn}" />
      </p:column>
      <p:column headerText="FECHA / HORA" style="width:150px;">
        <h:outputText value="#{biometrico.ndatetime}" />
      </p:column>


    </p:dataTable>
  </h:form>
</p:dialog>

How can I show the data in string in the table?

    
asked by Root93 15.03.2018 в 23:46
source

1 answer

0

The easiest thing to do is to add to RegistroAcceso the getters that the logic provides.

P. ex.

public String getDescEventId() {
   switch (this.getNeventidn()) {
      case "55":
      case "40":
         return "EXITOSO";
      default:
         return "ERRONEO";
   }
}

And in the JSF

    <h:outputText value="#{biometrico.descEventId}" />

Other alternatives:

  • Develop a set of JSTL functions that contain the transformation logic; you end up having something like this:

    <h:outputText value="#{funciones:descripcionEvento(biometrico.neventidn)}" />
    
  • If you do not want to modify RegistroAcceso create a class with the necessary methods, and for each RegistroAcceso create an instance with your data of the new class. Use this last class to represent the data.

answered by 16.03.2018 в 01:16