Initial pass at spring-js Ajax enhancement.

This commit is contained in:
Jeremy Grelle
2008-04-24 00:30:04 +00:00
parent b8e60ba86e
commit 391931a3af
8 changed files with 97 additions and 75 deletions

View File

@@ -36,12 +36,14 @@ public class HotelsController {
}
@RequestMapping(method = RequestMethod.GET)
public Hotel show(@RequestParam("id") Long id) {
public Hotel show(@RequestParam("id")
Long id) {
return bookingService.findHotelById(id);
}
@RequestMapping(method = RequestMethod.GET)
public String deleteBooking(@RequestParam("id") Long id) {
public String deleteBooking(@RequestParam("id")
Long id) {
bookingService.cancelBooking(id);
return "redirect:index";
}

View File

@@ -46,7 +46,7 @@
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="requestContextAttribute" value="requestContext"/>
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
<property name="viewClass" value="org.springframework.js.ajax.view.TilesAjaxView"/>
</bean>
<!-- Enables annotated POJO @Controllers -->

View File

@@ -43,11 +43,10 @@
<div class="input">
<form:input path="checkinDate"/>
<script type="text/javascript">
dojo.require('dijit.form.DateTextBox');
Spring.decorations.push(new Spring.ElementDecoration({
elementId : 'checkinDate',
widgetType : dijit.form.DateTextBox,
widgetAttrs : { value : dojo.date.locale.parse(dojo.byId('checkinDate').value, {selector : 'date', datePattern : 'yyyy-MM-dd'}), required : true }}));
elementId : "checkinDate",
widgetType : "dijit.form.DateTextBox",
widgetAttrs : { value : dojo.date.locale.parse(dojo.byId("checkinDate").value, {selector : "date", datePattern : "yyyy-MM-dd"}), required : true }}));
</script>
</div>
</div>
@@ -58,11 +57,10 @@
<div class="input">
<form:input path="checkoutDate"/>
<script type="text/javascript">
dojo.require('dijit.form.DateTextBox');
Spring.decorations.push(new Spring.ElementDecoration({
elementId : 'checkoutDate',
widgetType : dijit.form.DateTextBox,
widgetAttrs : { value : dojo.date.locale.parse(dojo.byId('checkoutDate').value, {selector : 'date', datePattern : 'yyyy-MM-dd'}), required : true }}));
elementId : "checkoutDate",
widgetType : "dijit.form.DateTextBox",
widgetAttrs : { value : dojo.date.locale.parse(dojo.byId("checkoutDate").value, {selector : "date", datePattern : "yyyy-MM-dd"}), required : true }}));
</script>
</div>
</div>
@@ -86,15 +84,14 @@
<form:radiobutton id="smoking" path="smoking" label="Smoking" value="true"/>
<form:radiobutton id="non-smoking" path="smoking" label="Non Smoking" value="false"/>
<script type="text/javascript">
dojo.require('dijit.form.CheckBox');
Spring.decorations.push(new Spring.ElementDecoration({
elementId : 'smoking',
widgetType : dijit.form.RadioButton,
widgetAttrs : { promptMessage : 'Smoking room' }}));
widgetType : "dijit.form.RadioButton",
widgetModule : "dijit.form.CheckBox" }));
Spring.decorations.push(new Spring.ElementDecoration({
elementId : 'non-smoking',
widgetType : dijit.form.RadioButton,
widgetAttrs : { promptMessage : 'Non-smoking room' }}));
widgetType : "dijit.form.RadioButton",
widgetModule : "dijit.form.CheckBox" }));
</script>
</div>
@@ -106,11 +103,11 @@
<div class="input">
<form:input path="creditCard"/>
<script type="text/javascript">
dojo.require('dijit.form.ValidationTextBox');
Spring.decorations.push(new Spring.ElementDecoration({
elementId : 'creditCard',
widgetType : dijit.form.ValidationTextBox,
widgetAttrs : { required : true, invalidMessage : 'A 16-digit credit card number is required.', regExp : '[0-9]{16}' }}));
elementId : "creditCard",
widgetType : "dijit.form.ValidationTextBox",
widgetAttrs : { required : true, invalidMessage : "A 16-digit credit card number is required.",
regExp : "[0-9]{16}" }}));
</script>
</div>
</div>
@@ -121,10 +118,9 @@
<div class="input">
<form:input path="creditCardName" maxlength="40"/>
<script type="text/javascript">
dojo.require('dijit.form.ValidationTextBox');
Spring.decorations.push(new Spring.ElementDecoration({
elementId : 'creditCardName',
widgetType : dijit.form.ValidationTextBox,
elementId : "creditCardName",
widgetType : "dijit.form.ValidationTextBox",
widgetAttrs : { required : true }}));
</script>
</div>

View File

@@ -0,0 +1,56 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div id="hotelResults" class="section">
<c:if test="${not empty hotels}">
<table class="summary">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th>City, State</th>
<th>Zip</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<c:forEach var="hotel" items="${hotels}">
<tr>
<td>${hotel.name}</td>
<td>${hotel.address}</td>
<td>${hotel.city}, ${hotel.state}, ${hotel.country}</td>
<td>${hotel.zip}</td>
<td><a href="show?id=${hotel.id}">View Hotel</a></td>
</tr>
</c:forEach>
<c:if test="${empty hotels}">
<tr>
<td colspan="5">No hotels found</td>
</tr>
</c:if>
</tbody>
</table>
<div class="next">
<c:if test="${not empty hotels}">
<a id="moreResultsLink" href="search?searchString=${searchCriteria.searchString}&pageSize=${searchCriteria.pageSize}&page=${searchCriteria.page + 1}">More Results</a>
<script>
Spring.addDecoration(new Spring.AjaxEventDecoration({
elementId: "moreResultsLink",
event: "onclick",
params: {fragments: "hotelResults"}
}));
</script>
</c:if>
</div>
<div class="prev">
<c:if test="${searchCriteria.page > 0}">
<a id="prevResultsLink" href="search?searchString=${searchCriteria.searchString}&pageSize=${searchCriteria.pageSize}&page=${searchCriteria.page - 1}">Previous Results</a>
<script>
Spring.addDecoration(new Spring.AjaxEventDecoration({
elementId: "prevResultsLink",
event: "onclick",
params: {fragments: "hotelResults"}
}));
</script>
</c:if>
</div>
</c:if>
</div>

View File

@@ -11,11 +11,10 @@
<fieldset>
<form:input path="searchString"/>
<script type="text/javascript">
dojo.require('dijit.form.ValidationTextBox');
Spring.decorations.push(new Spring.ElementDecoration({
elementId : 'searchString',
widgetType : dijit.form.ValidationTextBox,
widgetAttrs : { promptMessage : 'Search hotels by name, address, city, or zip.' }}));
elementId : "searchString",
widgetType : "dijit.form.ValidationTextBox",
widgetAttrs : { promptMessage : "Search hotels by name, address, city, or zip." }}));
</script>
<label for="pageSize">Maximum results:</label>
<form:select path="pageSize">
@@ -23,6 +22,7 @@
<form:option label="10" value="10"/>
<form:option label="20" value="20"/>
</form:select>
<form:hidden path="page"/>
<input type="submit" class="button" value="Find Hotels" />
</fieldset>
</div>

View File

@@ -1,40 +1,8 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<div class="section">
<div id="heading" class="section">
<h1>Hotel Results</h1>
</div>
<c:if test="${not empty hotels}">
<div class="section">
<table class="summary">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th>City, State</th>
<th>Zip</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<c:forEach var="hotel" items="${hotels}">
<tr>
<td>${hotel.name}</td>
<td>${hotel.address}</td>
<td>${hotel.city}, ${hotel.state}, ${hotel.country}</td>
<td>${hotel.zip}</td>
<td>
<a href="show?id=${hotel.id}">View Hotel</a>
</td>
</tr>
</c:forEach>
<c:if test="${empty hotels}">
<tr>
<td colspan="5">No hotels found</td>
</tr>
</c:if>
</tbody>
</table>
</div>
</c:if>
<tiles:insertAttribute name="hotelResults" />

View File

@@ -10,8 +10,11 @@
</definition>
<definition name="hotels/search" extends="standard-layout">
<put-attribute name="body" value="/WEB-INF/hotels/search.jsp" />
<put-attribute name="body" value="search.body" />
</definition>
<definition name="search.body" template="/WEB-INF/hotels/search.jsp">
<put-attribute name="hotelResults" value="/WEB-INF/hotels/hotelResults.jsp" />
</definition>
<definition name="hotels/show" extends="standard-layout">
<put-attribute name="body" value="/WEB-INF/hotels/show.jsp" />

View File

@@ -31,11 +31,10 @@
<div class="output">
<input type="text" name="j_username" id="j_username" <c:if test="${not empty param.login_error}">value="<%= session.getAttribute(AuthenticationProcessingFilter.SPRING_SECURITY_LAST_USERNAME_KEY) %>"</c:if> />
<script type="text/javascript">
dojo.require('dijit.form.ValidationTextBox');
Spring.decorations.push(new Spring.ElementDecoration({
elementId : 'j_username',
widgetType : dijit.form.ValidationTextBox,
widgetAttrs : { promptMessage : 'Your username', required : true }}));
elementId : "j_username",
widgetType : "dijit.form.ValidationTextBox",
widgetAttrs : { promptMessage : "Your username", required : true }}));
</script>
</div>
</div>
@@ -44,11 +43,10 @@
<div class="output">
<input type="password" name="j_password" id="j_password" />
<script type="text/javascript">
dojo.require('dijit.form.ValidationTextBox');
Spring.decorations.push(new Spring.ElementDecoration({
elementId : 'j_password',
widgetType : dijit.form.ValidationTextBox,
widgetAttrs : { promptMessage : 'Your password', required : true}}));
elementId : "j_password",
widgetType : "dijit.form.ValidationTextBox",
widgetAttrs : { promptMessage : "Your password", required : true}}));
</script>
</div>
</div>
@@ -57,10 +55,9 @@
<div class="output">
<input type="checkbox" name="_spring_security_remember_me" id="remember_me" />
<script type="text/javascript">
dojo.require('dijit.form.CheckBox');
Spring.decorations.push(new Spring.ElementDecoration({
elementId : 'remember_me',
widgetType : dijit.form.CheckBox}));
elementId : "remember_me",
widgetType : "dijit.form.CheckBox"}));
</script>
</div>
</div>