http://jira.springframework.org/browse/SWF-834 Sample apps should demonstrate collection and enum binding

This commit is contained in:
Scott Andrews
2008-08-13 14:22:28 +00:00
parent 05c1bca58c
commit dada0b2ef4
7 changed files with 68 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
package org.springframework.webflow.samples.booking;
public enum Amenity {
OCEAN_VIEW, LATE_CHECKOUT, MINIBAR;
}

View File

@@ -49,6 +49,8 @@ public class Booking implements Serializable {
private int beds;
private Amenity amenities;
public Booking() {
}
@@ -178,6 +180,15 @@ public class Booking implements Serializable {
this.creditCardExpiryYear = creditCardExpiryYear;
}
@Transient
public Amenity getAmenities() {
return amenities;
}
public void setAmenities(Amenity amenities) {
this.amenities = amenities;
}
public void validateEnterBookingDetails(MessageContext context) {
if (checkinDate.before(today())) {
context.addMessage(new MessageBuilder().error().source("checkinDate").code(

View File

@@ -89,6 +89,18 @@
</h:selectOneRadio>
</div>
</div>
<div class="field">
<div class="label">
<h:outputLabel for="amenities">Amenities:</h:outputLabel>
</div>
<div class="input">
<h:selectOneRadio id="amenities" value="#{booking.amenities}" layout="pageDirection">
<f:selectItem itemValue="OCEAN_VIEW" itemLabel="Ocean View" />
<f:selectItem itemValue="LATE_CHECKOUT" itemLabel="Late Checkout" />
<f:selectItem itemValue="MINIBAR" itemLabel="Minibar" />
</h:selectOneRadio>
</div>
</div>
<div class="field">
<div class="label">
<h:outputLabel for="creditCard">Credit Card #:</h:outputLabel>

View File

@@ -0,0 +1,5 @@
package org.springframework.webflow.samples.booking;
public enum Amenity {
OCEAN_VIEW, LATE_CHECKOUT, MINIBAR;
}

View File

@@ -5,6 +5,7 @@ import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Entity;
@@ -46,6 +47,8 @@ public class Booking implements Serializable {
private int beds;
private Set<Amenity> amenities;
public Booking() {
Calendar calendar = Calendar.getInstance();
setCheckinDate(calendar.getTime());
@@ -176,6 +179,15 @@ public class Booking implements Serializable {
this.creditCardExpiryYear = creditCardExpiryYear;
}
@Transient
public Set<Amenity> getAmenities() {
return amenities;
}
public void setAmenities(Set<Amenity> amenities) {
this.amenities = amenities;
}
public void validateEnterBookingDetails(MessageContext context) {
if (checkinDate.before(today())) {
context.addMessage(new MessageBuilder().error().source("checkinDate").code(

View File

@@ -22,7 +22,8 @@
<binding property="creditCard" required="true" />
<binding property="creditCardName" required="true" />
<binding property="creditCardExpiryMonth" required="true" />
<binding property="creditCardExpiryYear" required="true" />
<binding property="creditCardExpiryYear" required="true" />
<binding property="amenities" required="false" />
</binder>
<transition on="proceed" to="reviewBooking" />
<transition on="cancel" to="cancel" bind="false" />

View File

@@ -89,7 +89,27 @@
widgetModule : "dijit.form.CheckBox",
widgetAttrs : { value : false }}));
</script>
</div>
</div>
<div class="field">
<div class="label">
Amenities:
</div>
<div id="amenities" class="input">
<ul>
<li><form:checkbox path="amenities" value="OCEAN_VIEW" label="Ocean View" /></li>
<li><form:checkbox path="amenities" value="LATE_CHECKOUT" label="Late Checkout" /></li>
<li><form:checkbox path="amenities" value="MINIBAR" label="Minibar" /></li>
</ul>
<script type="text/javascript">
dojo.query('#amenities input').forEach(function(element){
Spring.addDecoration(new Spring.ElementDecoration({
elementId: element.id,
widgetType : "dijit.form.CheckBox",
widgetAttrs : { checked : element.checked }
}));
});
</script>
</div>
</div>
<div class="field">