Final polish of Ajax support.

This commit is contained in:
Jeremy Grelle
2008-04-25 16:06:14 +00:00
parent b8151d133f
commit ff33b67afc
22 changed files with 579 additions and 360 deletions

View File

@@ -0,0 +1,31 @@
package org.springframework.js.ajax;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.support.RequestContextUtils;
import org.springframework.web.servlet.view.RedirectView;
public class AjaxRedirectView extends RedirectView implements View {
private AjaxHandler ajaxHandler = new SpringJavascriptAjaxHandler();
public AjaxRedirectView(String redirectUrl, boolean redirectContextRelative, boolean redirectHttp10Compatible) {
super(redirectUrl, redirectContextRelative, redirectHttp10Compatible);
}
protected void sendRedirect(HttpServletRequest request, HttpServletResponse response, String targetUrl,
boolean http10Compatible) throws IOException {
ServletContext context = RequestContextUtils.getWebApplicationContext(request).getServletContext();
if (ajaxHandler.isAjaxRequest(context, request, response)) {
ajaxHandler.sendAjaxRedirect(context, request, response, targetUrl, false);
} else {
super.sendRedirect(request, response, targetUrl, http10Compatible);
}
}
}

View File

@@ -0,0 +1,28 @@
package org.springframework.js.ajax;
import java.util.Locale;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
public class AjaxUrlBasedViewResolver extends UrlBasedViewResolver {
/**
* Overridden to implement check for "redirect:" prefix.
* <p>
* Redirect requires special behavior on an Ajax request.
*/
protected View createView(String viewName, Locale locale) throws Exception {
// If this resolver is not supposed to handle the given view,
// return null to pass on to the next resolver in the chain.
if (!canHandle(viewName, locale)) {
return null;
}
// Check for special "redirect:" prefix.
if (viewName.startsWith(REDIRECT_URL_PREFIX)) {
String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length());
return new AjaxRedirectView(redirectUrl, isRedirectContextRelative(), isRedirectHttp10Compatible());
}
return super.createView(viewName, locale);
}
}

View File

@@ -17,13 +17,14 @@ import org.apache.tiles.context.TilesRequestContext;
import org.apache.tiles.impl.BasicTilesContainer;
import org.springframework.js.ajax.AjaxHandler;
import org.springframework.js.ajax.SpringJavascriptAjaxHandler;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.support.JstlUtils;
import org.springframework.web.servlet.support.RequestContext;
import org.springframework.web.servlet.view.tiles2.TilesView;
public class AjaxTilesView extends TilesView {
public static final String FRAGMENTS_PARAM = "fragments";
private static final String FRAGMENTS_PARAM = "fragments";
private AjaxHandler ajaxHandler = new SpringJavascriptAjaxHandler();
@@ -48,16 +49,22 @@ public class AjaxTilesView extends TilesView {
Map flattenedAttributeMap = new HashMap();
flattenAttributeMap(container, tilesRequestContext, flattenedAttributeMap, compositeDefinition);
String attrName = request.getParameter(FRAGMENTS_PARAM);
Attribute attributeToRender = (Attribute) flattenedAttributeMap.get(attrName);
container.render(attributeToRender, response.getWriter(), new Object[] { request, response });
String[] attrNames = getRenderFragments(model, request, response);
response.flushBuffer();
for (int i = 0; i < attrNames.length; i++) {
Attribute attributeToRender = (Attribute) flattenedAttributeMap.get(attrNames[i]);
container.render(attributeToRender, response.getWriter(), new Object[] { request, response });
}
} else {
super.renderMergedOutputModel(model, request, response);
}
}
protected String[] getRenderFragments(Map model, HttpServletRequest request, HttpServletResponse response) {
String attrName = request.getParameter(FRAGMENTS_PARAM);
return StringUtils.commaDelimitedListToStringArray(attrName);
}
private void flattenAttributeMap(BasicTilesContainer container, TilesRequestContext requestContext, Map resultMap,
Definition compositeDefinition) throws Exception {
Iterator i = compositeDefinition.getAttributes().keySet().iterator();

File diff suppressed because one or more lines are too long

View File

@@ -13,8 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
dojo.declare("Spring.DefaultEquals", null, {
equals : function(/*Object*/other){
if (other.declaredClass && other.declaredClass == this.declaredClass) {
return true;
}else{
return false;
}
}
});
dojo.declare("Spring.ElementDecoration", Spring.AbstractElementDecoration, {
dojo.declare("Spring.ElementDecoration", [Spring.AbstractElementDecoration, Spring.DefaultEquals], {
constructor : function(config) {
this.copyFields = new Array('name', 'value', 'type', 'checked', 'selected', 'readOnly', 'disabled', 'alt', 'maxLength');
dojo.mixin(this, config);
@@ -28,17 +37,23 @@ dojo.declare("Spring.ElementDecoration", Spring.AbstractElementDecoration, {
dijit.byId(this.elementId).destroyRecursive(false);
}
var element = dojo.byId(this.elementId);
for (var copyField in this.copyFields) {
copyField = this.copyFields[copyField];
if (!this.widgetAttrs[copyField] && element[copyField] && (typeof element[copyField] != 'number' ||
(typeof element[copyField] == 'number' && element[copyField] >= 0))) {
this.widgetAttrs[copyField] = element[copyField];
}
if (!element) {
console.error("Could not apply " + this.widgetType + " decoration. Element with id '" + this.elementId + "' not found in the DOM.");
}
else {
for (var copyField in this.copyFields) {
copyField = this.copyFields[copyField];
if (!this.widgetAttrs[copyField] && element[copyField] &&
(typeof element[copyField] != 'number' ||
(typeof element[copyField] == 'number' && element[copyField] >= 0))) {
this.widgetAttrs[copyField] = element[copyField];
}
}
dojo.require(this.widgetModule);
var widgetConstructor = dojo.eval(this.widgetType);
this.widget = new widgetConstructor(this.widgetAttrs, element);
this.widget.startup();
}
dojo.require(this.widgetModule);
var widgetConstructor = dojo.eval(this.widgetType);
this.widget = new widgetConstructor(this.widgetAttrs, element);
this.widget.startup();
//return this to support method chaining
return this;
},
@@ -54,10 +69,10 @@ dojo.declare("Spring.ElementDecoration", Spring.AbstractElementDecoration, {
this.widget._setStateClass();
}
return isValid;
}
}
});
dojo.declare("Spring.ValidateAllDecoration", Spring.AbstractValidateAllDecoration, {
dojo.declare("Spring.ValidateAllDecoration", [Spring.AbstractValidateAllDecoration, Spring.DefaultEquals], {
constructor : function(config) {
this.originalHandler = null;
this.connection = null;
@@ -90,7 +105,7 @@ dojo.declare("Spring.ValidateAllDecoration", Spring.AbstractValidateAllDecoratio
}
});
dojo.declare("Spring.AjaxEventDecoration", Spring.AbstractAjaxEventDecoration, {
dojo.declare("Spring.AjaxEventDecoration", [Spring.AbstractAjaxEventDecoration, Spring.DefaultEquals], {
constructor : function(config){
this.connection = null;
dojo.mixin(this, config);
@@ -110,7 +125,7 @@ dojo.declare("Spring.AjaxEventDecoration", Spring.AbstractAjaxEventDecoration, {
this.sourceId = this.elementId;
}
if(this.formId == ""){
Spring.remoting.getLinkedResource(this.sourceId, this.params, false);
Spring.remoting.getLinkedResource(this.sourceId, this.params, this.popup);
} else {
Spring.remoting.submitForm(this.sourceId, this.formId, this.params);
}
@@ -130,8 +145,11 @@ dojo.declare("Spring.RemotingHandler", Spring.AbstractRemotingHandler, {
var sourceComponent = dojo.byId(sourceId);
if (sourceComponent != null){
if(sourceComponent.value != undefined) {
content[sourceId] = sourceComponent.value;
if(sourceComponent.value != undefined && sourceComponent.type && ("button,submit,reset").indexOf(sourceComponent.type) < 0) {
content[sourceId] = sourceComponent.value;
}
else if(sourceComponent.name != undefined) {
content[sourceComponent.name] = sourceComponent.name;
} else {
content[sourceId] = sourceId;
}
@@ -198,7 +216,19 @@ dojo.declare("Spring.RemotingHandler", Spring.AbstractRemotingHandler, {
return response;
}
else {
window.location = window.location.protocol + "//" + window.location.host + redirectURL;
if (redirectURL.indexOf("/") >= 0) {
window.location = window.location.protocol + "//" + window.location.host + redirectURL;
} else {
var location = window.location.protocol + "//" + window.location.host + window.location.pathname;
var appendIndex = location.lastIndexOf("/");
location = location.substr(0,appendIndex+1) + redirectURL;
if (location == window.location) {
Spring.remoting.getResource(location, ioArgs.args.content, false);
}
else {
window.location = location;
}
}
return response;
}
}
@@ -240,7 +270,11 @@ dojo.declare("Spring.RemotingHandler", Spring.AbstractRemotingHandler, {
newNodes.forEach(function(item){
if (item.id != null && item.id != "") {
var target = dojo.byId(item.id);
target.parentNode.replaceChild(item, target);
if (!target) {
console.error("An existing DOM elment with id '" + item.id + "' could not be found for replacement.");
} else {
target.parentNode.replaceChild(item, target);
}
}
});
}
@@ -276,7 +310,7 @@ dojo.declare("Spring.RemotingHandler", Spring.AbstractRemotingHandler, {
}
});
dojo.declare("Spring.CommandLinkDecoration", Spring.AbstractCommandLinkDecoration, {
dojo.declare("Spring.CommandLinkDecoration", [Spring.AbstractCommandLinkDecoration, Spring.DefaultEquals], {
constructor : function(config){
dojo.mixin(this, config);
},

View File

@@ -13,4 +13,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Spring={};Spring.decorations=[];Spring.decorations.applied=false;Spring.initialize=function(){Spring.applyDecorations();Spring.remoting=new Spring.RemotingHandler();};Spring.addDecoration=function(_1){Spring.decorations.push(_1);if(Spring.decorations.applied){_1.apply();}};Spring.applyDecorations=function(){if(!Spring.decorations.applied){for(var x=0;x<Spring.decorations.length;x++){Spring.decorations[x].apply();}Spring.decorations.applied=true;}};Spring.validateAll=function(){var _3=true;for(x in Spring.decorations){if(Spring.decorations[x].widget&&!Spring.decorations[x].validate()){_3=false;}}return _3;};Spring.validateRequired=function(){var _4=true;for(x in Spring.decorations){if(Spring.decorations[x].decorator&&Spring.decorations[x].isRequired()&&!Spring.decorations[x].validate()){_4=false;}}return _4;};Spring.AbstractElementDecoration=function(){};Spring.AbstractElementDecoration.prototype={elementId:"",widgetType:"",widgetModule:"",widget:null,widgetAttrs:{},apply:function(){},validate:function(){},isRequired:function(){}};Spring.AbstractValidateAllDecoration=function(){};Spring.AbstractValidateAllDecoration.prototype={event:"",elementId:"",apply:function(){},cleanup:function(){},handleEvent:function(_5){}};Spring.AbstractCommandLinkDecoration=function(){};Spring.AbstractCommandLinkDecoration.prototype={elementId:"",linkHtml:"",apply:function(){},submitFormFromLink:function(_6,_7,_8){}};Spring.AbstractAjaxEventDecoration=function(){};Spring.AbstractAjaxEventDecoration.prototype={event:"",elementId:"",sourceId:"",formId:"",params:{},apply:function(){},cleanup:function(){},submit:function(_9){}};Spring.AbstractRemotingHandler=function(){};Spring.AbstractRemotingHandler.prototype={submitForm:function(_a,_b,_c){},getLinkedResource:function(_d,_e,_f){},getResource:function(_10,_11,_12){},handleResponse:function(){},handleError:function(){}};
Spring={};Spring.decorations={};Spring.decorations.applied=false;Spring.initialize=function(){Spring.applyDecorations();Spring.remoting=new Spring.RemotingHandler();};Spring.addDecoration=function(_1){if(!Spring.decorations[_1.elementId]){Spring.decorations[_1.elementId]=[];Spring.decorations[_1.elementId].push(_1);}else{var _2=false;for(var i=0;i<Spring.decorations[_1.elementId].length;i++){var _4=Spring.decorations[_1.elementId][i];if(_4.equals(_1)){if(_4.cleanup!=undefined){_4.cleanup();}Spring.decorations[_1.elementId][i]=_1;_2=true;break;}}if(!_2){Spring.decorations[_1.elementId].push(_1);}}if(Spring.decorations.applied){_1.apply();}};Spring.applyDecorations=function(){if(!Spring.decorations.applied){for(var _5 in Spring.decorations){for(var x=0;x<Spring.decorations[_5].length;x++){Spring.decorations[_5][x].apply();}}Spring.decorations.applied=true;}};Spring.validateAll=function(){var _7=true;for(var _8 in Spring.decorations){for(var x=0;x<Spring.decorations[_8].length;x++){if(Spring.decorations[_8][x].widget&&!Spring.decorations[_8][x].validate()){_7=false;}}}return _7;};Spring.validateRequired=function(){var _a=true;for(var _b in Spring.decorations){for(var x=0;x<Spring.decorations[_b].length;x++){if(Spring.decorations[_b][x].widget&&Spring.decorations[_b][x].isRequired()&&!Spring.decorations[_b][x].validate()){_a=false;}}}return _a;};Spring.AbstractElementDecoration=function(){};Spring.AbstractElementDecoration.prototype={elementId:"",widgetType:"",widgetModule:"",widget:null,widgetAttrs:{},apply:function(){},validate:function(){},isRequired:function(){},equals:function(_d){}};Spring.AbstractValidateAllDecoration=function(){};Spring.AbstractValidateAllDecoration.prototype={event:"",elementId:"",apply:function(){},cleanup:function(){},handleEvent:function(_e){},equals:function(_f){}};Spring.AbstractCommandLinkDecoration=function(){};Spring.AbstractCommandLinkDecoration.prototype={elementId:"",linkHtml:"",apply:function(){},submitFormFromLink:function(_10,_11,_12){},equals:function(_13){}};Spring.AbstractAjaxEventDecoration=function(){};Spring.AbstractAjaxEventDecoration.prototype={event:"",elementId:"",sourceId:"",formId:"",popup:false,params:{},apply:function(){},cleanup:function(){},submit:function(_14){},equals:function(_15){}};Spring.AbstractRemotingHandler=function(){};Spring.AbstractRemotingHandler.prototype={submitForm:function(_16,_17,_18){},getLinkedResource:function(_19,_1a,_1b){},getResource:function(_1c,_1d,_1e){},handleResponse:function(){},handleError:function(){}};

View File

@@ -15,7 +15,7 @@
*/
Spring = {};
Spring.decorations = [];
Spring.decorations = {};
Spring.decorations.applied = false;
@@ -25,16 +25,40 @@ Spring.initialize = function(){
};
Spring.addDecoration = function(/*Object*/decoration){
Spring.decorations.push(decoration);
//Spring.decorations.push(decoration);
if (!Spring.decorations[decoration.elementId]) {
Spring.decorations[decoration.elementId] = [];
Spring.decorations[decoration.elementId].push(decoration);
} else {
var replaced = false;
for(var i = 0; i<Spring.decorations[decoration.elementId].length; i++) {
var existingDecoration = Spring.decorations[decoration.elementId][i];
if(existingDecoration.equals(decoration)) {
if (existingDecoration.cleanup != undefined) {
existingDecoration.cleanup();
}
Spring.decorations[decoration.elementId][i] = decoration;
replaced=true;
break;
}
}
if (!replaced) {
Spring.decorations[decoration.elementId].push(decoration);
}
}
if(Spring.decorations.applied) {
decoration.apply();
}
};
Spring.applyDecorations = function(){
if (!Spring.decorations.applied) {
for (var x=0; x<Spring.decorations.length; x++) {
Spring.decorations[x].apply();
if (!Spring.decorations.applied) {
for (var elementId in Spring.decorations) {
for (var x = 0; x < Spring.decorations[elementId].length; x++) {
Spring.decorations[elementId][x].apply();
}
}
Spring.decorations.applied = true;
}
@@ -42,10 +66,11 @@ Spring.applyDecorations = function(){
Spring.validateAll = function(){
var valid = true;
for(x in Spring.decorations) {
if (Spring.decorations[x].widget &&
!Spring.decorations[x].validate()) {
valid = false;
for (var elementId in Spring.decorations) {
for (var x = 0; x < Spring.decorations[elementId].length; x++) {
if (Spring.decorations[elementId][x].widget && !Spring.decorations[elementId][x].validate()) {
valid = false;
}
}
}
return valid;
@@ -53,11 +78,13 @@ Spring.validateAll = function(){
Spring.validateRequired = function(){
var valid = true;
for(x in Spring.decorations) {
if(Spring.decorations[x].decorator &&
Spring.decorations[x].isRequired() &&
!Spring.decorations[x].validate())
valid = false;
for (var elementId in Spring.decorations) {
for (var x = 0; x < Spring.decorations[elementId].length; x++) {
if (Spring.decorations[elementId][x].widget && Spring.decorations[elementId][x].isRequired() &&
!Spring.decorations[elementId][x].validate()) {
valid = false;
}
}
}
return valid;
};
@@ -76,7 +103,9 @@ Spring.AbstractElementDecoration.prototype = {
validate : function(){},
isRequired : function(){}
isRequired : function(){},
equals : function(/*Object*/other){}
};
Spring.AbstractValidateAllDecoration = function(){};
@@ -90,7 +119,9 @@ Spring.AbstractValidateAllDecoration.prototype = {
cleanup : function(){},
handleEvent : function(event){}
handleEvent : function(event){},
equals : function(/*Object*/other){}
};
Spring.AbstractCommandLinkDecoration = function(){};
@@ -102,7 +133,9 @@ Spring.AbstractCommandLinkDecoration.prototype = {
apply : function(){},
submitFormFromLink : function(/*String*/ formId, /*String*/ sourceId, /*Array of name,value params*/ params){}
submitFormFromLink : function(/*String*/ formId, /*String*/ sourceId, /*Array of name,value params*/ params){},
equals : function(/*Object*/other){}
};
Spring.AbstractAjaxEventDecoration = function(){};
@@ -113,13 +146,16 @@ Spring.AbstractAjaxEventDecoration.prototype = {
elementId : "",
sourceId : "",
formId : "",
popup : false,
params : {},
apply : function(){},
cleanup : function(){},
submit : function(event){}
submit : function(event){},
equals : function(/*Object*/other){}
};
Spring.AbstractRemotingHandler = function(){};

View File

@@ -9,7 +9,9 @@
<on-render>
<evaluate expression="bookingService.findBookings(currentUser.name)" result="viewScope.bookings" result-type="dataModel" />
</on-render>
<transition on="search" to="reviewHotels" />
<transition on="search" to="reviewHotels">
<evaluate expression="searchCriteria.resetPage()"/>
</transition>
<transition on="cancelBooking">
<evaluate expression="bookingService.cancelBooking(bookings.selectedRow)" />
<render fragments="bookingsFragment"/>

View File

@@ -37,12 +37,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

@@ -45,8 +45,8 @@
</bean>
<!-- Resolves views by delegating to the Tiles layout system; a view name to resolve is treated as the name of a tiles definition -->
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.js.ajax.tiles2.AjaxTilesView"/>
<bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
<property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/>
</bean>
<!-- Enables annotated POJO @Controllers -->

View File

@@ -0,0 +1,160 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<form:form modelAttribute="booking">
<fieldset>
<div class="field">
<div class="label">Name:</div>
<div class="output">${booking.hotel.name}</div>
</div>
<div class="field">
<div class="label">Address:</div>
<div class="output">${booking.hotel.address}</div>
</div>
<div class="field">
<div class="label">City, State:</div>
<div class="output">${booking.hotel.city}, ${booking.hotel.state}</div>
</div>
<div class="field">
<div class="label">Zip:</div>
<div class="output">${booking.hotel.zip}</div>
</div>
<div class="field">
<div class="label">Country:</div>
<div class="output">${booking.hotel.country}</div>
</div>
<div class="field">
<div class="label">Nightly rate:</div>
<div class="output">
<spring:bind path="booking.hotel.price">${status.value}</spring:bind>
</div>
</div>
<div class="field">
<div class="label">
<label for="checkinDate">Check In Date:</label>
</div>
<div class="input">
<form:input path="checkinDate"/>
<script type="text/javascript">
Spring.addDecoration(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 }}));
</script>
</div>
</div>
<div class="field">
<div class="label">
<label for="checkoutDate">Check Out Date:</label>
</div>
<div class="input">
<form:input path="checkoutDate"/>
<script type="text/javascript">
Spring.addDecoration(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 }}));
</script>
</div>
</div>
<div class="field">
<div class="label">
<label for="beds">Room Preference:</label>
</div>
<div class="input">
<form:select id="beds" path="beds">
<form:option label="One king-size bed" value="1"/>
<form:option label="Two double beds" value="2"/>
<form:option label="Three beds" value="3"/>
</form:select>
</div>
</div>
<div class="field">
<div class="label">
Smoking Preference:
</div>
<div id="radio" class="input">
<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">
Spring.addDecoration(new Spring.ElementDecoration({
elementId : 'smoking',
widgetType : "dijit.form.RadioButton",
widgetModule : "dijit.form.CheckBox" }));
Spring.addDecoration(new Spring.ElementDecoration({
elementId : 'non-smoking',
widgetType : "dijit.form.RadioButton",
widgetModule : "dijit.form.CheckBox" }));
</script>
</div>
</div>
<div class="field">
<div class="label">
<label for="creditCard">Credit Card #:</label>
</div>
<div class="input">
<form:input path="creditCard"/>
<script type="text/javascript">
Spring.addDecoration(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}" }}));
</script>
</div>
</div>
<div class="field">
<div class="label">
<label for="creditCardName">Credit Card Name:</label>
</div>
<div class="input">
<form:input path="creditCardName" maxlength="40"/>
<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({
elementId : "creditCardName",
widgetType : "dijit.form.ValidationTextBox",
widgetAttrs : { required : true }}));
</script>
</div>
</div>
<div class="field">
<div class="label">
<label for="creditCardExpiryMonth">Expiration Date:</label>
</div>
<div class="input">
<form:select id="creditCardExpiryMonth" path="creditCardExpiryMonth">
<form:option label="Jan" value="1"/>
<form:option label="Feb" value="2"/>
<form:option label="Mar" value="3"/>
<form:option label="Apr" value="4"/>
<form:option label="May" value="5"/>
<form:option label="Jun" value="6"/>
<form:option label="Jul" value="7"/>
<form:option label="Aug" value="8"/>
<form:option label="Sep" value="9"/>
<form:option label="Oct" value="10"/>
<form:option label="Nov" value="11"/>
<form:option label="Dec" value="12"/>
</form:select>
<form:select path="creditCardExpiryYear">
<form:option label="2008" value="1"/>
<form:option label="2009" value="2"/>
<form:option label="2010" value="3"/>
<form:option label="2011" value="4"/>
<form:option label="2012" value="5"/>
</form:select>
</div>
</div>
<div class="buttonGroup">
<input type="submit" id="proceed" name="_eventId_proceed" value="Proceed"
onclick="Spring.remoting.submitForm('proceed', 'booking', {fragments:'messages,bookingForm'}); return false;"/>&#160;
<script type="text/javascript">
Spring.addDecoration(new Spring.ValidateAllDecoration({elementId:'proceed', event:'onclick'}));
</script>
<input type="submit" name="_eventId_cancel" value="Cancel"/>&#160;
</div>
</fieldset>
</form:form>

View File

@@ -1,165 +1,13 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ 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">
<h2>Book Hotel</h2>
</div>
<div class="section">
<form:form id="booking" modelAttribute="booking">
<form:errors path="*" cssClass="errors" />
<fieldset>
<div class="field">
<div class="label">Name:</div>
<div class="output">${booking.hotel.name}</div>
</div>
<div class="field">
<div class="label">Address:</div>
<div class="output">${booking.hotel.address}</div>
</div>
<div class="field">
<div class="label">City, State:</div>
<div class="output">${booking.hotel.city}, ${booking.hotel.state}</div>
</div>
<div class="field">
<div class="label">Zip:</div>
<div class="output">${booking.hotel.zip}</div>
</div>
<div class="field">
<div class="label">Country:</div>
<div class="output">${booking.hotel.country}</div>
</div>
<div class="field">
<div class="label">Nightly rate:</div>
<div class="output">
<spring:bind path="booking.hotel.price">${status.value}</spring:bind>
</div>
</div>
<div class="field">
<div class="label">
<label for="checkinDate">Check In Date:</label>
</div>
<div class="input">
<form:input path="checkinDate"/>
<script type="text/javascript">
Spring.addDecoration(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 }}));
</script>
</div>
</div>
<div class="field">
<div class="label">
<label for="checkoutDate">Check Out Date:</label>
</div>
<div class="input">
<form:input path="checkoutDate"/>
<script type="text/javascript">
Spring.addDecoration(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 }}));
</script>
</div>
</div>
<div class="field">
<div class="label">
<label for="beds">Room Preference:</label>
</div>
<div class="input">
<form:select id="beds" path="beds">
<form:option label="One king-size bed" value="1"/>
<form:option label="Two double beds" value="2"/>
<form:option label="Three beds" value="3"/>
</form:select>
</div>
</div>
<div class="field">
<div class="label">
Smoking Preference:
</div>
<div id="radio" class="input">
<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">
Spring.addDecoration(new Spring.ElementDecoration({
elementId : 'smoking',
widgetType : "dijit.form.RadioButton",
widgetModule : "dijit.form.CheckBox" }));
Spring.addDecoration(new Spring.ElementDecoration({
elementId : 'non-smoking',
widgetType : "dijit.form.RadioButton",
widgetModule : "dijit.form.CheckBox" }));
</script>
</div>
</div>
<div class="field">
<div class="label">
<label for="creditCard">Credit Card #:</label>
</div>
<div class="input">
<form:input path="creditCard"/>
<script type="text/javascript">
Spring.addDecoration(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}" }}));
</script>
</div>
</div>
<div class="field">
<div class="label">
<label for="creditCardName">Credit Card Name:</label>
</div>
<div class="input">
<form:input path="creditCardName" maxlength="40"/>
<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({
elementId : "creditCardName",
widgetType : "dijit.form.ValidationTextBox",
widgetAttrs : { required : true }}));
</script>
</div>
</div>
<div class="field">
<div class="label">
<label for="creditCardExpiryMonth">Expiration Date:</label>
</div>
<div class="input">
<form:select id="creditCardExpiryMonth" path="creditCardExpiryMonth">
<form:option label="Jan" value="1"/>
<form:option label="Feb" value="2"/>
<form:option label="Mar" value="3"/>
<form:option label="Apr" value="4"/>
<form:option label="May" value="5"/>
<form:option label="Jun" value="6"/>
<form:option label="Jul" value="7"/>
<form:option label="Aug" value="8"/>
<form:option label="Sep" value="9"/>
<form:option label="Oct" value="10"/>
<form:option label="Nov" value="11"/>
<form:option label="Dec" value="12"/>
</form:select>
<form:select path="creditCardExpiryYear">
<form:option label="2008" value="1"/>
<form:option label="2009" value="2"/>
<form:option label="2010" value="3"/>
<form:option label="2011" value="4"/>
<form:option label="2012" value="5"/>
</form:select>
</div>
</div>
<div class="buttonGroup">
<input type="submit" id="proceed" name="_eventId_proceed" value="Proceed"/>&#160;
<input type="submit" name="_eventId_cancel" value="Cancel"/>&#160;
<script type="text/javascript">
Spring.addDecoration(new Spring.ValidateAllDecoration({event : 'onclick', elementId : 'proceed'}));
</script>
</div>
</fieldset>
</form:form>
<div id="bookingDetails" class="section">
<tiles:insertAttribute name="messages"/>
<tiles:insertAttribute name="bookingForm"/>
</div>

View File

@@ -0,0 +1,4 @@
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<div id="messages">
<form:errors path="booking.*" cssClass="errors" />
</div>

View File

@@ -6,7 +6,11 @@
<tiles-definitions>
<definition name="enterBookingDetails" extends="standardLayout">
<put-attribute name="body" value="/WEB-INF/hotels/booking/enterBookingDetails.jsp" />
<put-attribute name="body" value="details.body" />
</definition>
<definition name="details.body" template="/WEB-INF/hotels/booking/enterBookingDetails.jsp">
<put-attribute name="messages" value="/WEB-INF/hotels/booking/messages.jsp" />
<put-attribute name="bookingForm" value="/WEB-INF/hotels/booking/bookingForm.jsp" />
</definition>
<definition name="reviewBooking" extends="standardLayout">

View File

@@ -0,0 +1,53 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<div id="bookings" "class="section">
<security:authorize ifAllGranted="ROLE_USER">
<h2>Current Hotel Bookings</h2>
<c:if test="${empty bookings}">
<tr>
<td colspan="7">No bookings found</td>
</tr>
</c:if>
<c:if test="${!empty bookings}">
<table class="summary">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th>City, State</th>
<th>Check in Date</th>
<th>Check out Date</th>
<th>Confirmation Number</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<c:forEach var="booking" items="${bookings}">
<tr>
<td>${booking.hotel.name}</td>
<td>${booking.hotel.address}</td>
<td>${booking.hotel.city}, ${booking.hotel.state}</td>
<td>${booking.checkinDate}</td>
<td>${booking.checkoutDate}</td>
<td>${booking.id}</td>
<td>
<a id="cancelLink_${booking.id}" href="deleteBooking?id=${booking.id}">Cancel</a>
<script type="text/javascript">
Spring.addDecoration(new Spring.AjaxEventDecoration({
elementId:"cancelLink_${booking.id}",
event:"onclick",
params: {fragments:"bookingsTable"}
}));
</script>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</c:if>
</security:authorize>
</div>

View File

@@ -1,56 +0,0 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<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="buttonGroup">
<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>
<c:if test="${not empty hotels && fn:length(hotels) == searchCriteria.pageSize}">
<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>
</c:if>
</div>

View File

@@ -0,0 +1,41 @@
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<form:form modelAttribute="searchCriteria" action="search" method="get">
<div class="section">
<span class="errors">
<form:errors path="*"/>
</span>
<h2>Search Hotels</h2>
<fieldset>
<div class="field">
<div class="label">
<label for="searchString">Search String:</label>
</div>
<div class="input">
<form:input id="searchString" path="searchString"/>
<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({
elementId : "searchString",
widgetType : "dijit.form.ValidationTextBox",
widgetAttrs : { promptMessage : "Search hotels by name, address, city, or zip." }}));
</script>
</div>
</div>
<div class="field">
<div class="label">
<label for="pageSize">Maximum results:</label>
</div>
<div class="input">
<form:select id="pageSize" path="pageSize">
<form:option label="5" value="5"/>
<form:option label="10" value="10"/>
<form:option label="20" value="20"/>
</form:select>
</div>
</div>
<div class="buttonGroup">
<input type="submit" value="Find Hotels" />
</div>
</fieldset>
</div>
</form:form>

View File

@@ -1,87 +1,5 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<form:form modelAttribute="searchCriteria" action="search" method="get">
<div class="section">
<span class="errors">
<form:errors path="*"/>
</span>
<h2>Search Hotels</h2>
<fieldset>
<div class="field">
<div class="label">
<label for="searchString">Search String:</label>
</div>
<div class="input">
<form:input id="searchString" path="searchString"/>
<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({
elementId : "searchString",
widgetType : "dijit.form.ValidationTextBox",
widgetAttrs : { promptMessage : "Search hotels by name, address, city, or zip." }}));
</script>
</div>
</div>
<div class="field">
<div class="label">
<label for="pageSize">Maximum results:</label>
</div>
<div class="input">
<form:select id="pageSize" path="pageSize">
<form:option label="5" value="5"/>
<form:option label="10" value="10"/>
<form:option label="20" value="20"/>
</form:select>
</div>
</div>
<div class="buttonGroup">
<input type="submit" value="Find Hotels" />
</div>
</fieldset>
</div>
</form:form>
<tiles:insertAttribute name="hotelSearchForm" />
<security:authorize ifAllGranted="ROLE_USER">
<div class="section">
<h2>Current Hotel Bookings</h2>
<c:if test="${empty bookings}">
<tr>
<td colspan="7">No bookings found</td>
</tr>
</c:if>
<c:if test="${!empty bookings}">
<table class="summary">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th>City, State</th>
<th>Check in Date</th>
<th>Check out Date</th>
<th>Confirmation Number</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<c:forEach var="booking" items="${bookings}">
<tr>
<td>${booking.hotel.name}</td>
<td>${booking.hotel.address}</td>
<td>${booking.hotel.city}, ${booking.hotel.state}</td>
<td>${booking.checkinDate}</td>
<td>${booking.checkoutDate}</td>
<td>${booking.id}</td>
<td>
<a href="deleteBooking?id=${booking.id}">Cancel</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</c:if>
</div>
</security:authorize>
<tiles:insertAttribute name="bookingsTable" />

View File

@@ -1,8 +1,72 @@
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<div id="heading" class="section">
<h2>Hotel Results</h2>
</div>
<tiles:insertAttribute name="hotelResults" />
<p>
<a id="changeSearchLink" href="index?searchString=${searchCriteria.searchString}&pageSize=${searchCriteria.pageSize}">Change Search</a>
<script type="text/javascript">
Spring.addDecoration(new Spring.AjaxEventDecoration({
elementId: "changeSearchLink",
event: "onclick",
popup: true,
params: {fragments: "hotelSearchForm"}
}));
</script>
</p>
<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="buttonGroup">
<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 type="text/javascript">
Spring.addDecoration(new Spring.AjaxEventDecoration({
elementId: "prevResultsLink",
event: "onclick",
params: {fragments: "body"}
}));
</script>
</c:if>
<c:if test="${not empty hotels && fn:length(hotels) == searchCriteria.pageSize}">
<a id="moreResultsLink" href="search?searchString=${searchCriteria.searchString}&pageSize=${searchCriteria.pageSize}&page=${searchCriteria.page + 1}">More Results</a>
<script type="text/javascript">
Spring.addDecoration(new Spring.AjaxEventDecoration({
elementId: "moreResultsLink",
event: "onclick",
params: {fragments: "body"}
}));
</script>
</c:if>
</div>
</c:if>
</div>

View File

@@ -6,17 +6,17 @@
<tiles-definitions>
<definition name="hotels/index" extends="standardLayout">
<put-attribute name="body" value="/WEB-INF/hotels/index.jsp" />
<put-attribute name="body" value="index.body" />
</definition>
<definition name="index.body" template="/WEB-INF/hotels/index.jsp">
<put-attribute name="hotelSearchForm" value="/WEB-INF/hotels/hotelSearchForm.jsp" />
<put-attribute name="bookingsTable" value="/WEB-INF/hotels/bookingsTable.jsp" />
</definition>
<definition name="hotels/search" extends="standardLayout">
<put-attribute name="body" value="search.body" />
<put-attribute name="body" value="/WEB-INF/hotels/search.jsp" />
</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="standardLayout">
<put-attribute name="body" value="/WEB-INF/hotels/show.jsp" />
</definition>

View File

@@ -7,6 +7,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Spring Travel: Spring MVC and Web Flow Reference Application</title>
<link type="text/css" rel="stylesheet" href="<c:url value="/resources/dijit/themes/tundra/tundra.css" />" />
<style type="text/css" media="screen">
@import url("<c:url value="/resources/css-framework/css/tools.css" />");
@import url("<c:url value="/resources/css-framework/css/typo.css" />");
@@ -15,10 +16,9 @@
@import url("<c:url value="/resources/css-framework/css/layout.css" />");
@import url("<c:url value="/resources/styles/booking.css" />");
</style>
<script type="text/javascript" src="<c:url value="/resources/spring/Spring.js" />"></script>
<script type="text/javascript" src="<c:url value="/resources/dojo/dojo.js" />"></script>
<script type="text/javascript" src="<c:url value="/resources/spring/Spring.js" />"></script>
<script type="text/javascript" src="<c:url value="/resources/spring/Spring-Dojo.js" />"></script>
<link type="text/css" rel="stylesheet" href="<c:url value="/resources/dijit/themes/tundra/tundra.css" />" />
</head>
<body class="tundra spring">
<div id="page">

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2004-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.webflow.mvc.view;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.js.ajax.tiles2.AjaxTilesView;
import org.springframework.webflow.execution.RequestContext;
import org.springframework.webflow.execution.RequestContextHolder;
import org.springframework.webflow.execution.View;
public class FlowAjaxTilesView extends AjaxTilesView {
protected String[] getRenderFragments(Map model, HttpServletRequest request, HttpServletResponse response) {
RequestContext context = RequestContextHolder.getRequestContext();
if (context == null) {
return super.getRenderFragments(model, request, response);
} else {
String[] fragments = (String[]) context.getFlashScope().get(View.RENDER_FRAGMENTS_ATTRIBUTE);
if (fragments == null) {
return super.getRenderFragments(model, request, response);
}
return fragments;
}
}
}