0

I am getting ready for my exam in enterprise application development. We should build simple travel agency application with spring boot, using JSF for building frontend.

I am trying to make a user book a trip (from page details.jsf). But when I click on commandButton, that should make a purchase, action on button is not executed (I know this since I ran it in debug mode and it doesn't stop at break point).

  <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:sec="http://www.springframework.org/security/tags"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xml:lang="en" lang="en">
<ui:composition template="layout.xhtml">
    <ui:define name="title">
        Trip details
    </ui:define>
    <ui:define name="content">
        <c:set var="id" value="#{param['tripID']}"/>
        <c:set var="trip" value="#{travelController.getTrip(id)}"/>
        <c:set var="isPurchased" value="#{param['isPurchased']}"/>
        <c:if test="#{!empty isPurchased}">
            <c:choose>
                <c:when test="#{isPurchased.equals(true)}">
                    <p>Purchase was sucesfull!</p>
                </c:when>
                <c:otherwise>
                    <p>Purchase failed!</p>
                </c:otherwise>
            </c:choose>
        </c:if>
        <c:choose>
            <c:when test="#{empty param['tripID']}">
                <p class="alert alert-danger">No id, can not display data</p>
            </c:when>
            <c:otherwise>
                <div class="descriptionData">
                    <h:outputLabel>Trip to: #{trip.title}</h:outputLabel>
                    <h:outputLabel>Description: #{trip.description}</h:outputLabel>
                    <h:outputLabel>Price: #{trip.cost}</h:outputLabel>
                    <h:outputLabel>Name of location: #{trip.locationName}</h:outputLabel>
                    <h:outputLabel>Departure date: #{trip.departureDate}</h:outputLabel>
                    <h:outputLabel>Return date: #{trip.returnDate}</h:outputLabel>
                    <sec:authenticated>
                        <c:if test="#{travelController.isNotPurchased(trip.id,userInfoController.userName)}">
                            <h:form prependId="false" id="bookingForm">
                                <h:commandButton value="Book the trip"
                                                 action="#{travelController.makePurchase(trip.id,userInfoController.userName)}"
                                                 id="bookingBtn"/>
                            </h:form>
                        </c:if>
                    </sec:authenticated>
                    <div class="userInfoTable">
                        <p class="alert alert-dark">Users taking this trip</p>
                        <h:dataTable styleClass="table table-hover" value="#{trip.allTravelers}"
                                     var="user" border="1" id="tripTable">
                            <h:column>
                                <f:facet name="header">Name</f:facet>
                                <h:outputText value="#{user.name}"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">Last name</f:facet>
                                <h:outputText value="#{user.lastName}"/>
                            </h:column>

                        </h:dataTable>
                    </div>
                </div>
            </c:otherwise>
        </c:choose>

    </ui:define>

</ui:composition>


</html>

Part of code I am talking about is:

<c:if test="#{travelController.isNotPurchased(trip.id,userInfoController.userName)}">
    <h:form prependId="false" id="bookingForm">
        <h:commandButton value="Book the trip"
                         action="#{travelController.makePurchase(trip.id,userInfoController.userName)}"
                         id="bookingBtn"/>
    </h:form>
</c:if>

If info provided is not enough I uploaded the project to GitHub https://github.com/guberArmin/tsdes-exercise

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
guber90
  • 91
  • 1
  • 9
  • 2
    Point 6 of abovelinked duplicate is applicable here. By the way, next time try creating a real [mcve] as per instructions in https://stackoverflow.com/tags/jsf/info. This one has way too much noise. – BalusC Apr 20 '20 at 18:20
  • 1
    and off-topic: https://stackoverflow.com/questions/7415230/uiform-with-prependid-false-breaks-fajax-render – Kukeltje Apr 20 '20 at 18:25
  • Minimum, not working version: https://justpaste.it/1lwpu – guber90 Apr 20 '20 at 20:27

0 Answers0