-Moving AjaxHandler to spring-js
-Polishing Spring.js API -Refactoring spring-faces components to match Spring.js API changes.
This commit is contained in:
@@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.ajax4jsf.context.AjaxContext;
|
||||
import org.springframework.faces.webflow.FlowLifecycle;
|
||||
import org.springframework.webflow.mvc.servlet.SpringJavascriptAjaxHandler;
|
||||
import org.springframework.js.mvc.servlet.SpringJavascriptAjaxHandler;
|
||||
|
||||
/**
|
||||
* Ajax handler that works with Rich Faces, allowing support for Web Flow ajax features with the Rich Faces toolkit.
|
||||
|
||||
@@ -17,12 +17,12 @@ package org.springframework.faces.ui;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
import javax.faces.event.ActionEvent;
|
||||
|
||||
import org.springframework.faces.webflow.JsfUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -38,32 +38,37 @@ public class AjaxEventInterceptorRenderer extends DojoRenderer {
|
||||
writer.writeAttribute("type", "text/javascript", null);
|
||||
|
||||
String processIds = (String) component.getAttributes().get("processIds");
|
||||
String renderIds = (String) component.getAttributes().get("renderIds");
|
||||
if (StringUtils.hasText(processIds) && !processIds.contains(component.getClientId(context))) {
|
||||
processIds = component.getClientId(context) + ", " + processIds;
|
||||
} else if (!StringUtils.hasText(processIds)) {
|
||||
processIds = component.getClientId(context);
|
||||
}
|
||||
if (!StringUtils.hasText(renderIds)) {
|
||||
renderIds = processIds;
|
||||
}
|
||||
String childId = getElementId(context, component);
|
||||
StringBuffer script = new StringBuffer();
|
||||
script.append("Spring.advisors.push(new Spring.RemoteEventAdvisor({");
|
||||
script.append("Spring.addDecoration(new Spring.AjaxEventDecoration({");
|
||||
script.append("event:'" + event + "'");
|
||||
script.append(", targetId: '" + ((UIComponent) component.getChildren().get(0)).getClientId(context) + "'");
|
||||
script.append(", sourceId : '" + component.getClientId(context) + "'");
|
||||
script.append(", elementId: '" + childId + "'");
|
||||
script.append(", formId : '" + RendererUtils.getFormId(context, component) + "'");
|
||||
script.append(", processIds : '" + processIds + "'");
|
||||
script.append(", renderIds : '" + renderIds + "'})");
|
||||
if (JsfUtils.isAsynchronousFlowRequest()) {
|
||||
script.append(".apply()");
|
||||
}
|
||||
script.append(");");
|
||||
script.append(", params: {processIds : '" + processIds + "'");
|
||||
script.append(", ajaxSource : '" + component.getClientId(context) + "'} }));");
|
||||
|
||||
writer.writeText(script.toString(), null);
|
||||
writer.endElement("script");
|
||||
}
|
||||
|
||||
private String getElementId(FacesContext context, UIComponent component) {
|
||||
if (component.getChildCount() > 0) {
|
||||
UIComponent child = (UIComponent) component.getChildren().get(0);
|
||||
if (!(child instanceof DojoAdvisor)) {
|
||||
return child.getClientId(context);
|
||||
} else {
|
||||
return getElementId(context, child);
|
||||
}
|
||||
} else {
|
||||
throw new FacesException("Could not locate a proper child element to trigger the ajax event.");
|
||||
}
|
||||
}
|
||||
|
||||
public void decode(FacesContext context, UIComponent component) {
|
||||
if (context.getExternalContext().getRequestParameterMap().containsKey("ajaxSource")
|
||||
&& context.getExternalContext().getRequestParameterMap().get("ajaxSource").equals(
|
||||
|
||||
@@ -25,7 +25,6 @@ import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
|
||||
import org.springframework.faces.ui.resource.ResourceHelper;
|
||||
import org.springframework.faces.webflow.JsfUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class DojoAdvisorRenderer extends DojoRenderer {
|
||||
@@ -48,11 +47,10 @@ public class DojoAdvisorRenderer extends DojoRenderer {
|
||||
writer.startElement(SCRIPT_ELEMENT, component);
|
||||
writer.writeAttribute("type", "text/javascript", null);
|
||||
StringBuffer script = new StringBuffer();
|
||||
script.append(" Spring.advisors.push(new Spring.ValidatingFieldAdvisor({ ");
|
||||
script.append(" targetElId : '" + advisedChild.getClientId(context) + "', ");
|
||||
script.append(" msgElId : '" + advisedChild.getClientId(context) + ":msg', ");
|
||||
script.append(" decoratorType : '" + ((DojoAdvisor) component).getDojoComponentType() + "', ");
|
||||
script.append(" decoratorAttrs : \"{ ");
|
||||
script.append(" Spring.addDecoration(new Spring.ElementDecoration({ ");
|
||||
script.append(" elementId : '" + advisedChild.getClientId(context) + "', ");
|
||||
script.append(" widgetType : '" + ((DojoAdvisor) component).getDojoComponentType() + "', ");
|
||||
script.append(" widgetAttrs : { ");
|
||||
|
||||
String nodeAttrs = getNodeAttributesAsString(context, advisedChild);
|
||||
String dojoAttrs = getDojoAttributesAsString(context, component);
|
||||
@@ -63,13 +61,7 @@ public class DojoAdvisorRenderer extends DojoRenderer {
|
||||
}
|
||||
script.append(dojoAttrs);
|
||||
|
||||
script.append(" }\"})");
|
||||
|
||||
if (JsfUtils.isAsynchronousFlowRequest()) {
|
||||
script.append(".apply()");
|
||||
}
|
||||
|
||||
script.append("); ");
|
||||
script.append(" }}));");
|
||||
|
||||
writer.writeText(script, null);
|
||||
writer.endElement(SCRIPT_ELEMENT);
|
||||
|
||||
@@ -69,20 +69,16 @@ public class ProgressiveCommandButtonRenderer extends BaseDojoParentComponentRen
|
||||
|
||||
Boolean ajaxEnabled = (Boolean) component.getAttributes().get("ajaxEnabled");
|
||||
String processIds = (String) component.getAttributes().get("processIds");
|
||||
String renderIds = (String) component.getAttributes().get("renderIds");
|
||||
if (Boolean.TRUE.equals(ajaxEnabled)) {
|
||||
if (StringUtils.hasText(processIds) && !processIds.contains(component.getClientId(context))) {
|
||||
processIds = component.getClientId(context) + ", " + processIds;
|
||||
} else if (!StringUtils.hasText(processIds)) {
|
||||
processIds = component.getClientId(context);
|
||||
}
|
||||
if (!StringUtils.hasText(renderIds)) {
|
||||
renderIds = processIds;
|
||||
}
|
||||
onclick.append("Spring.RemotingHandler.submitForm('" + component.getClientId(context) + "', ");
|
||||
onclick.append("Spring.remoting.submitForm('" + component.getClientId(context) + "', ");
|
||||
onclick.append("'" + RendererUtils.getFormId(context, component) + "', ");
|
||||
onclick.append("'" + processIds + "', '" + renderIds + "', " + encodeParams(context, component)
|
||||
+ "); return false;");
|
||||
onclick.append("{processIds: '" + processIds + "'" + encodeParams(context, component)
|
||||
+ "}); return false;");
|
||||
} else {
|
||||
onclick.append(getOnClickNoAjax(context, component));
|
||||
}
|
||||
@@ -142,20 +138,15 @@ public class ProgressiveCommandButtonRenderer extends BaseDojoParentComponentRen
|
||||
|
||||
protected String encodeParams(FacesContext context, UIComponent component) {
|
||||
StringBuffer paramArray = new StringBuffer();
|
||||
paramArray.append("[");
|
||||
for (int i = 0; i < component.getChildCount(); i++) {
|
||||
if (component.getChildren().get(i) instanceof UIParameter) {
|
||||
UIParameter param = (UIParameter) component.getChildren().get(i);
|
||||
Assert.hasText(param.getName(),
|
||||
"UIParameter requires a name when used as a child of a UICommand component");
|
||||
if (paramArray.length() > 1) {
|
||||
paramArray.append(", ");
|
||||
}
|
||||
paramArray.append("{name : '" + param.getName() + "'");
|
||||
paramArray.append(", value : '" + param.getValue() + "'}");
|
||||
|
||||
paramArray.append(", " + param.getName() + ": '" + param.getValue() + "'");
|
||||
}
|
||||
}
|
||||
paramArray.append("]");
|
||||
return paramArray.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -101,9 +101,9 @@ public class ProgressiveCommandLinkRenderer extends ProgressiveCommandButtonRend
|
||||
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
|
||||
super.encodeEnd(context, component);
|
||||
|
||||
StringBuffer advisorParams = new StringBuffer();
|
||||
advisorParams.append("{");
|
||||
advisorParams.append("targetElId : '" + component.getClientId(context) + "'");
|
||||
StringBuffer decorationParams = new StringBuffer();
|
||||
decorationParams.append("{");
|
||||
decorationParams.append("elementId : '" + component.getClientId(context) + "'");
|
||||
|
||||
ResponseWriter writer = context.getResponseWriter();
|
||||
// Close the script variable started in encodeBegin if this is not an AJAX request
|
||||
@@ -117,18 +117,14 @@ public class ProgressiveCommandLinkRenderer extends ProgressiveCommandButtonRend
|
||||
String scriptVarEnd = "\";\n";
|
||||
writer.writeText(scriptVarEnd, null);
|
||||
|
||||
advisorParams.append(", linkHtml : " + component.getClientId(context).replaceAll(":", "_") + "_link");
|
||||
decorationParams.append(", linkHtml : " + component.getClientId(context).replaceAll(":", "_") + "_link");
|
||||
writer.endElement("script");
|
||||
}
|
||||
|
||||
advisorParams.append("}");
|
||||
decorationParams.append("}");
|
||||
StringBuffer advisorScript = new StringBuffer();
|
||||
advisorScript.append("Spring.advisors.push(new Spring.CommandLinkAdvisor(" + advisorParams.toString() + ")");
|
||||
// Apply the advisor immediately if this is an AJAX request
|
||||
if (JsfUtils.isAsynchronousFlowRequest()) {
|
||||
advisorScript.append(".apply()");
|
||||
}
|
||||
advisorScript.append(");");
|
||||
advisorScript.append("Spring.addDecoration(new Spring.CommandLinkDecoration(" + decorationParams.toString()
|
||||
+ "));");
|
||||
writer.startElement("script", component);
|
||||
writer.writeText(advisorScript, null);
|
||||
writer.endElement("script");
|
||||
|
||||
@@ -44,8 +44,8 @@ public class ValidateAllRenderer extends SpringFacesRenderer {
|
||||
writer.startElement(SCRIPT_ELEMENT, component);
|
||||
writer.writeAttribute("type", "text/javascript", null);
|
||||
StringBuffer script = new StringBuffer();
|
||||
script.append("Spring.advisors.push(new Spring.ValidateAllAdvisor({" + "event : 'onclick', " + "targetId : '"
|
||||
+ advisedChild.getClientId(context) + "'}));");
|
||||
script.append("Spring.addDecoration(new Spring.ValidateAllDecoration({" + "event : 'onclick', "
|
||||
+ "elementId : '" + advisedChild.getClientId(context) + "'}));");
|
||||
writer.writeText(script, null);
|
||||
writer.endElement(SCRIPT_ELEMENT);
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.io.ContextResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.faces.ui.AjaxViewRoot;
|
||||
import org.springframework.js.mvc.servlet.AjaxHandler;
|
||||
import org.springframework.js.mvc.servlet.SpringJavascriptAjaxHandler;
|
||||
import org.springframework.webflow.context.ExternalContext;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.View;
|
||||
import org.springframework.webflow.execution.ViewFactory;
|
||||
import org.springframework.webflow.mvc.servlet.AjaxHandler;
|
||||
import org.springframework.webflow.mvc.servlet.SpringJavascriptAjaxHandler;
|
||||
|
||||
/**
|
||||
* JSF-specific {@link ViewFactory} implementation.
|
||||
|
||||
Reference in New Issue
Block a user