klausur-practice-2
This commit is contained in:
31
src/main/java/org/example/demo/beans/BookingBean.java
Normal file
31
src/main/java/org/example/demo/beans/BookingBean.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package org.example.demo.beans;
|
||||||
|
|
||||||
|
import jakarta.enterprise.context.SessionScoped;
|
||||||
|
import jakarta.inject.Named;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Named
|
||||||
|
@SessionScoped
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class BookingBean implements Serializable {
|
||||||
|
private String passengerName;
|
||||||
|
private Integer luggageCount = 0;
|
||||||
|
private Double totalPrice = 100.0;
|
||||||
|
|
||||||
|
public void calculate() {
|
||||||
|
if (luggageCount == null) luggageCount = 0;
|
||||||
|
totalPrice = 100.0 + (luggageCount * 25.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String book() {
|
||||||
|
return "confirmation";
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/main/webapp/klausur2/booking.xhtml
Normal file
38
src/main/webapp/klausur2/booking.xhtml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
||||||
|
<!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:ui="jakarta.faces.facelets"
|
||||||
|
xmlns:f="jakarta.faces.core"
|
||||||
|
xmlns:h="jakarta.faces.html"
|
||||||
|
xmlns:p="http://primefaces.org/ui">
|
||||||
|
<h:head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
|
||||||
|
<title>Booking Website</title>
|
||||||
|
</h:head>
|
||||||
|
<body>
|
||||||
|
<f:view>
|
||||||
|
<h:form>
|
||||||
|
<h:panelGrid columns="2">
|
||||||
|
<h:outputLabel for="name">Name: </h:outputLabel>
|
||||||
|
<h:inputText id="name" value="#{bookingBean.passengerName}"/>
|
||||||
|
|
||||||
|
<h:outputLabel for="bagsInput">Anzahl Koffer: </h:outputLabel>
|
||||||
|
<h:inputText id="bagsInput" value="${bookingBean.luggageCount}">
|
||||||
|
<p:ajax event="keyup"
|
||||||
|
process="@this"
|
||||||
|
listener="#{bookingBean.calculate}"
|
||||||
|
update="priceOutput"
|
||||||
|
/>
|
||||||
|
</h:inputText>
|
||||||
|
|
||||||
|
<h:outputLabel for="priceOutput">Aktueller Preis</h:outputLabel>
|
||||||
|
<h:outputText id="priceOutput" value="#{bookingBean.totalPrice} $"/>
|
||||||
|
|
||||||
|
<h:outputText value="" />
|
||||||
|
<h:commandButton value="Jetzt buchen" action="#{bookingBean.book}"/>
|
||||||
|
|
||||||
|
</h:panelGrid>
|
||||||
|
</h:form>
|
||||||
|
</f:view>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user