From 7661cb76751219b94192a7fd94ffa11d5790175b Mon Sep 17 00:00:00 2001 From: Jeremy Grelle Date: Mon, 14 Jan 2008 20:45:29 +0000 Subject: [PATCH] SWF-437 - The form action URL will now only be updated for forms that are children of the JSF View that is rendered during the course of the AJAX request. --- .../META-INF/spring-faces/SpringFaces-Dojo.js | 8 ++--- .../faces/ui/AjaxViewRoot.java | 31 ++++++++++++++----- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/spring-faces/src/main/java/META-INF/spring-faces/SpringFaces-Dojo.js b/spring-faces/src/main/java/META-INF/spring-faces/SpringFaces-Dojo.js index 8c2a6dd9..b76da745 100644 --- a/spring-faces/src/main/java/META-INF/spring-faces/SpringFaces-Dojo.js +++ b/spring-faces/src/main/java/META-INF/spring-faces/SpringFaces-Dojo.js @@ -90,6 +90,8 @@ SpringFaces.DojoAjaxHandler.prototype = { handleAs: "text", + headers: {"Accept" : "text/html;type=ajax"}, + // The LOAD function will be called on a successful response. load: this.handleResponse, @@ -131,11 +133,7 @@ SpringFaces.DojoAjaxHandler.prototype = { //Insert the new DOM nodes and update the Form's action URL newNodes.forEach(function(item) { - if (item.id == 'flowExecutionUrl'){ - dojo.query("form").forEach(function (formNode) { - formNode.action = item.firstChild.nodeValue; - }); - } else if (item.id != null && item.id != "") { + if (item.id != null && item.id != "") { var target = dojo.byId(item.id); target.parentNode.replaceChild(item, target); } 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 6c2bf510..0c92dbae 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 @@ -52,7 +52,7 @@ public class AjaxViewRoot extends DelegatingViewRoot { Iterator i = target.getChildren().iterator(); while (i.hasNext()) { UIComponent child = (UIComponent) i.next(); - child.setParent(this); + child.setParent(target); } } @@ -82,7 +82,7 @@ public class AjaxViewRoot extends DelegatingViewRoot { context.setViewRoot(getOriginalViewRoot()); if (!getAttributes().containsKey(FORM_RENDERED)) { context.getApplication().getViewHandler().writeState(context); - writeFormURL(context); + updateFormAction(context); } broadCastEvents(context, PhaseId.APPLY_REQUEST_VALUES); @@ -92,18 +92,35 @@ public class AjaxViewRoot extends DelegatingViewRoot { * * @param context */ - private void writeFormURL(FacesContext context) { + private void updateFormAction(FacesContext context) { ResponseWriter writer = context.getResponseWriter(); try { - writer.startElement("div", null); - writer.writeAttribute("id", "flowExecutionUrl", null); - writer.writeText(context.getApplication().getViewHandler().getActionURL(context, getViewId()), null); - writer.endElement("div"); + 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 < renderIds.length; i++) { + UIComponent component = context.getViewRoot().findComponent(renderIds[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)