diff --git a/spring-faces/src/main/java/org/springframework/faces/ui/AjaxEventInterceptorRenderer.java b/spring-faces/src/main/java/org/springframework/faces/ui/AjaxEventInterceptorRenderer.java index 124bf0f5..d28e88c6 100644 --- a/spring-faces/src/main/java/org/springframework/faces/ui/AjaxEventInterceptorRenderer.java +++ b/spring-faces/src/main/java/org/springframework/faces/ui/AjaxEventInterceptorRenderer.java @@ -23,6 +23,7 @@ import javax.faces.context.FacesContext; import javax.faces.context.ResponseWriter; import javax.faces.event.ActionEvent; +import org.springframework.faces.ui.resource.ResourceHelper; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -39,9 +40,9 @@ public class AjaxEventInterceptorRenderer extends DojoDecorationRenderer { Assert.hasText(event, "The event attribute is required on " + component); Assert.isTrue(component.getChildCount() == 1, "Exactly one child component is required for " + component); + ResourceHelper.beginScriptBlock(context); + ResponseWriter writer = context.getResponseWriter(); - writer.startElement("script", component); - writer.writeAttribute("type", "text/javascript", null); String processIds = (String) component.getAttributes().get("processIds"); if (StringUtils.hasText(processIds) && !processIds.contains(component.getClientId(context))) { @@ -60,7 +61,8 @@ public class AjaxEventInterceptorRenderer extends DojoDecorationRenderer { script.append(", ajaxSource : '" + component.getClientId(context) + "'} }));"); writer.writeText(script.toString(), null); - writer.endElement("script"); + + ResourceHelper.endScriptBlock(context); } private String getElementId(FacesContext context, UIComponent component) { 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 2a0f49bc..2cfdd69e 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 @@ -34,6 +34,7 @@ import javax.faces.event.FacesEvent; import javax.faces.event.PhaseId; import javax.faces.lifecycle.Lifecycle; +import org.springframework.faces.ui.resource.ResourceHelper; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.webflow.execution.View; @@ -201,10 +202,9 @@ public class AjaxViewRoot extends DelegatingViewRoot { if (StringUtils.hasLength(formId)) { String script = "dojo.byId('" + formId + "').action = '" + context.getApplication().getViewHandler().getActionURL(context, getViewId()) + "'"; - writer.startElement("script", null); - writer.writeAttribute("type", "text/javascript", null); + ResourceHelper.beginScriptBlock(context); writer.writeText(script, null); - writer.endElement("script"); + ResourceHelper.endScriptBlock(context); } } catch (IOException e) { e.printStackTrace(); diff --git a/spring-faces/src/main/java/org/springframework/faces/ui/BaseDojoComponentRenderer.java b/spring-faces/src/main/java/org/springframework/faces/ui/BaseDojoComponentRenderer.java index 29252032..7706d3ac 100644 --- a/spring-faces/src/main/java/org/springframework/faces/ui/BaseDojoComponentRenderer.java +++ b/spring-faces/src/main/java/org/springframework/faces/ui/BaseDojoComponentRenderer.java @@ -41,17 +41,15 @@ public abstract class BaseDojoComponentRenderer extends BaseSpringJavascriptComp private String springDojoJsResourceUri = "/spring/Spring-Dojo.js"; - private ResourceHelper resourceHelper = new ResourceHelper(); - public void encodeBegin(FacesContext context, UIComponent component) throws IOException { super.encodeBegin(context, component); if (!JsfUtils.isAsynchronousFlowRequest()) { - resourceHelper.renderStyleLink(context, dijitThemePath + dijitTheme + "/" + dijitTheme + ".css"); + ResourceHelper.renderStyleLink(context, dijitThemePath + dijitTheme + "/" + dijitTheme + ".css"); - resourceHelper.renderScriptLink(context, dojoJsResourceUri); + ResourceHelper.renderScriptLink(context, dojoJsResourceUri); - resourceHelper.renderScriptLink(context, springDojoJsResourceUri); + ResourceHelper.renderScriptLink(context, springDojoJsResourceUri); } } diff --git a/spring-faces/src/main/java/org/springframework/faces/ui/BaseSpringJavascriptComponentRenderer.java b/spring-faces/src/main/java/org/springframework/faces/ui/BaseSpringJavascriptComponentRenderer.java index f29063ba..3a9540a1 100644 --- a/spring-faces/src/main/java/org/springframework/faces/ui/BaseSpringJavascriptComponentRenderer.java +++ b/spring-faces/src/main/java/org/springframework/faces/ui/BaseSpringJavascriptComponentRenderer.java @@ -34,14 +34,12 @@ public abstract class BaseSpringJavascriptComponentRenderer extends BaseComponen private String springJsResourceUri = "/spring/Spring.js"; - private ResourceHelper resourceHelper = new ResourceHelper(); - public void encodeBegin(FacesContext context, UIComponent component) throws IOException { super.encodeBegin(context, component); if (!JsfUtils.isAsynchronousFlowRequest()) { - resourceHelper.renderScriptLink(context, springJsResourceUri); + ResourceHelper.renderScriptLink(context, springJsResourceUri); } } } diff --git a/spring-faces/src/main/java/org/springframework/faces/ui/BaseSpringJavascriptDecorationRenderer.java b/spring-faces/src/main/java/org/springframework/faces/ui/BaseSpringJavascriptDecorationRenderer.java index f439aae3..1158f54b 100644 --- a/spring-faces/src/main/java/org/springframework/faces/ui/BaseSpringJavascriptDecorationRenderer.java +++ b/spring-faces/src/main/java/org/springframework/faces/ui/BaseSpringJavascriptDecorationRenderer.java @@ -28,12 +28,10 @@ public abstract class BaseSpringJavascriptDecorationRenderer extends Renderer { private String springJsResourceUri = "/spring/Spring.js"; - private ResourceHelper resourceHelper = new ResourceHelper(); - public void encodeBegin(FacesContext context, UIComponent component) throws IOException { if (!JsfUtils.isAsynchronousFlowRequest()) { - resourceHelper.renderScriptLink(context, springJsResourceUri); + ResourceHelper.renderScriptLink(context, springJsResourceUri); } } diff --git a/spring-faces/src/main/java/org/springframework/faces/ui/DojoDecorationRenderer.java b/spring-faces/src/main/java/org/springframework/faces/ui/DojoDecorationRenderer.java index ded2e285..4d0323e5 100644 --- a/spring-faces/src/main/java/org/springframework/faces/ui/DojoDecorationRenderer.java +++ b/spring-faces/src/main/java/org/springframework/faces/ui/DojoDecorationRenderer.java @@ -38,8 +38,6 @@ import org.springframework.util.StringUtils; */ public class DojoDecorationRenderer extends BaseSpringJavascriptDecorationRenderer { - private static final String SCRIPT_ELEMENT = "script"; - private String dojoJsResourceUri = "/dojo/dojo.js"; private String dijitThemePath = "/dijit/themes/"; @@ -48,18 +46,16 @@ public class DojoDecorationRenderer extends BaseSpringJavascriptDecorationRender private String springDojoJsResourceUri = "/spring/Spring-Dojo.js"; - private ResourceHelper resourceHelper = new ResourceHelper(); - public void encodeBegin(FacesContext context, UIComponent component) throws IOException { super.encodeBegin(context, component); if (!JsfUtils.isAsynchronousFlowRequest()) { - resourceHelper.renderStyleLink(context, dijitThemePath + dijitTheme + "/" + dijitTheme + ".css"); + ResourceHelper.renderStyleLink(context, dijitThemePath + dijitTheme + "/" + dijitTheme + ".css"); - resourceHelper.renderScriptLink(context, dojoJsResourceUri); + ResourceHelper.renderScriptLink(context, dojoJsResourceUri); - resourceHelper.renderScriptLink(context, springDojoJsResourceUri); + ResourceHelper.renderScriptLink(context, springDojoJsResourceUri); } } @@ -72,10 +68,10 @@ public class DojoDecorationRenderer extends BaseSpringJavascriptDecorationRender UIComponent advisedChild = (UIComponent) component.getChildren().get(0); - resourceHelper.renderDojoInclude(context, ((DojoDecoration) component).getDojoComponentType()); + ResourceHelper.renderDojoInclude(context, ((DojoDecoration) component).getDojoComponentType()); + + ResourceHelper.beginScriptBlock(context); - writer.startElement(SCRIPT_ELEMENT, component); - writer.writeAttribute("type", "text/javascript", null); StringBuffer script = new StringBuffer(); script.append(" Spring.addDecoration(new Spring.ElementDecoration({ "); script.append(" elementId : '" + advisedChild.getClientId(context) + "', "); @@ -94,7 +90,8 @@ public class DojoDecorationRenderer extends BaseSpringJavascriptDecorationRender script.append(" }}));"); writer.writeText(script, null); - writer.endElement(SCRIPT_ELEMENT); + + ResourceHelper.endScriptBlock(context); } protected String getNodeAttributesAsString(FacesContext context, UIComponent component) { diff --git a/spring-faces/src/main/java/org/springframework/faces/ui/DojoStyleRenderer.java b/spring-faces/src/main/java/org/springframework/faces/ui/DojoStyleRenderer.java index 1d0dd575..c1051077 100644 --- a/spring-faces/src/main/java/org/springframework/faces/ui/DojoStyleRenderer.java +++ b/spring-faces/src/main/java/org/springframework/faces/ui/DojoStyleRenderer.java @@ -35,10 +35,8 @@ public class DojoStyleRenderer extends Renderer { private static final String dijitTheme = "tundra"; - private static final ResourceHelper resourceHelper = new ResourceHelper(); - public void encodeBegin(FacesContext context, UIComponent component) throws IOException { - resourceHelper.renderStyleLink(context, dijitThemePath + dijitTheme + "/" + dijitTheme + ".css"); + ResourceHelper.renderStyleLink(context, dijitThemePath + dijitTheme + "/" + dijitTheme + ".css"); } } diff --git a/spring-faces/src/main/java/org/springframework/faces/ui/ProgressiveCommandLinkRenderer.java b/spring-faces/src/main/java/org/springframework/faces/ui/ProgressiveCommandLinkRenderer.java index 04441876..51f7aae0 100644 --- a/spring-faces/src/main/java/org/springframework/faces/ui/ProgressiveCommandLinkRenderer.java +++ b/spring-faces/src/main/java/org/springframework/faces/ui/ProgressiveCommandLinkRenderer.java @@ -32,6 +32,7 @@ import javax.faces.context.ResponseWriter; import javax.faces.render.Renderer; import org.springframework.beans.BeanUtils; +import org.springframework.faces.ui.resource.ResourceHelper; import org.springframework.faces.webflow.JsfUtils; import org.springframework.util.Assert; @@ -102,9 +103,9 @@ public class ProgressiveCommandLinkRenderer extends ProgressiveCommandButtonRend button.encodeEnd(context); // Now render the link's HTML into a javascript variable + ResourceHelper.beginScriptBlock(context); + ResponseWriter writer = context.getResponseWriter(); - writer.startElement("script", component); - writer.writeAttribute("type", "text/javascript", null); String scriptVarStart = "var " + component.getClientId(context).replaceAll(":", "_") + "_link = \""; writer.writeText(scriptVarStart, null); writer = new DoubleQuoteEscapingWriter(writer); @@ -133,16 +134,17 @@ public class ProgressiveCommandLinkRenderer extends ProgressiveCommandButtonRend writer.writeText(scriptVarEnd, null); decorationParams.append(", linkHtml : " + component.getClientId(context).replaceAll(":", "_") + "_link"); - writer.endElement("script"); + + ResourceHelper.endScriptBlock(context); } decorationParams.append("}"); StringBuffer advisorScript = new StringBuffer(); advisorScript.append("Spring.addDecoration(new Spring.CommandLinkDecoration(" + decorationParams.toString() + "));"); - writer.startElement("script", component); + ResourceHelper.beginScriptBlock(context); writer.writeText(advisorScript, null); - writer.endElement("script"); + ResourceHelper.endScriptBlock(context); } protected String[] getAttributesToRender(UIComponent component) { diff --git a/spring-faces/src/main/java/org/springframework/faces/ui/ResourceGroupRenderer.java b/spring-faces/src/main/java/org/springframework/faces/ui/ResourceGroupRenderer.java index 73e07126..8777b32d 100644 --- a/spring-faces/src/main/java/org/springframework/faces/ui/ResourceGroupRenderer.java +++ b/spring-faces/src/main/java/org/springframework/faces/ui/ResourceGroupRenderer.java @@ -37,18 +37,16 @@ import org.springframework.faces.ui.resource.ResourceHelper; */ public class ResourceGroupRenderer extends Renderer { - private static final ResourceHelper resourceHelper = new ResourceHelper(); - public void encodeBegin(FacesContext context, UIComponent component) throws IOException { if (component.getChildCount() > 0) { - resourceHelper.beginCombineStyles(context); + ResourceHelper.beginCombineStyles(context); } } public void encodeEnd(FacesContext context, UIComponent component) throws IOException { if (component.getChildCount() > 0) { - resourceHelper.endCombineStyles(context); + ResourceHelper.endCombineStyles(context); } } } diff --git a/spring-faces/src/main/java/org/springframework/faces/ui/ResourceRenderer.java b/spring-faces/src/main/java/org/springframework/faces/ui/ResourceRenderer.java index f7313358..abe149e1 100644 --- a/spring-faces/src/main/java/org/springframework/faces/ui/ResourceRenderer.java +++ b/spring-faces/src/main/java/org/springframework/faces/ui/ResourceRenderer.java @@ -37,8 +37,6 @@ import org.springframework.util.Assert; */ public class ResourceRenderer extends Renderer { - private static final ResourceHelper resourceHelper = new ResourceHelper(); - public void encodeEnd(FacesContext context, UIComponent component) throws IOException { String resourcePath = (String) component.getAttributes().get("path"); Assert.hasText(resourcePath, "Resource component " + component.getClientId(context) + " is missing a path."); @@ -46,7 +44,7 @@ public class ResourceRenderer extends Renderer { resourcePath = "/" + resourcePath; component.getAttributes().put("path", resourcePath); } - resourceHelper.renderResource(context, resourcePath); + ResourceHelper.renderResource(context, resourcePath); } } diff --git a/spring-faces/src/main/java/org/springframework/faces/ui/ValidateAllRenderer.java b/spring-faces/src/main/java/org/springframework/faces/ui/ValidateAllRenderer.java index 0147e48f..2f57e345 100644 --- a/spring-faces/src/main/java/org/springframework/faces/ui/ValidateAllRenderer.java +++ b/spring-faces/src/main/java/org/springframework/faces/ui/ValidateAllRenderer.java @@ -24,6 +24,8 @@ import javax.faces.context.FacesContext; import javax.faces.context.ResponseWriter; import javax.faces.render.Renderer; +import org.springframework.faces.ui.resource.ResourceHelper; + /** * {@link Renderer} for the {@code } tag. * @@ -32,8 +34,6 @@ import javax.faces.render.Renderer; */ public class ValidateAllRenderer extends BaseSpringJavascriptDecorationRenderer { - private static final String SCRIPT_ELEMENT = "script"; - public void encodeEnd(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); @@ -48,12 +48,13 @@ public class ValidateAllRenderer extends BaseSpringJavascriptDecorationRenderer UIComponent advisedChild = (UIComponent) component.getChildren().get(0); - writer.startElement(SCRIPT_ELEMENT, component); - writer.writeAttribute("type", "text/javascript", null); + ResourceHelper.beginScriptBlock(context); + StringBuffer script = new StringBuffer(); script.append("Spring.addDecoration(new Spring.ValidateAllDecoration({" + "event : 'onclick', " + "elementId : '" + advisedChild.getClientId(context) + "'}));"); writer.writeText(script, null); - writer.endElement(SCRIPT_ELEMENT); + + ResourceHelper.endScriptBlock(context); } } diff --git a/spring-faces/src/main/java/org/springframework/faces/ui/resource/ResourceHelper.java b/spring-faces/src/main/java/org/springframework/faces/ui/resource/ResourceHelper.java index e40ec32b..abb3ad83 100644 --- a/spring-faces/src/main/java/org/springframework/faces/ui/resource/ResourceHelper.java +++ b/spring-faces/src/main/java/org/springframework/faces/ui/resource/ResourceHelper.java @@ -43,13 +43,23 @@ public class ResourceHelper { private static final String COMBINED_RESOURCES_KEY = "org.springframework.faces.CombinedResources"; + private static final String SCRIPT_BLOCK_ESCAPE_BEGIN = ""; + + private static final String SCRIPT_ELEMENT = "script"; + + private ResourceHelper() { + + } + /** * Renders either a script or style resource depending on the resourcePath * @param facesContext * @param resourcePath * @throws IOException */ - public void renderResource(FacesContext facesContext, String resourcePath) throws IOException { + public static void renderResource(FacesContext facesContext, String resourcePath) throws IOException { if (resourcePath.endsWith(".js")) { renderScriptLink(facesContext, resourcePath); } else if (resourcePath.endsWith(".css")) { @@ -63,7 +73,7 @@ public class ResourceHelper { * @param scriptPath * @throws IOException */ - public void renderScriptLink(FacesContext facesContext, String scriptPath) throws IOException { + public static void renderScriptLink(FacesContext facesContext, String scriptPath) throws IOException { renderScriptLink(facesContext, scriptPath, Collections.EMPTY_MAP); } @@ -74,12 +84,13 @@ public class ResourceHelper { * @param attributes - a map of additional attributes to render on the script tag * @throws IOException */ - public void renderScriptLink(FacesContext facesContext, String scriptPath, Map attributes) throws IOException { + public static void renderScriptLink(FacesContext facesContext, String scriptPath, Map attributes) + throws IOException { if (alreadyRendered(facesContext, scriptPath)) { return; } ResponseWriter writer = facesContext.getResponseWriter(); - writer.startElement("script", null); + writer.startElement(SCRIPT_ELEMENT, null); writer.writeAttribute("type", "text/javascript", null); Iterator i = attributes.keySet().iterator(); while (i.hasNext()) { @@ -88,7 +99,7 @@ public class ResourceHelper { } String src = facesContext.getExternalContext().getRequestContextPath() + "/resources" + scriptPath; writer.writeAttribute("src", src, null); - writer.endElement("script"); + writer.endElement(SCRIPT_ELEMENT); markRendered(facesContext, scriptPath); } @@ -98,7 +109,7 @@ public class ResourceHelper { * @param cssPath * @throws IOException */ - public void renderStyleLink(FacesContext facesContext, String cssPath) throws IOException { + public static void renderStyleLink(FacesContext facesContext, String cssPath) throws IOException { if (alreadyRendered(facesContext, cssPath)) { return; } else if (isCombineStyles(facesContext)) { @@ -121,33 +132,33 @@ public class ResourceHelper { * @param module * @throws IOException */ - public void renderDojoInclude(FacesContext facesContext, String module) throws IOException { + public static void renderDojoInclude(FacesContext facesContext, String module) throws IOException { if (alreadyRendered(facesContext, module)) { return; } ResponseWriter writer = facesContext.getResponseWriter(); - writer.startElement("script", null); + writer.startElement(SCRIPT_ELEMENT, null); writer.writeAttribute("type", "text/javascript", null); writer.writeText("dojo.require('" + module + "');", null); - writer.endElement("script"); + writer.endElement(SCRIPT_ELEMENT); markRendered(facesContext, module); } - public void beginCombineStyles(FacesContext facesContext) { + public static void beginCombineStyles(FacesContext facesContext) { List combinedResources = new ArrayList(); facesContext.getExternalContext().getRequestMap().put(COMBINED_RESOURCES_KEY, combinedResources); } - private boolean isCombineStyles(FacesContext facesContext) { + private static boolean isCombineStyles(FacesContext facesContext) { return facesContext.getExternalContext().getRequestMap().containsKey(COMBINED_RESOURCES_KEY); } - private void addStyle(FacesContext facesContext, String stylePath) { + private static void addStyle(FacesContext facesContext, String stylePath) { List combinedResources = (List) facesContext.getExternalContext().getRequestMap().get(COMBINED_RESOURCES_KEY); combinedResources.add(stylePath); } - public void endCombineStyles(FacesContext facesContext) throws IOException { + public static void endCombineStyles(FacesContext facesContext) throws IOException { List combinedResources = (List) facesContext.getExternalContext().getRequestMap() .remove(COMBINED_RESOURCES_KEY); StringBuffer combinedPath = new StringBuffer(); @@ -164,7 +175,20 @@ public class ResourceHelper { renderStyleLink(facesContext, combinedPath.toString()); } - private void markRendered(FacesContext facesContext, String scriptPath) { + public static void beginScriptBlock(FacesContext facesContext) throws IOException { + ResponseWriter writer = facesContext.getResponseWriter(); + writer.startElement(SCRIPT_ELEMENT, null); + writer.writeAttribute("type", "text/javascript", null); + writer.writeText(SCRIPT_BLOCK_ESCAPE_BEGIN, null); + } + + public static void endScriptBlock(FacesContext facesContext) throws IOException { + ResponseWriter writer = facesContext.getResponseWriter(); + writer.writeText(SCRIPT_BLOCK_ESCAPE_END, null); + writer.endElement(SCRIPT_ELEMENT); + } + + private static void markRendered(FacesContext facesContext, String scriptPath) { Set renderedResources = (Set) facesContext.getExternalContext().getRequestMap().get(RENDERED_RESOURCES_KEY); if (renderedResources == null) { renderedResources = new HashSet(); @@ -173,7 +197,7 @@ public class ResourceHelper { renderedResources.add(scriptPath); } - private boolean alreadyRendered(FacesContext facesContext, String scriptPath) { + private static boolean alreadyRendered(FacesContext facesContext, String scriptPath) { Set renderedResources = (Set) facesContext.getExternalContext().getRequestMap().get(RENDERED_RESOURCES_KEY); return renderedResources != null && renderedResources.contains(scriptPath); } diff --git a/spring-faces/src/test/java/org/springframework/faces/ui/resource/FlowResourceHelperTests.java b/spring-faces/src/test/java/org/springframework/faces/ui/resource/FlowResourceHelperTests.java index 754bf169..bd1ec147 100644 --- a/spring-faces/src/test/java/org/springframework/faces/ui/resource/FlowResourceHelperTests.java +++ b/spring-faces/src/test/java/org/springframework/faces/ui/resource/FlowResourceHelperTests.java @@ -10,8 +10,6 @@ import org.springframework.faces.webflow.JSFMockHelper; public class FlowResourceHelperTests extends TestCase { - ResourceHelper resourceHelper = new ResourceHelper(); - StringWriter writer = new StringWriter(); JSFMockHelper jsf = new JSFMockHelper(); @@ -31,8 +29,8 @@ public class FlowResourceHelperTests extends TestCase { String scriptPath = "/dojo/dojo.js"; String expectedUrl = "null/resources/dojo/dojo.js"; - resourceHelper.renderScriptLink(jsf.facesContext(), scriptPath); - resourceHelper.renderScriptLink(jsf.facesContext(), scriptPath); + ResourceHelper.renderScriptLink(jsf.facesContext(), scriptPath); + ResourceHelper.renderScriptLink(jsf.facesContext(), scriptPath); String expectedOutput = ")";var _24=[];var _25=new RegExp(_23,"img");var _26=new RegExp(_23,"im");var _27=_1c.match(_25);if(_27!=null){for(var i=0;i<_27.length;i++){var _29=(_27[i].match(_26)||["","",""])[2];_29=_29.replace(//mg,"");_24.push(_29);}}_1c=_1c.replace(_25,"");var _2a=dojo.doc.createElement("span");_2a.id="ajaxResponse";_2a.style.visibility="hidden";document.body.appendChild(_2a);_2a.innerHTML=_1c;var _2b=new dojo.NodeList(_2a);var _2c=_2b.query("#ajaxResponse > *").orphan();_2b.orphan();if(_20){Spring.remoting.renderNodeListToModalDialog(_2c);}else{_2c.forEach(function(_2d){if(_2d.id!=null&&_2d.id!=""){var _2e=dojo.byId(_2d.id);if(!_2e){console.error("An existing DOM elment with id '"+_2d.id+"' could not be found for replacement.");}else{_2e.parentNode.replaceChild(_2d,_2e);}}});}dojo.forEach(_24,function(_2f){dojo.eval(_2f);});return _1c;},handleError:function(_30,_31){dojo.require("dijit.Dialog");console.error("HTTP status code: ",_31.xhr.status);if(Spring.debug&&_31.xhr.status!=200){var _32=new dijit.Dialog({});dojo.connect(_32,"hide",_32,function(){this.destroyRecursive(false);});_32.domNode.style.width="80%";_32.domNode.style.height="80%";_32.domNode.style.textAlign="left";_32.setContent(_30.responseText);_32.show();}return _30;},renderURLToModalDialog:function(url,_34){url=url+"&"+dojo.objectToQuery(_34.args.content);Spring.remoting.getResource(url,{},true);},renderNodeListToModalDialog:function(_35){dojo.require("dijit.Dialog");var _36=new dijit.Dialog({});_36.setContent(_35);dojo.connect(_36,"hide",_36,function(){this.destroyRecursive(false);});_36.show();}});dojo.declare("Spring.CommandLinkDecoration",[Spring.AbstractCommandLinkDecoration,Spring.DefaultEquals],{constructor:function(_37){dojo.mixin(this,_37);},apply:function(){var _38=dojo.byId(this.elementId);if(!dojo.hasClass(_38,"progressiveLink")){var _39=new dojo.NodeList(_38);_39.addContent(this.linkHtml,"after").orphan("*");_38=dojo.byId(this.elementId);}_38.submitFormFromLink=this.submitFormFromLink;return this;},submitFormFromLink:function(_3a,_3b,_3c){var _3d=[];var _3e=dojo.byId(_3a);var _3f=document.createElement("input");_3f.name=_3b;_3f.value="submitted";_3d.push(_3f);dojo.forEach(_3c,function(_40){var _41=document.createElement("input");_41.name=_40.name;_41.value=_40.value;_3d.push(_41);});dojo.forEach(_3d,function(_42){dojo.addClass(_42,"SpringLinkInput");dojo.place(_42,_3e,"last");});if((_3e.onsubmit?!_3e.onsubmit():false)||!_3e.submit()){dojo.forEach(_3d,function(_43){_3e.removeChild(_43);});}}});dojo.addOnLoad(Spring.initialize); \ No newline at end of file +dojo.declare("Spring.DefaultEquals",null,{equals:function(_1){if(_1.declaredClass&&_1.declaredClass==this.declaredClass){return true;}else{return false;}}});dojo.declare("Spring.ElementDecoration",[Spring.AbstractElementDecoration,Spring.DefaultEquals],{constructor:function(_2){this.copyFields=new Array("name","value","type","checked","selected","readOnly","disabled","alt","maxLength","class","title");dojo.mixin(this,_2);if(this.widgetModule==""){this.widgetModule=this.widgetType;}},apply:function(){if(dijit.byId(this.elementId)){dijit.byId(this.elementId).destroyRecursive(false);}var _3=dojo.byId(this.elementId);if(!_3){console.error("Could not apply "+this.widgetType+" decoration. Element with id '"+this.elementId+"' not found in the DOM.");}else{for(var _4 in this.copyFields){_4=this.copyFields[_4];if(!this.widgetAttrs[_4]&&_3[_4]&&(typeof _3[_4]!="number"||(typeof _3[_4]=="number"&&_3[_4]>=0))){this.widgetAttrs[_4]=_3[_4];}}if(_3["style"]&&_3["style"].cssText){this.widgetAttrs["style"]=_3["style"].cssText;}dojo.require(this.widgetModule);var _5=dojo.eval(this.widgetType);this.widget=new _5(this.widgetAttrs,_3);this.widget.startup();}return this;},validate:function(){if(!this.widget.isValid){return true;}var _6=this.widget.isValid(false);if(!_6){this.widget.state="Error";this.widget._setStateClass();}return _6;}});dojo.declare("Spring.ValidateAllDecoration",[Spring.AbstractValidateAllDecoration,Spring.DefaultEquals],{constructor:function(_7){this.originalHandler=null;this.connection=null;dojo.mixin(this,_7);},apply:function(){var _8=dojo.byId(this.elementId);this.originalHandler=_8[this.event];var _9=this;_8[this.event]=function(_a){_9.handleEvent(_a,_9);};return this;},cleanup:function(){dojo.disconnect(this.connection);},handleEvent:function(_b,_c){if(!Spring.validateAll()){dojo.stopEvent(_b);}else{if(dojo.isFunction(_c.originalHandler)){var _d=_c.originalHandler(_b);if(_d==false){dojo.stopEvent(_b);}}}}});dojo.declare("Spring.AjaxEventDecoration",[Spring.AbstractAjaxEventDecoration,Spring.DefaultEquals],{constructor:function(_e){this.connection=null;dojo.mixin(this,_e);},apply:function(){this.connection=dojo.connect(dojo.byId(this.elementId),this.event,this,"submit");return this;},cleanup:function(){dojo.disconnect(this.connection);},submit:function(_f){if(this.sourceId==""){this.sourceId=this.elementId;}if(this.formId==""){Spring.remoting.getLinkedResource(this.sourceId,this.params,this.popup);}else{Spring.remoting.submitForm(this.sourceId,this.formId,this.params);}dojo.stopEvent(_f);}});dojo.declare("Spring.RemotingHandler",Spring.AbstractRemotingHandler,{constructor:function(){},submitForm:function(_10,_11,_12){var _13=new Object();for(var key in _12){_13[key]=_12[key];}var _15=dojo.byId(_10);if(_15!=null){if(_15.value!=undefined&&_15.type&&("button,submit,reset").indexOf(_15.type)<0){_13[_10]=_15.value;}else{if(_15.name!=undefined){_13[_15.name]=_15.name;}else{_13[_10]=_10;}}}if(!_13["ajaxSource"]){_13["ajaxSource"]=_10;}dojo.xhrPost({content:_13,form:_11,handleAs:"text",headers:{"Accept":"text/html;type=ajax"},load:this.handleResponse,error:this.handleError});},getLinkedResource:function(_16,_17,_18){this.getResource(dojo.byId(_16).href,_17,_18);},getResource:function(_19,_1a,_1b){dojo.xhrGet({url:_19,content:_1a,handleAs:"text",headers:{"Accept":"text/html;type=ajax"},load:this.handleResponse,error:this.handleError,modal:_1b});},handleResponse:function(_1c,_1d){var _1e=_1d.xhr.getResponseHeader("Spring-Redirect-URL");var _1f=_1d.xhr.getResponseHeader("Spring-Modal-View");var _20=((dojo.isString(_1f)&&_1f.length>0)||_1d.args.modal);if(dojo.isString(_1e)&&_1e.length>0){if(_20){Spring.remoting.renderURLToModalDialog(_1e,_1d);return _1c;}else{if(_1e.indexOf("/")>=0){window.location=window.location.protocol+"//"+window.location.host+_1e;}else{var _21=window.location.protocol+"//"+window.location.host+window.location.pathname;var _22=_21.lastIndexOf("/");_21=_21.substr(0,_22+1)+_1e;if(_21==window.location){Spring.remoting.getResource(_21,_1d.args.content,false);}else{window.location=_21;}}return _1c;}}var _23="(?:)((\n|\r|.)*?)(?:)";var _24=[];var _25=new RegExp(_23,"img");var _26=new RegExp(_23,"im");var _27=_1c.match(_25);if(_27!=null){for(var i=0;i<_27.length;i++){var _29=(_27[i].match(_26)||["","",""])[2];_29=_29.replace(//mg,"").replace(/)*/mg,"").replace(/(/mg,"");_24.push(_29);}}_1c=_1c.replace(_25,"");var _2a=dojo.doc.createElement("span");_2a.id="ajaxResponse";_2a.style.visibility="hidden";document.body.appendChild(_2a);_2a.innerHTML=_1c;var _2b=new dojo.NodeList(_2a);var _2c=_2b.query("#ajaxResponse > *").orphan();_2b.orphan();if(_20){Spring.remoting.renderNodeListToModalDialog(_2c);}else{_2c.forEach(function(_2d){if(_2d.id!=null&&_2d.id!=""){var _2e=dojo.byId(_2d.id);if(!_2e){console.error("An existing DOM elment with id '"+_2d.id+"' could not be found for replacement.");}else{_2e.parentNode.replaceChild(_2d,_2e);}}});}dojo.forEach(_24,function(_2f){dojo.eval(_2f);});return _1c;},handleError:function(_30,_31){dojo.require("dijit.Dialog");console.error("HTTP status code: ",_31.xhr.status);if(Spring.debug&&_31.xhr.status!=200){var _32=new dijit.Dialog({});dojo.connect(_32,"hide",_32,function(){this.destroyRecursive(false);});_32.domNode.style.width="80%";_32.domNode.style.height="80%";_32.domNode.style.textAlign="left";_32.setContent(_30.responseText);_32.show();}return _30;},renderURLToModalDialog:function(url,_34){url=url+"&"+dojo.objectToQuery(_34.args.content);Spring.remoting.getResource(url,{},true);},renderNodeListToModalDialog:function(_35){dojo.require("dijit.Dialog");var _36=new dijit.Dialog({});_36.setContent(_35);dojo.connect(_36,"hide",_36,function(){this.destroyRecursive(false);});_36.show();}});dojo.declare("Spring.CommandLinkDecoration",[Spring.AbstractCommandLinkDecoration,Spring.DefaultEquals],{constructor:function(_37){dojo.mixin(this,_37);},apply:function(){var _38=dojo.byId(this.elementId);if(!dojo.hasClass(_38,"progressiveLink")){var _39=new dojo.NodeList(_38);_39.addContent(this.linkHtml,"after").orphan("*");_38=dojo.byId(this.elementId);}_38.submitFormFromLink=this.submitFormFromLink;return this;},submitFormFromLink:function(_3a,_3b,_3c){var _3d=[];var _3e=dojo.byId(_3a);var _3f=document.createElement("input");_3f.name=_3b;_3f.value="submitted";_3d.push(_3f);dojo.forEach(_3c,function(_40){var _41=document.createElement("input");_41.name=_40.name;_41.value=_40.value;_3d.push(_41);});dojo.forEach(_3d,function(_42){dojo.addClass(_42,"SpringLinkInput");dojo.place(_42,_3e,"last");});if((_3e.onsubmit?!_3e.onsubmit():false)||!_3e.submit()){dojo.forEach(_3d,function(_43){_3e.removeChild(_43);});}}});dojo.addOnLoad(Spring.initialize); \ No newline at end of file diff --git a/spring-js/src/main/resources/META-INF/spring/Spring-Dojo.js.uncompressed b/spring-js/src/main/resources/META-INF/spring/Spring-Dojo.js.uncompressed index 36f022e0..df320994 100644 --- a/spring-js/src/main/resources/META-INF/spring/Spring-Dojo.js.uncompressed +++ b/spring-js/src/main/resources/META-INF/spring/Spring-Dojo.js.uncompressed @@ -248,7 +248,7 @@ dojo.declare("Spring.RemotingHandler", Spring.AbstractRemotingHandler, { for (var i=0; i/mg,''); + script = script.replace(//mg,'').replace(/)*/mg,'').replace(/(/mg,''); extractedScriptNodes.push(script); } }