Refactored SpringFaces.js to have Ext and Dojo implementations.
Fixed resource support to properly send a 404 status when resource is not found.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
SpringFaces.DojoGenericFieldAdvisor = function(config){
|
||||
|
||||
dojo.mixin(this, config);
|
||||
};
|
||||
|
||||
SpringFaces.DojoGenericFieldAdvisor.prototype = {
|
||||
|
||||
targetElId : "",
|
||||
decoratorType : "",
|
||||
decorator : null,
|
||||
decoratorAttrs : "",
|
||||
|
||||
apply : function(){
|
||||
|
||||
this.decorator = eval("new "+ this.decoratorType + "(" + this.decoratorAttrs +", dojo.byId('"+this.targetElId+"'));" );
|
||||
|
||||
this.decorator.startup();
|
||||
}
|
||||
};
|
||||
|
||||
dojo.addOnLoad(SpringFaces.applyAdvisors);
|
||||
@@ -0,0 +1,26 @@
|
||||
SpringFaces.ExtGenericFieldAdvisor = function(config){
|
||||
|
||||
Ext.apply(this, config);
|
||||
};
|
||||
|
||||
SpringFaces.ExtGenericFieldAdvisor.prototype = {
|
||||
|
||||
targetElId : "",
|
||||
msgElId : "",
|
||||
decoratorType : "",
|
||||
decorator : null,
|
||||
decoratorAttrs : "",
|
||||
|
||||
apply : function(){
|
||||
|
||||
var target = document.getElementById(this.targetElId);
|
||||
var msgEl = document.getElementById(this.msgElId);
|
||||
|
||||
this.decorator = eval("new "+ this.decoratorType + "(" + this.decoratorAttrs +");" );
|
||||
|
||||
this.decorator.msgTarget=msgEl;
|
||||
this.decorator.applyTo(target);
|
||||
}
|
||||
};
|
||||
|
||||
Ext.onReady(SpringFaces.applyAdvisors);
|
||||
@@ -2,31 +2,6 @@ SpringFaces = {};
|
||||
|
||||
SpringFaces.advisors = [];
|
||||
|
||||
SpringFaces.ExtGenericFieldAdvisor = function(config){
|
||||
|
||||
Ext.apply(this, config);
|
||||
};
|
||||
|
||||
SpringFaces.ExtGenericFieldAdvisor.prototype = {
|
||||
|
||||
targetElId : "",
|
||||
msgElId : "",
|
||||
decoratorType : "",
|
||||
decorator : null,
|
||||
decoratorAttrs : "",
|
||||
|
||||
apply : function(){
|
||||
|
||||
var target = document.getElementById(this.targetElId);
|
||||
var msgEl = document.getElementById(this.msgElId);
|
||||
|
||||
this.decorator = eval("new "+ this.decoratorType + "(" + this.decoratorAttrs +");" );
|
||||
|
||||
this.decorator.msgTarget=msgEl;
|
||||
this.decorator.applyTo(target);
|
||||
}
|
||||
};
|
||||
|
||||
SpringFaces.applyAdvisors = function(){
|
||||
|
||||
for (var x=0; x<SpringFaces.advisors.length; x++) {
|
||||
@@ -43,6 +18,4 @@ SpringFaces.validateAll = function(){
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
};
|
||||
|
||||
Ext.onReady(SpringFaces.applyAdvisors);
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.springframework.faces.ui;
|
||||
|
||||
import javax.faces.component.UIComponentBase;
|
||||
|
||||
public class DojoAdvisor extends UIComponentBase {
|
||||
|
||||
public String getFamily() {
|
||||
|
||||
return "spring.faces.DojoAdvisor";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.springframework.faces.ui;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.render.Renderer;
|
||||
|
||||
import org.springframework.faces.ui.resource.FlowResourceHelper;
|
||||
|
||||
public class DojoRenderer extends Renderer {
|
||||
|
||||
private String dojoJsResourceUri = "/dojo/dojo.js";
|
||||
|
||||
private String dojoStyleResourceUri = "/dojo/dojo.css";
|
||||
|
||||
private String dijitThemePath = "/dijit/themes/";
|
||||
|
||||
private String dijitTheme = "tundra";
|
||||
|
||||
private String springFacesJsResourceUri = "/spring-faces/SpringFaces.js";
|
||||
|
||||
private String springFacesDojoJsResourceUri = "/spring-faces/SpringFaces-Dojo.js";
|
||||
|
||||
private FlowResourceHelper resourceHelper = new FlowResourceHelper();
|
||||
|
||||
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
|
||||
|
||||
resourceHelper.renderStyleLink(context, dijitThemePath + "/" + dijitTheme + "/" + dijitTheme + ".css");
|
||||
|
||||
resourceHelper.renderStyleLink(context, dojoStyleResourceUri);
|
||||
|
||||
resourceHelper.renderScriptLink(context, dojoJsResourceUri);
|
||||
|
||||
resourceHelper.renderScriptLink(context, springFacesJsResourceUri);
|
||||
|
||||
resourceHelper.renderScriptLink(context, springFacesDojoJsResourceUri);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ public class ExtJsRenderer extends Renderer {
|
||||
|
||||
private static final String SPRING_FACES_SCRIPT = "/spring-faces/SpringFaces.js";
|
||||
|
||||
private static final String SPRING_FACES_EXT_SCRIPT = "/spring-faces/SpringFaces-Ext.js";
|
||||
|
||||
private FlowResourceHelper resourceHelper = new FlowResourceHelper();
|
||||
|
||||
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
|
||||
@@ -31,5 +33,7 @@ public class ExtJsRenderer extends Renderer {
|
||||
}
|
||||
|
||||
resourceHelper.renderScriptLink(context, SPRING_FACES_SCRIPT);
|
||||
|
||||
resourceHelper.renderScriptLink(context, SPRING_FACES_EXT_SCRIPT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.springframework.faces.ui.resource;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -41,14 +42,22 @@ public class ResolveAndRenderResourceAction implements Action {
|
||||
|
||||
public Event execute(RequestContext context) throws Exception {
|
||||
|
||||
String resourcePath = "META-INF" + context.getExternalContext().getRequestPath().toString();
|
||||
URLConnection resourceConn = ClassUtils.getDefaultClassLoader().getResource(resourcePath).openConnection();
|
||||
long lastModified = resourceConn.getLastModified();
|
||||
|
||||
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
|
||||
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
|
||||
ServletContext servletContext = (ServletContext) context.getExternalContext().getContext();
|
||||
|
||||
String resourcePath = "META-INF" + context.getExternalContext().getRequestPath().toString();
|
||||
|
||||
URL resource = ClassUtils.getDefaultClassLoader().getResource(resourcePath);
|
||||
|
||||
if (resource == null) {
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
return new Event(this, "success");
|
||||
}
|
||||
|
||||
URLConnection resourceConn = resource.openConnection();
|
||||
long lastModified = resourceConn.getLastModified();
|
||||
|
||||
long ifModifiedSince = request.getDateHeader(IF_MODIFIED_SINCE_HEADER);
|
||||
if (ifModifiedSince > 0 && lastModified / 1000 <= ifModifiedSince / 1000) {
|
||||
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
|
||||
|
||||
Reference in New Issue
Block a user