how to get the item from a list in java and pass it to a variable?

2

I have the following code, which sends a query that returns a list,
within that list there is an element called getHoraEntrada, which comes in Date format, and I in my view just want to show the time, so what I did was create a variable String (inputTime) and pass it the value, to later get just the time with the code that comes below the if.

public void buscaDetalle() {


    incidenciaAnioMesDet = anioMesDetService.findIncidenciaAnioMesDeByAnioMes(cvePersona, annio, mes);
    for (IncidenciaAnioMesDet incidenciaDetalle : incidenciaAnioMesDet) {


        if (incidenciaDetalle.getHoraEntrada() != null) {
            horarioEntrada = incidenciaDetalle.getHoraEntrada().toString();
        }

        //Obtiene el formato correcto
        String str = new String(horarioEntrada);
        String time = str.split("\s")[1].split("\.")[0];
        entrada = time;

    }

}

I have the following table where I show my data

<p:dataTable id="table" var="detalle" styleClass="columns" style="max-width:3000px;max-height:770px;" rendered="#{RegistroAccesoComponent.muestraTablaDetalle}" value="#{RegistroAccesoComponent.incidenciaAnioMesDet}" emptyMessage="No se encontraron registros">

  <p:column headerText="FECHA" style="width:150px;" styleClass="columns">
    <h:outputText />
  </p:column>
  <p:column headerText="ENTRADA" style="width:150px;" styleClass="columns">
    <h:outputText value="#{RegistroAccesoComponent.entrada}" />
  </p:column>
  <p:column headerText="SALIDA" style="width:150px;" styleClass="columns">
    <h:outputText value="#{detalle.horaSalida}" />
  </p:column>

  <p:column headerText="INCIDENCIA" style="width:330px;" styleClass="columns">
    <h:outputText value="#{detalle.incidencias.cveIdIncidencia} - #{detalle.incidencias.concepto}" />
  </p:column>

  <p:column headerText="ACCIONES" style="width:120px;text-align: center" styleClass="columns">
    <p:commandButton icon="ui-icon-search" title="View" onclick="PF('modalIntentos').show();">

    </p:commandButton>
  </p:column>
</p:dataTable>

and in the ENTRY column, I show the time that the query throws me with the variable "input" that declares in my method to show only the time and does it

the detail is that the query gives me a list of records and not all the records brings the data of time entered, then if I do not validate that it is different from null, my page thunders, but if it is valid that is different of null, as it comes in my method, in my table it paints all the records with that same time in the field of ENTRY, which is wrong, xq not all the records bring full that data How can I show the time in the format I want, only in the records that bring that data?

    
asked by Root93 22.02.2018 в 00:19
source

1 answer

1

You should format the date in the view, you could use:

<h:outputText value="#{detalle.horaEntrada}">
    <f:convertDateTime type="date" pattern="HH:mm:ss"/>
</h:outputText>
    
answered by 22.02.2018 в 01:23