我正在努力让JSF执行commandLink背后的操作。它似乎没有执行它的action
,即使它不是以另一种形式嵌套的形式,也不应该有任何验证错误,并且元素似乎正确呈现。
该页面显示了航班预订的详细信息。我正在谈论的按钮应该将用户带到付款页面。
问题一直发生在此文件的表单后面(上面的消息不打印任何内容):
<ui:composition template="/WEB-INF/template.xhtml">
<ui:define name="metaData">
<f:metadata>
<f:viewParam name="departureId" value="#{bookingCreationWizard.departureId}"/>
<f:viewParam name="returnId" value="#{bookingCreationWizard.returnId}"/>
</f:metadata>
</ui:define>
<ui:define name="pageTitle">#{msg.flights_details_page_title}</ui:define>
<ui:define name="pageContent">
<h1>#{msg.flights_details_page_title}</h1>
<h:panelGroup layout="block">
<h2>#{msg.flight_details_h2_departure}</h2>
<table>
<tr>
<th>Airline</th>
<th>Class</th>
<th>Seats Remaining</th>
<th>Departure Time</th>
<th>Flight Duration</th>
<th>Arrival Time</th>
<th>Departure Airport</th>
<th>Arrival Airport</th>
<th>Price</th>
</tr>
<tr>
<td>#{bookingCreationWizard.departureFlight.flight.airline.name}</td>
<td>#{bookingCreationWizard.departureFlight.name}</td>
<td>#{bookingCreationWizard.departureFlight.freeSeats}</td>
<td>#{bookingCreationWizard.departureFlight.flight.departureTime}</td>
<td>TODO</td>
<td>#{bookingCreationWizard.departureFlight.flight.arrivalTime}</td>
<td>#{bookingCreationWizard.departureFlight.flight.departureAirport.code}</td>
<td>#{bookingCreationWizard.departureFlight.flight.arrivalAirport.code}</td>
<td>#{bookingCreationWizard.departureFlight.price}</td>
</tr>
</table>
</h:panelGroup>
<h:panelGroup layout="block" rendered="#{bookingCreationWizard.hasReturnFlight()}">
<h2>#{msg.flight_details_h2_return_flight}</h2>
<table>
<tr>
<th>Airline</th>
<th>Class</th>
<th>Seats Remaining</th>
<th>Departure Time</th>
<th>Flight Duration</th>
<th>Arrival Time</th>
<th>Departure Airport</th>
<th>Arrival Airport</th>
<th>Price</th>
</tr>
<tr>
<td>#{bookingCreationWizard.returnFlight.flight.airline.name}</td>
<td>#{bookingCreationWizard.returnFlight.name}</td>
<td>#{bookingCreationWizard.returnFlight.freeSeats}</td>
<td>#{bookingCreationWizard.returnFlight.flight.departureTime}</td>
<td>TODO</td>
<td>#{bookingCreationWizard.returnFlight.flight.arrivalTime}</td>
<td>#{bookingCreationWizard.returnFlight.flight.departureAirport.code}</td>
<td>#{bookingCreationWizard.returnFlight.flight.arrivalAirport.code}</td>
<td>#{bookingCreationWizard.returnFlight.price}</td>
</tr>
</table>
</h:panelGroup>
<h:panelGroup layout="block">
<h2>#{msg.flight_details_h2_price}</h2>
<table>
<tr>
<th>#{msg.flight_details_price_table_flight}</th>
<th>#{msg.flight_details_price_table_amount}</th>
<th>#{msg.flight_details_price_table_total_price}</th>
</tr>
<tr>
<td>#{bookingCreationWizard.departureFlight.flight.departureAirport.code} - #{bookingCreationWizard.departureFlight.flight.arrivalAirport.code}</td>
<td>#{bookingCreationWizard.numberOfPeople}</td>
<td>#{bookingCreationWizard.departureFlight.finalPrice}</td>
</tr>
<h:panelGroup rendered="#{bookingCreationWizard.hasReturnFlight()}">
<td>#{bookingCreationWizard.returnFlight.flight.departureAirport.code} - #{bookingCreationWizard.returnFlight.flight.arrivalAirport.code}</td>
<td>#{bookingCreationWizard.numberOfPeople}</td>
<td>#{bookingCreationWizard.returnFlight.finalPrice}</td>
</h:panelGroup>
</table>
</h:panelGroup>
<h:panelGroup layout="block">
<h:form>
<h:messages style="color:red;margin:8px;"/>
<h:commandLink action="#{bookingCreationWizard.proceedToPayment()}" value="#{msg.flight_details_booking_button}" />
</h:form>
</h:panelGroup>
</ui:define>
</ui:composition>
</html>
下面我还包含了这个文件嵌入的模板,以及包含应该执行的操作的@Conversationscoped bean。
模板:
<?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:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<f:view locale="#{languageSwitcherController.locale}">
<h:head>
<title><ui:insert name="pageTitle">#{msg.template_title_addon}</ui:insert></title>
<h:outputStylesheet library="css" name="normalize.css"/>
<h:outputStylesheet library="css" name="skeleton.css"/>
<h:outputStylesheet library="css" name="main.css"/>
<ui:insert name="metaData"/>
<meta name="viewport" content="width=device-width, inital-scale=1.0"/>
</h:head>
<h:body>
<h:form id="langauge_form">
<h:commandLink action="#{languageSwitcherController.changeLanguage('nl_BE')}" value="Nederlands"/> |
<h:commandLink action="#{languageSwitcherController.changeLanguage('en')}" value="English"/>
</h:form>
<!--<h:graphicImage name="01.jpg" library="images" width="500" height="100"/>-->
<h1>#{msg.template_header}</h1>
<div>
<ui:insert name="pageContent">
</ui:insert>
</div>
<br/>
#{msg.template_footer}
</h:body>
</f:view>
</html>
豆:
@ConversationScoped
@Named
public class BookingCreationWizard implements Serializable {
@Inject
private Conversation conversation;
@Inject
private CategoryService service;
private Long departureId;
private Long returnId;
private Category departureFlight;
private Category returnFlight;
private int numberOfPeople;
@PostConstruct
public void init() {
this.numberOfPeople = 1;
}
public int getNumberOfPeople() {
return this.numberOfPeople;
}
public void setNumberOfPeople(int numberOfPeople) {
if (conversation.isTransient()){
conversation.begin();
}
this.numberOfPeople = numberOfPeople;
}
public Long getDepartureId() {
return departureId;
}
public void setDepartureId(Long departureId) {
this.departureId = departureId;
}
public Long getReturnId() {
return returnId;
}
public void setReturnId(Long returnId) {
this.returnId = returnId;
}
public Category getDepartureFlight() {
if (departureFlight == null) {
this.departureFlight = service.getFlightById(this.departureId);
}
return this.departureFlight;
}
public Category getReturnFlight() {
if (returnFlight == null) {
this.returnFlight = service.getFlightById(this.returnId);
}
return this.returnFlight;
}
public boolean hasReturnFlight() {
return this.returnId != null;
}
public String chooseFlight() {
return "details.jsf?faces-redirect=true";
}
public String proceedToPayment() {
System.out.print("Proceeding");
return "../pay.jsf";
}
}