1

I would like to know how to filter so that only the patents of vehicles that are available appear.

<p:column headerText="Patent car">
<h:outputText value="#{v.fkcar.patent}"/>   
</p:column>

In the database there is a table called State with 2 income

id_state 1 ---- name_state Available and id_state 2 ---- name_state Not available

What I need is that only the patents of the vehicles that have the State in Available are shown

The State table has its respective Bean

I hope you can help me: D

Entry code Rent

   <h:head>
        <title>Realizar Alquiler</title>
        <h:outputStylesheet library="css" name="style.css"  />
    </h:head>
    <h:body>
        <h2>Realizar Alquiler</h2>
        <h:form id="fv">

            <h:panelGrid columns="1" styleClass="panelGridCenter">

            <h:outputText value="Precio"/>
            <p:inputText value="#{alquilerBean.precio}" required="true"/>

            <p:outputLabel for="datetime" value="Fecha" />
            <p:calendar id="datetime" value="#{alquilerBean.fecha3}" pattern="MM/dd/yyyy HH:mm:ss" required="true"/>


            Cliente
            <p:selectOneMenu value="#{alquilerBean.cliente.idCliente}">
                <f:selectItems value="#{clienteBean.cliente}" var="e" itemLabel="#{e.rut}" itemValue="#{e.idCliente}"/>
            </p:selectOneMenu>

            Patente
            <p:selectOneMenu value="#{alquilerBean.vehiculo.idVehiculo}">
                <f:selectItems value="#{vehiculoBean.vehiculos}" var="o" itemLabel="#{o.patente}" itemValue="#{o.idVehiculo}"/>   
            </p:selectOneMenu>

            ¿Entregado?
            <p:selectOneMenu value="#{alquilerBean.entregado.idEntregado}">
                <f:selectItems value="#{entregadoBean.entregado}" var="o" itemLabel="#{o.nombreEntregado}" itemValue="#{o.idEntregado}"/>   
            </p:selectOneMenu>


            <br/>
            <h:outputText value=""/>
            <p:commandButton actionListener="#{alquilerBean.crear()}" value="Agregar Alquiler" update="fv"/>

            </h:panelGrid> 
            <br/>
            <p:dataTable value="#{alquilerBean.alquiler}" var="v" emptyMessage="No hay registros" >


                <p:column headerText="Fecha">
                    <h:outputText value="#{v.fecha}"/>
                </p:column>


                <p:column headerText="Precio">
                    <h:outputText value="#{v.precio}"/>
                </p:column>

                <p:column headerText="Entregado">
                    <h:outputText value="#{v.fkEntregado.nombreEntregado}"/>
                </p:column>

                <p:column headerText="Rut Cliente">
                    <h:outputText value="#{v.fkCliente.rut}"/>
                </p:column>

                <p:column headerText="Patente Auto"

                    <h:outputText value="#{v.fkVehiculo.patente}"/>   

                </p:column>


                     </p:column>





                 <f:facet name="footer">
                     Se han alquilado #{alquilerBean.alquiler.size()} Vehiculos.
                </f:facet>


            </p:dataTable>

        </h:form>    
        <br/>
        <h:form>
        <h:commandLink action="index">
        <h:graphicImage value="resources/images/atras2.png" />
        </h:commandLink>
        </h:form>


    </h:body> </html>

Here is the state bean code.

private int id_entregado;
private String nombre_entregado;


public EntregadoBean() {
}

public String crear(){
    Entregado e = new Entregado();
    e.setNombreEntregado(nombre_entregado);
    entregadoFacade.create(e);
    return "#";
}

public List<Entregado> getEntregado(){
    return entregadoFacade.findAll();
}

public EntregadoFacadeLocal getEntregadoFacade() {
    return entregadoFacade;
}

public void setEntregadoFacade(EntregadoFacadeLocal entregadoFacade) {
    this.entregadoFacade = entregadoFacade;
}

public int getId_entregado() {
    return id_entregado;
}

public void setId_entregado(int id_entregado) {
    this.id_entregado = id_entregado;
}

public String getNombre_entregado() {
    return nombre_entregado;
}

public void setNombre_entregado(String nombre_entregado) {
    this.nombre_entregado = nombre_entregado;
}


 }
currarpickt
  • 2,290
  • 4
  • 24
  • 39
  • 1
    For me your question is unclear. DataTable fetches from `alquilerBean`, but there is no code. It seems you have to filter inside `alquilerBean` like: `public Collection getAlquiler() { return alquielers.stream().filter(filterForAttribute).collect(Collectors.toList());` to only serve the vehicles to display. But as mentioned: make your question more clear. – ChristophS Jul 09 '18 at 06:13
  • @ChristophS: Don't do that in the getter. Or do it lazy http://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times – Kukeltje Jul 09 '18 at 08:15
  • Datatable complete is https://github.com/basnunez/Arrienda_Auto – Yerko Lizama Hermosilla Jul 09 '18 at 08:28
  • Sorry my english is very bad T-T pls help me chris – Yerko Lizama Hermosilla Jul 09 '18 at 08:30
  • @Kukeltje: I know about multiple executions of getters ... but you can do as long as you collect data only once. Same is done in your link (`if (someProperty == null) {...}`) – ChristophS Jul 09 '18 at 09:07
  • @YerkoLizamaHermosilla: pls understand that I don't want to examine your project. Some hints: don't use constructor to initialize bean member variables (AlquilerBean.class), read about PostConstruct annotation. Maybe use an dedicated getter method to only serve the data you want do display (e.g. `getByState(stateAvailable)', read link by Kukeltje why bean gettery may perform bad. Here is an exaple for PostConstruct and dataTable, modify for your needs: https://stackoverflow.com/questions/5765853/how-and-when-should-i-load-the-model-from-database-for-hdatatable – ChristophS Jul 09 '18 at 09:17
  • @ChristophS: yes, that is why I mentioned 'lazy'... in my comment too. ;-) – Kukeltje Jul 09 '18 at 09:53

0 Answers0