Add action and onClick to a commandButton

Asked

Viewed 144 times

-1

Good afternoon, I am building a javaWeb system, I wonder if I can add an Action and an onClick in a commandButton?

h:commandButton value="Reservar" action="#{aluguelController.reservarEtios}" onClick="chamaTela();" styleclass="btn btn-primary"/>

1 answer

0

I don’t know if it’s what you need, but I did something about it:

Dialog de confirmação

  <p:commandButton value="Reserva" action="#{locadoraBean.reservarVeiculo}" oncomplete="PF('reserva').show();" />   

    <p:dialog id="mod" modal="true" widgetVar="reserva"
        header="Confirmação da Reserva" draggable="false" closable="true" autoUpdate="true">
        <h:form id="rent-car-dialog">
            <div class="modal-content">

<p:panelGrid columns="2">

<f:facet name="header">
    <p:graphicImage url="/RESOURCES/images/background/toyota_etios.png" />
</f:facet>

<h:outputText value="Veículo:" style="font-weight:bold;"/>
<h:outputText value="Toyota Etios" />

<h:outputText value="Ano/Modelo:" style="font-weight:bold;"/>
<h:outputText value="2018/2019" />

<h:outputText value="Cor:" style="font-weight:bold;"/>
<h:outputText value="Prata" />

<h:outputText value="Placa:" style="font-weight:bold;"/>
<h:outputText value="XXX-0000" />

<h:outputText value="Combustível:" style="font-weight:bold;"/>
<h:outputText value="Flex" />

<h:outputText value="Reservado em nome:" style="font-weight:bold;"/>
<h:outputText value="Fulano de Tal" />

<h:outputText value="Retirada prevista:" style="font-weight:bold;"/>
<h:outputText value="14/06/2019 12:15:00" />

 <h:outputText value="Devolução prevista:" style="font-weight:bold;"/>
<h:outputText value="18/06/2019 12:15:00" />   

 </p:panelGrid> 
    </div>
       </h:form>
          </p:dialog>

In the above example, the method reservarVeiculo not doing anything, just exemplifying, because I created a dialog with data static. From what I understand you want to perform the action of a button, right after calling a screen, so when you choose the reservation information and click on Book, the reservation should be made and then a screen should appear with the information of the reservation made.

I hope I’ve helped, anything just ask again.

  • Thank you very much for your reply. I managed to make the method work without javascript, in case within the method in Java reservarEtios I put a Return with the name of the other page, then it does the redirecting. Now, would you like to tell me if in java there’s any way I can capture the id of that button that calls the method? Thanks again

  • I believe so, but what purpose would it serve?

  • Because I need a method that passes to DAO class the ID of the car, each boot is equivalent to a car so each one has an ID, I would like to pass this ID.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.