diff --git a/spring-faces/src/main/java/org/springframework/faces/ui/AjaxViewRoot.java b/spring-faces/src/main/java/org/springframework/faces/ui/AjaxViewRoot.java index 148c7936..28b2fcac 100644 --- a/spring-faces/src/main/java/org/springframework/faces/ui/AjaxViewRoot.java +++ b/spring-faces/src/main/java/org/springframework/faces/ui/AjaxViewRoot.java @@ -55,19 +55,13 @@ public class AjaxViewRoot extends DelegatingViewRoot { setId(original.getId() + "_ajax"); } - private void swapChildren(UIViewRoot source, UIViewRoot target) { - target.getChildren().addAll(source.getChildren()); - Iterator i = target.getChildren().iterator(); - while (i.hasNext()) { - UIComponent child = (UIComponent) i.next(); - child.setParent(target); - } + // implementing view root + + public void queueEvent(FacesEvent event) { + Assert.notNull(event, "Cannot queue a null event."); + events.add(event); } - /* - * (non-Javadoc) - * @see org.springframework.faces.webflow.DelegatingViewRoot#encodeAll(javax.faces.context.FacesContext) - */ public void encodeAll(FacesContext context) throws IOException { for (int i = 0; i < getRenderIds().length; i++) { String renderId = getRenderIds()[i]; @@ -91,55 +85,9 @@ public class AjaxViewRoot extends DelegatingViewRoot { context.getApplication().getViewHandler().writeState(context); updateFormAction(context); } - broadCastEvents(context, PhaseId.APPLY_REQUEST_VALUES); } - /** - * - * @param context - */ - private void updateFormAction(FacesContext context) { - ResponseWriter writer = context.getResponseWriter(); - try { - String formId = findContainingFormId(context); - if (StringUtils.hasLength(formId)) { - String script = "dojo.byId('" + formId + "').action = " - + context.getApplication().getViewHandler().getActionURL(context, getViewId()); - writer.startElement("script", null); - writer.writeText(script, null); - writer.endElement("script"); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - private String findContainingFormId(FacesContext context) { - for (int i = 0; i < getRenderIds().length; i++) { - UIComponent component = context.getViewRoot().findComponent(getRenderIds()[i]); - while (!(component instanceof UIViewRoot)) { - component = component.getParent(); - if (component instanceof UIForm) { - return component.getClientId(context); - } - } - } - return null; - } - - /* - * (non-Javadoc) - * @see org.springframework.faces.webflow.DelegatingViewRoot#processApplication(javax.faces.context.FacesContext) - */ - public void processApplication(FacesContext context) { - broadCastEvents(context, PhaseId.INVOKE_APPLICATION); - } - - /* - * (non-Javadoc) - * @see org.springframework.faces.webflow.DelegatingViewRoot#processDecodes(javax.faces.context.FacesContext) - */ public void processDecodes(FacesContext context) { for (int i = 0; i < getProcessIds().length; i++) { String processId = getProcessIds()[i]; @@ -153,30 +101,6 @@ public class AjaxViewRoot extends DelegatingViewRoot { broadCastEvents(context, PhaseId.APPLY_REQUEST_VALUES); } - private String[] removeNestedChildren(FacesContext context, String[] ids) { - List idList = Arrays.asList(ids); - final List trimmedIds = new ArrayList(idList); - - for (final ListIterator i = trimmedIds.listIterator(); i.hasNext();) { - String id = (String) i.next(); - invokeOnComponent(context, id, new ContextCallback() { - public void invokeContextCallback(FacesContext context, UIComponent component) { - while (!(component.getParent() instanceof UIViewRoot)) { - component = component.getParent(); - if (trimmedIds.contains(component.getClientId(context))) { - i.remove(); - } - } - } - }); - } - return (String[]) trimmedIds.toArray(new String[trimmedIds.size()]); - } - - /* - * (non-Javadoc) - * @see org.springframework.faces.webflow.DelegatingViewRoot#processUpdates(javax.faces.context.FacesContext) - */ public void processUpdates(FacesContext context) { for (int i = 0; i < getProcessIds().length; i++) { String processId = getProcessIds()[i]; @@ -190,10 +114,6 @@ public class AjaxViewRoot extends DelegatingViewRoot { broadCastEvents(context, PhaseId.UPDATE_MODEL_VALUES); } - /* - * (non-Javadoc) - * @see org.springframework.faces.webflow.DelegatingViewRoot#processValidators(javax.faces.context.FacesContext) - */ public void processValidators(FacesContext context) { for (int i = 0; i < getProcessIds().length; i++) { String processId = getProcessIds()[i]; @@ -207,47 +127,11 @@ public class AjaxViewRoot extends DelegatingViewRoot { broadCastEvents(context, PhaseId.PROCESS_VALIDATIONS); } - /* - * (non-Javadoc) - * @see org.springframework.faces.webflow.DelegatingViewRoot#queueEvent(javax.faces.event.FacesEvent) - */ - public void queueEvent(FacesEvent event) { - Assert.notNull(event, "Cannot queue a null event."); - events.add(event); + public void processApplication(FacesContext context) { + broadCastEvents(context, PhaseId.INVOKE_APPLICATION); } - private void broadCastEvents(FacesContext context, PhaseId phaseId) { - - List processedEvents = new ArrayList(); - - if (events.size() == 0) - return; - - boolean abort = false; - - int phaseIdOrdinal = phaseId.getOrdinal(); - Iterator i = events.iterator(); - while (i.hasNext()) { - FacesEvent event = (FacesEvent) i.next(); - int ordinal = event.getPhaseId().getOrdinal(); - if (ordinal == PhaseId.ANY_PHASE.getOrdinal() || ordinal == phaseIdOrdinal) { - UIComponent source = event.getComponent(); - try { - processedEvents.add(event); - source.broadcast(event); - } catch (AbortProcessingException e) { - abort = true; - break; - } - } - } - - if (abort) { - events.clear(); - } else { - events.removeAll(processedEvents); - } - } + // subclassing hooks protected String[] getProcessIds() { if (processIds == null) { @@ -267,7 +151,6 @@ public class AjaxViewRoot extends DelegatingViewRoot { protected String[] getRenderIds() { if (renderIds == null) { FacesContext context = FacesContext.getCurrentInstance(); - renderIds = (String[]) renderIdsExpr.getValue(context); if (renderIds == null || renderIds.length == 0) { renderIds = getProcessIds(); @@ -278,4 +161,93 @@ public class AjaxViewRoot extends DelegatingViewRoot { return renderIds; } + // internal helpers + + private void swapChildren(UIViewRoot source, UIViewRoot target) { + target.getChildren().addAll(source.getChildren()); + Iterator i = target.getChildren().iterator(); + while (i.hasNext()) { + UIComponent child = (UIComponent) i.next(); + child.setParent(target); + } + } + + private void updateFormAction(FacesContext context) { + ResponseWriter writer = context.getResponseWriter(); + try { + String formId = findContainingFormId(context); + if (StringUtils.hasLength(formId)) { + String script = "dojo.byId('" + formId + "').action = " + + context.getApplication().getViewHandler().getActionURL(context, getViewId()); + writer.startElement("script", null); + writer.writeText(script, null); + writer.endElement("script"); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + private String findContainingFormId(FacesContext context) { + for (int i = 0; i < getRenderIds().length; i++) { + UIComponent component = context.getViewRoot().findComponent(getRenderIds()[i]); + Assert.notNull(component, "Component to be rendered with id '" + getRenderIds()[i] + + "' could not be found."); + while (!(component instanceof UIViewRoot)) { + component = component.getParent(); + if (component instanceof UIForm) { + return component.getClientId(context); + } + } + } + return null; + } + + private String[] removeNestedChildren(FacesContext context, String[] ids) { + List idList = Arrays.asList(ids); + final List trimmedIds = new ArrayList(idList); + for (final ListIterator i = trimmedIds.listIterator(); i.hasNext();) { + String id = (String) i.next(); + invokeOnComponent(context, id, new ContextCallback() { + public void invokeContextCallback(FacesContext context, UIComponent component) { + while (!(component.getParent() instanceof UIViewRoot)) { + component = component.getParent(); + if (trimmedIds.contains(component.getClientId(context))) { + i.remove(); + } + } + } + }); + } + return (String[]) trimmedIds.toArray(new String[trimmedIds.size()]); + } + + private void broadCastEvents(FacesContext context, PhaseId phaseId) { + List processedEvents = new ArrayList(); + if (events.size() == 0) + return; + boolean abort = false; + int phaseIdOrdinal = phaseId.getOrdinal(); + Iterator i = events.iterator(); + while (i.hasNext()) { + FacesEvent event = (FacesEvent) i.next(); + int ordinal = event.getPhaseId().getOrdinal(); + if (ordinal == PhaseId.ANY_PHASE.getOrdinal() || ordinal == phaseIdOrdinal) { + UIComponent source = event.getComponent(); + try { + processedEvents.add(event); + source.broadcast(event); + } catch (AbortProcessingException e) { + abort = true; + break; + } + } + } + if (abort) { + events.clear(); + } else { + events.removeAll(processedEvents); + } + } + } diff --git a/spring-webflow-samples/booking-faces/src/main/java/org/springframework/webflow/samples/booking/SearchCriteria.java b/spring-webflow-samples/booking-faces/src/main/java/org/springframework/webflow/samples/booking/SearchCriteria.java index cb325c9a..0a1b92dc 100755 --- a/spring-webflow-samples/booking-faces/src/main/java/org/springframework/webflow/samples/booking/SearchCriteria.java +++ b/spring-webflow-samples/booking-faces/src/main/java/org/springframework/webflow/samples/booking/SearchCriteria.java @@ -48,21 +48,19 @@ public class SearchCriteria implements Serializable { this.page = page; } - /** - * Increase the current page - */ public void nextPage() { page++; } - /** - * Decrease the current page - */ public void previousPage() { page--; } + public void resetPage() { + page = 0; + } + public String toString() { - return "searchString = '" + searchString + "'"; + return "[Search Criteria searchString = '" + searchString + "'"; } } \ No newline at end of file diff --git a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/booking/enterBookingDetails.xhtml b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/booking/enterBookingDetails.xhtml index ec5907ac..f4caf1ca 100644 --- a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/booking/enterBookingDetails.xhtml +++ b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/booking/enterBookingDetails.xhtml @@ -120,7 +120,7 @@
- +  
diff --git a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/enterSearchCriteria.xhtml b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/enterSearchCriteria.xhtml index 36022081..c4660d97 100644 --- a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/enterSearchCriteria.xhtml +++ b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/enterSearchCriteria.xhtml @@ -38,7 +38,7 @@ -
+

Current Hotel Bookings

@@ -69,7 +69,7 @@ Action - +
diff --git a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/main.xml b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/main.xml index af649979..4c00cff1 100755 --- a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/main.xml +++ b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/main.xml @@ -12,6 +12,7 @@ + @@ -21,11 +22,11 @@ - + - + @@ -49,7 +50,9 @@ - + + + diff --git a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/reviewHotel.xhtml b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/reviewHotel.xhtml index 252dcaa2..725dea2a 100644 --- a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/reviewHotel.xhtml +++ b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/reviewHotel.xhtml @@ -44,19 +44,19 @@
- - -
- -
+ +
- +  
+ + + \ No newline at end of file diff --git a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/reviewHotels.xhtml b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/reviewHotels.xhtml index da44ff71..8f3e52ae 100644 --- a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/reviewHotels.xhtml +++ b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/flows/main/reviewHotels.xhtml @@ -8,7 +8,7 @@ - +

Hotel Results

@@ -42,8 +42,8 @@

- diff --git a/spring-webflow-samples/booking-faces/src/main/webapp/styles/booking.css b/spring-webflow-samples/booking-faces/src/main/webapp/styles/booking.css index 49114ede..e7846284 100644 --- a/spring-webflow-samples/booking-faces/src/main/webapp/styles/booking.css +++ b/spring-webflow-samples/booking-faces/src/main/webapp/styles/booking.css @@ -143,7 +143,7 @@ margin-right: 5px; } - #content .prev { + #content .previous { float: right; }