WW-1897 Create JSONValidationInterceptor

* Add 'validate' attribute to submit,anchor and bind tags for ajax validation
 * Add 'ajaxAfterValidation' attribute to submit,anchor and bind tags to make an ajax request if validation succeeds (false by default)

WW-1900 Clean up Dojo plugin
 * Rename AbstractRemoteCallUIBean
 * Drop 'form' tag

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@533389 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Musachy Barroso
2007-04-28 16:59:01 +00:00
parent f3b4786cc9
commit 8c9b0d1dff
38 changed files with 1598 additions and 1581 deletions
@@ -30,7 +30,7 @@ import com.opensymphony.xwork2.util.ValueStack;
* AbstractRemoteCallUIBean is superclass for all components dealing with remote
* calls.
*/
public abstract class AbstractRemoteCallUIBean extends ClosingUIBean implements RemoteUICallBean {
public abstract class AbstractRemoteBean extends ClosingUIBean implements RemoteBean {
protected String href;
protected String errorText;
@@ -50,7 +50,7 @@ public abstract class AbstractRemoteCallUIBean extends ClosingUIBean implements
protected String highlightColor;
protected String highlightDuration;
public AbstractRemoteCallUIBean(ValueStack stack, HttpServletRequest request,
public AbstractRemoteBean(ValueStack stack, HttpServletRequest request,
HttpServletResponse response) {
super(stack, request, response);
}
@@ -0,0 +1,63 @@
/*
* $Id$
*
* Copyright 2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.struts2.dojo.components;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.Form;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import com.opensymphony.xwork2.util.ValueStack;
/**
* Base class for tags that perform AJAX validation
*/
public abstract class AbstractValidateBean extends AbstractRemoteBean {
protected String validate;
protected String ajaxAfterValidation;
public AbstractValidateBean(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
}
public void evaluateExtraParams() {
super.evaluateExtraParams();
if (validate != null)
addParameter("validate", findValue(validate, Boolean.class));
if (ajaxAfterValidation != null)
addParameter("ajaxAfterValidation", findValue(ajaxAfterValidation, Boolean.class));
Form form = (Form) findAncestor(Form.class);
if (form != null)
addParameter("parentTheme", form.getTheme());
}
@StrutsTagAttribute(description = "Perform Ajax calidation. 'ajaxValidation' interceptor must be applied to action", type="Boolean",
defaultValue = "false")
public void setValidate(String validate) {
this.validate = validate;
}
@StrutsTagAttribute(description = "Make an asynchronous request if validation succeeds. Only valid is 'validate' is 'true'", type="Boolean",
defaultValue = "false")
public void setAjaxAfterValidation(String ajaxAfterValidation) {
this.ajaxAfterValidation = ajaxAfterValidation;
}
}
@@ -23,6 +23,7 @@ package org.apache.struts2.dojo.components;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.Form;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
@@ -90,7 +91,7 @@ import com.opensymphony.xwork2.util.ValueStack;
*/
@StrutsTag(name="a", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.AnchorTag", description="Renders an HTML anchor element that when clicked calls a URL via remote XMLHttpRequest and updates " +
"its targets content")
public class Anchor extends AbstractRemoteCallUIBean {
public class Anchor extends AbstractValidateBean {
public static final String OPEN_TEMPLATE = "a";
public static final String TEMPLATE = "a-close";
public static final String COMPONENT_NAME = Anchor.class.getName();
@@ -112,7 +113,7 @@ public class Anchor extends AbstractRemoteCallUIBean {
public void evaluateExtraParams() {
super.evaluateExtraParams();
if(targets != null)
if (targets != null)
addParameter("targets", findString(targets));
}
@@ -55,7 +55,7 @@ import com.opensymphony.xwork2.util.ValueStack;
*/
@StrutsTag(name="bind", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.BindTag", description="Attach event listeners to elements to make AJAX calls")
@StrutsTagSkipInheritance
public class Bind extends AbstractRemoteCallUIBean {
public class Bind extends AbstractValidateBean {
public static final String TEMPLATE = "bind-close";
public static final String OPEN_TEMPLATE = "bind";
@@ -78,11 +78,11 @@ public class Bind extends AbstractRemoteCallUIBean {
public void evaluateExtraParams() {
super.evaluateExtraParams();
if(targets != null)
if (targets != null)
addParameter("targets", findString(targets));
if(sources != null)
if (sources != null)
addParameter("sources", findString(sources));
if(events != null)
if (events != null)
addParameter("events", findString(events));
}
@@ -112,6 +112,8 @@ public class Bind extends AbstractRemoteCallUIBean {
return "ajax";
}
//these attributes are overwritten here just for the TLD generation
@StrutsTagAttribute(description="Topic that will trigger the remote call")
public void setListenTopics(String listenTopics) {
this.listenTopics = listenTopics;
@@ -221,4 +223,16 @@ public class Bind extends AbstractRemoteCallUIBean {
public void setHighlightDuration(String highlightDuration) {
this.highlightDuration = highlightDuration;
}
@StrutsTagAttribute(description = "Perform Ajax calidation. 'ajaxValidation' interceptor must be applied to action", type="Boolean",
defaultValue = "false")
public void setValidate(String validate) {
this.validate = validate;
}
@StrutsTagAttribute(description = "Make an asynchronous request if validation succeeds. Only valid is 'validate' is 'true'", type="Boolean",
defaultValue = "false")
public void setAjaxAfterValidation(String ajaxAfterValidation) {
this.ajaxAfterValidation = ajaxAfterValidation;
}
}
@@ -59,7 +59,7 @@ import com.opensymphony.xwork2.util.ValueStack;
*
*/
@StrutsTag(name="div", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.DivTag", description="Render HTML div providing content from remote call via AJAX")
public class Div extends AbstractRemoteCallUIBean {
public class Div extends AbstractRemoteBean {
public static final String TEMPLATE = "div";
public static final String TEMPLATE_CLOSE = "div-close";
@@ -1,53 +0,0 @@
/*
* "$Id$"
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2.dojo.components;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
import com.opensymphony.xwork2.util.ValueStack;
/**
* TODO
*
*/
@StrutsTag(name="form", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.FormTag", description="Renders an input form")
public class Form extends org.apache.struts2.components.Form {
public Form(ValueStack stack, HttpServletRequest request,
HttpServletResponse response) {
super(stack, request, response);
}
@Override
@StrutsTagSkipInheritance
public void setTheme(String theme) {
super.setTheme(theme);
}
@Override
public String getTheme() {
return "ajax";
}
}
@@ -21,7 +21,7 @@
package org.apache.struts2.dojo.components;
public interface RemoteUICallBean {
public interface RemoteBean {
void setListenTopics(String topics);
@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.components.Form;
import org.apache.struts2.components.FormButton;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
@@ -93,7 +94,7 @@ import com.opensymphony.xwork2.util.ValueStack;
*
*/
@StrutsTag(name="submit", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.SubmitTag", description="Render a submit button")
public class Submit extends FormButton implements RemoteUICallBean {
public class Submit extends FormButton implements RemoteBean {
private static final Log LOG = LogFactory.getLog(Submit.class);
@@ -118,7 +119,9 @@ public class Submit extends FormButton implements RemoteUICallBean {
protected String errorNotifyTopics;
protected String highlightColor;
protected String highlightDuration;
protected String validate;
protected String ajaxAfterValidation;
public Submit(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
}
@@ -180,6 +183,19 @@ public class Submit extends FormButton implements RemoteUICallBean {
addParameter("highlightColor", findString(highlightColor));
if (highlightDuration != null)
addParameter("highlightDuration", findString(highlightDuration));
Boolean validateValue = false;
if (validate != null) {
validateValue = (Boolean) findValue(validate, Boolean.class);
addParameter("validate", validateValue);
}
Form form = (Form) findAncestor(Form.class);
if (form != null)
addParameter("parentTheme", form.getTheme());
if (ajaxAfterValidation != null)
addParameter("ajaxAfterValidation", findValue(ajaxAfterValidation, Boolean.class));
}
@Override
@@ -353,4 +369,16 @@ public class Submit extends FormButton implements RemoteUICallBean {
public void setHighlightDuration(String highlightDuration) {
this.highlightDuration = highlightDuration;
}
@StrutsTagAttribute(description = "Perform Ajax calidation. 'ajaxValidation' interceptor must be applied to action", type="Boolean",
defaultValue = "false")
public void setValidate(String validate) {
this.validate = validate;
}
@StrutsTagAttribute(description = "Make an asynchronous request if validation succeeds. Only valid is 'validate' is 'true'", type="Boolean",
defaultValue = "false")
public void setAjaxAfterValidation(String ajaxAfterValidation) {
this.ajaxAfterValidation = ajaxAfterValidation;
}
}
@@ -12,7 +12,6 @@ import org.apache.struts2.dojo.views.velocity.components.AutocompleterDirective;
import org.apache.struts2.dojo.views.velocity.components.BindDirective;
import org.apache.struts2.dojo.views.velocity.components.DateTimePickerDirective;
import org.apache.struts2.dojo.views.velocity.components.DivDirective;
import org.apache.struts2.dojo.views.velocity.components.FormDirective;
import org.apache.struts2.dojo.views.velocity.components.HeadDirective;
import org.apache.struts2.dojo.views.velocity.components.SubmitDirective;
import org.apache.struts2.dojo.views.velocity.components.TabbedPanelDirective;
@@ -40,7 +39,6 @@ public class DojoTagLibrary implements TagLibrary {
TabbedPanelDirective.class,
TreeDirective.class,
TreeNodeDirective.class,
FormDirective.class,
HeadDirective.class,
BindDirective.class
};
@@ -18,7 +18,6 @@ public class DojoModels {
protected DivModel div;
protected AnchorModel a;
protected SubmitModel submit;
protected FormModel form;
protected BindModel bind;
private ValueStack stack;
@@ -47,14 +46,6 @@ public class DojoModels {
return dateTimePicker;
}
public FormModel getForm() {
if (form == null) {
form = new FormModel(stack, req, res);
}
return form;
}
public AutocompleterModel getAutocompleter() {
if (autocompleter == null) {
autocompleter = new AutocompleterModel(stack, req, res);
@@ -63,7 +54,7 @@ public class DojoModels {
return autocompleter;
}
public TabbedPanelModel getTabbedpanelModel() {
public TabbedPanelModel getTabbedpanel() {
if (tabbedPanel == null) {
tabbedPanel = new TabbedPanelModel(stack, req, res);
}
@@ -1,44 +0,0 @@
/*
* "$Id$"
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2.dojo.views.freemarker.tags;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.Component;
import org.apache.struts2.dojo.components.Form;
import org.apache.struts2.views.freemarker.tags.TextFieldModel;
import com.opensymphony.xwork2.util.ValueStack;
/**
* @see Form
*/
public class FormModel extends TextFieldModel {
public FormModel(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
super(stack, req, res);
}
protected Component getBean() {
return new Form(stack, req, res);
}
}
@@ -17,10 +17,10 @@
*/
package org.apache.struts2.dojo.views.jsp.ui;
import org.apache.struts2.dojo.components.RemoteUICallBean;
import org.apache.struts2.dojo.components.RemoteBean;
import org.apache.struts2.views.jsp.ui.AbstractClosingTag;
public abstract class AbstractRemoteCallUITag extends AbstractClosingTag {
public abstract class AbstractRemoteTag extends AbstractClosingTag {
protected String href;
protected String listenTopics;
@@ -43,7 +43,7 @@ public abstract class AbstractRemoteCallUITag extends AbstractClosingTag {
protected void populateParams() {
super.populateParams();
RemoteUICallBean remote = (RemoteUICallBean) component;
RemoteBean remote = (RemoteBean) component;
remote.setHref(href);
remote.setListenTopics(listenTopics);
remote.setLoadingText(loadingText);
@@ -0,0 +1,45 @@
/*
* $Id$
*
* Copyright 2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.struts2.dojo.views.jsp.ui;
import org.apache.struts2.dojo.components.AbstractValidateBean;
/**
* @see AbstractValidateTag
*/
public abstract class AbstractValidateTag extends AbstractRemoteTag {
protected String validate;
protected String ajaxAfterValidation;
protected void populateParams() {
super.populateParams();
AbstractValidateBean validateBean = (AbstractValidateBean) component;
validateBean.setValidate(validate);
validateBean.setAjaxAfterValidation(ajaxAfterValidation);
}
public void setAjaxAfterValidation(String ajaxAfterValidation) {
this.ajaxAfterValidation = ajaxAfterValidation;
}
public void setValidate(String validate) {
this.validate = validate;
}
}
@@ -31,13 +31,12 @@ import com.opensymphony.xwork2.util.ValueStack;
/**
* @see Anchor
*/
public class AnchorTag extends AbstractRemoteCallUITag {
public class AnchorTag extends AbstractValidateTag {
private static final long serialVersionUID = -1034616578492431113L;
protected String targets;
protected String preInvokeJS;
public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
return new Anchor(stack, req, res);
}
@@ -47,6 +46,7 @@ public class AnchorTag extends AbstractRemoteCallUITag {
Anchor link = (Anchor) component;
link.setTargets(targets);
link.setValidate(validate);
}
public void setTargets(String targets) {
@@ -28,11 +28,11 @@ import org.apache.struts2.dojo.components.Bind;
import com.opensymphony.xwork2.util.ValueStack;
public class BindTag extends AbstractRemoteCallUITag {
public class BindTag extends AbstractValidateTag {
protected String targets;
protected String sources;
protected String events;
public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
return new Bind(stack, req, res);
}
@@ -28,7 +28,7 @@ import org.apache.struts2.dojo.components.Div;
import com.opensymphony.xwork2.util.ValueStack;
public class DivTag extends AbstractRemoteCallUITag {
public class DivTag extends AbstractRemoteTag {
private static final long serialVersionUID = 5309231035916461758L;
@@ -1,39 +0,0 @@
/*
* "$Id$"
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2.dojo.views.jsp.ui;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.Component;
import org.apache.struts2.dojo.components.Form;
import com.opensymphony.xwork2.util.ValueStack;
public class FormTag extends org.apache.struts2.views.jsp.ui.FormTag{
@Override
public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
return new Form(stack, req, res);
}
}
@@ -59,7 +59,9 @@ public class SubmitTag extends AbstractUITag {
protected String errorNotifyTopics;
protected String highlightColor;
protected String highlightDuration;
protected String validate;
protected String ajaxAfterValidation;
public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
return new Submit(stack, req, res);
}
@@ -91,6 +93,8 @@ public class SubmitTag extends AbstractUITag {
submit.setErrorNotifyTopics(errorNotifyTopics);
submit.setHighlightColor(highlightColor);
submit.setHighlightDuration(highlightDuration);
submit.setValidate(validate);
submit.setAjaxAfterValidation(ajaxAfterValidation);
}
public void setAction(String action) {
@@ -188,4 +192,12 @@ public class SubmitTag extends AbstractUITag {
public void setHighlightDuration(String highlightDuration) {
this.highlightDuration = highlightDuration;
}
public void setValidate(String validate) {
this.validate = validate;
}
public void setAjaxAfterValidation(String ajaxAfterValidation) {
this.ajaxAfterValidation = ajaxAfterValidation;
}
}
@@ -1,38 +0,0 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2.dojo.views.velocity.components;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.Component;
import org.apache.struts2.dojo.components.Form;
import com.opensymphony.xwork2.util.ValueStack;
/**
* @see Form
*/
public class FormDirective {
protected Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
return new Form(stack, req, res);
}
}
@@ -42,7 +42,10 @@ dojo.widget.defineWidget(
highlightColor : "",
highlightDuration : 2000,
validate : false,
ajaxAfterValidation : false,
postCreate : function() {
var self = this;
@@ -149,38 +152,57 @@ dojo.widget.defineWidget(
});
}
},
bindHandler : function(type, data, e) {
//hide indicator
dojo.html.hide(this.indicator);
//publish topics
this.notify(data, type, e);
if(type == "load") {
if(this.executeScripts) {
//update targets content
var parsed = this.parse(data);
//eval scripts
if(parsed.scripts && parsed.scripts.length > 0) {
var scripts = "";
for(var i = 0; i < parsed.scripts.length; i++){
scripts += parsed.scripts[i];
}
(new Function('_container_', scripts+'; return this;'))(this);
}
this.setContent(parsed.text);
}
else {
this.setContent(data);
}
this.highlight();
} else {
if(this.showError) {
var message = dojo.string.isBlank(this.errorText) ? e.message : this.errorText;
this.setContent(message);
}
}
//hide indicator
dojo.html.hide(this.indicator);
//publish topics
this.notify(data, type, e);
if(type == "load") {
if(this.validate) {
StrutsUtils.clearValidationErrors(this.formNode);
//validation is active for this action
var errors = StrutsUtils.getValidationErrors(data);
if(errors && errors.fieldErrors) {
//validation failed
StrutsUtils.showValidationErrors(this.formNode, errors);
return;
} else {
//validation passed
if(!this.ajaxAfterValidation && this.formNode) {
//regular submit
this.formNode.submit();
return;
}
}
}
// no validation or validation passed
if(this.executeScripts) {
//update targets content
var parsed = this.parse(data);
//eval scripts
if(parsed.scripts && parsed.scripts.length > 0) {
var scripts = "";
for(var i = 0; i < parsed.scripts.length; i++){
scripts += parsed.scripts[i];
}
(new Function('_container_', scripts+'; return this;'))(this);
}
this.setContent(parsed.text);
}
else {
this.setContent(data);
}
this.highlight();
} else {
if(this.showError) {
var message = dojo.string.isBlank(this.errorText) ? e.message : this.errorText;
this.setContent(message);
}
}
},
notify : function(data, type, e) {
@@ -254,8 +276,9 @@ dojo.widget.defineWidget(
}
//if there is a parent form, and it has a "onsubmit"
//execute it, validation is usually there
if(this.formNode && this.formNode.onsubmit != null) {
//execute it, validation is usually there, except is validation == true
//on which case it is ajax validation, instead of client side
if(!this.validate && this.formNode && this.formNode.onsubmit != null) {
var makeRequest = this.formNode.onsubmit.call(evt);
if(makeRequest != null && !makeRequest) {
this.log("Request canceled by 'onsubmit' of the form");
@@ -268,9 +291,14 @@ dojo.widget.defineWidget(
if(this.showLoading) {
this.setContent(this.loadingText);
}
var tmpHref = this.href;
if(!this.ajaxAfterValidation) {
tmpHref = tmpHref + (tmpHref.indexOf("?") > -1 ? "&" : "?") + "validateOnly=true";
}
dojo.io.bind({
url: this.href,
url: tmpHref,
useCache: false,
preventCache: true,
formNode: self.formNode,
File diff suppressed because it is too large Load Diff
@@ -22094,7 +22094,10 @@ dojo.widget.defineWidget(
highlightColor : "",
highlightDuration : 2000,
validate : false,
ajaxAfterValidation : false,
postCreate : function() {
var self = this;
@@ -22201,38 +22204,57 @@ dojo.widget.defineWidget(
});
}
},
bindHandler : function(type, data, e) {
//hide indicator
dojo.html.hide(this.indicator);
//publish topics
this.notify(data, type, e);
if(type == "load") {
if(this.executeScripts) {
//update targets content
var parsed = this.parse(data);
//eval scripts
if(parsed.scripts && parsed.scripts.length > 0) {
var scripts = "";
for(var i = 0; i < parsed.scripts.length; i++){
scripts += parsed.scripts[i];
}
(new Function('_container_', scripts+'; return this;'))(this);
}
this.setContent(parsed.text);
}
else {
this.setContent(data);
}
this.highlight();
} else {
if(this.showError) {
var message = dojo.string.isBlank(this.errorText) ? e.message : this.errorText;
this.setContent(message);
}
}
//hide indicator
dojo.html.hide(this.indicator);
//publish topics
this.notify(data, type, e);
if(type == "load") {
if(this.validate) {
StrutsUtils.clearValidationErrors(this.formNode);
//validation is active for this action
var errors = StrutsUtils.getValidationErrors(data);
if(errors && errors.fieldErrors) {
//validation failed
StrutsUtils.showValidationErrors(this.formNode, errors);
return;
} else {
//validation passed
if(!this.ajaxAfterValidation && this.formNode) {
//regular submit
this.formNode.submit();
return;
}
}
}
// no validation or validation passed
if(this.executeScripts) {
//update targets content
var parsed = this.parse(data);
//eval scripts
if(parsed.scripts && parsed.scripts.length > 0) {
var scripts = "";
for(var i = 0; i < parsed.scripts.length; i++){
scripts += parsed.scripts[i];
}
(new Function('_container_', scripts+'; return this;'))(this);
}
this.setContent(parsed.text);
}
else {
this.setContent(data);
}
this.highlight();
} else {
if(this.showError) {
var message = dojo.string.isBlank(this.errorText) ? e.message : this.errorText;
this.setContent(message);
}
}
},
notify : function(data, type, e) {
@@ -22306,8 +22328,9 @@ dojo.widget.defineWidget(
}
//if there is a parent form, and it has a "onsubmit"
//execute it, validation is usually there
if(this.formNode && this.formNode.onsubmit != null) {
//execute it, validation is usually there, except is validation == true
//on which case it is ajax validation, instead of client side
if(!this.validate && this.formNode && this.formNode.onsubmit != null) {
var makeRequest = this.formNode.onsubmit.call(evt);
if(makeRequest != null && !makeRequest) {
this.log("Request canceled by 'onsubmit' of the form");
@@ -22320,9 +22343,14 @@ dojo.widget.defineWidget(
if(this.showLoading) {
this.setContent(this.loadingText);
}
var tmpHref = this.href;
if(!this.ajaxAfterValidation) {
tmpHref = tmpHref + (tmpHref.indexOf("?") > -1 ? "&" : "?") + "validateOnly=true";
}
dojo.io.bind({
url: this.href,
url: tmpHref,
useCache: false,
preventCache: true,
formNode: self.formNode,
@@ -1,4 +1,14 @@
<a dojoType="struts:BindAnchor"
<#if parameters.validate?exists>
validate="${parameters.validate?string?html}"<#rt/>
<#else>
validate="false"<#rt/>
</#if>
<#if parameters.ajaxAfterValidation?exists>
ajaxAfterValidation="${parameters.ajaxAfterValidation?string?html}"<#rt/>
<#else>
ajaxAfterValidation="false"
</#if>
<#include "/${parameters.templateDir}/ajax/ajax-common.ftl" />
<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
<#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
@@ -1,52 +1,74 @@
<script language="JavaScript" type="text/javascript">
dojo.addOnLoad(function() {
dojo.widget.createWidget("struts:BindEvent", {
"sources": "${parameters.sources?html}",
"events": "${parameters.events?html}",
"sources": "${parameters.sources?html}",<#rt/>
"events": "${parameters.events?html}",<#rt/>
<#if parameters.id?if_exists != "">
"id": "${parameters.id?html}",
"id": "${parameters.id?html}",<#rt/>
</#if>
<#if parameters.formId?if_exists != "">
"formId": "${parameters.formId?html}",
"formId": "${parameters.formId?html}",<#rt/>
</#if>
<#if parameters.formFilter?if_exists != "">
"formFilter": "${parameters.formFilter?html}",
"formFilter": "${parameters.formFilter?html}",<#rt/>
</#if>
<#if parameters.href?if_exists != "">
"href": "${parameters.href}",
"href": "${parameters.href}",<#rt/>
</#if>
<#if parameters.loadingText?if_exists != "">
"loadingText" : "${parameters.loadingText?html}",
"loadingText" : "${parameters.loadingText?html}",<#rt/>
</#if>
<#if parameters.errorText?if_exists != "">
"errorText" : "${parameters.errorText?html}",
"errorText" : "${parameters.errorText?html}",<#rt/>
</#if>
<#if parameters.executeScripts?exists>
"executeScripts": "${parameters.executeScripts?string?html}",
"executeScripts": ${parameters.executeScripts?string?html},<#rt/>
</#if>
<#if parameters.listenTopics?if_exists != "">
"listenTopics": "${parameters.listenTopics?html}",
"listenTopics": "${parameters.listenTopics?html}",<#t/>
</#if>
<#if parameters.notifyTopics?if_exists != "">
"notifyTopics": "${parameters.notifyTopics?html}",
"notifyTopics": "${parameters.notifyTopics?html}",<#t/>
</#if>
<#if parameters.beforeNotifyTopics?if_exists != "">
"beforeNotifyTopics": "${parameters.beforeNotifyTopics?html}",<#t/>
</#if>
<#if parameters.afterNotifyTopics?if_exists != "">
"afterNotifyTopics": "${parameters.afterNotifyTopics?html}",<#t/>
</#if>
<#if parameters.errorNotifyTopics?if_exists != "">
"errorNotifyTopics": "${parameters.errorNotifyTopics?html}",<#t/>
</#if>
<#if parameters.targets?if_exists != "">
"targets": "${parameters.targets?html}",
"targets": "${parameters.targets?html}",<#t/>
</#if>
<#if parameters.indicator?if_exists != "">
"indicator": "${parameters.indicator?html}",
"indicator": "${parameters.indicator?html}",<#t/>
</#if>
<#if parameters.showErrorTransportText?exists>
"showError": "${parameters.showErrorTransportText?string?html}",
"showError": ${parameters.showErrorTransportText?string?html},<#t/>
</#if>
<#if parameters.showLoadingText?exists>
"showLoading": ${parameters.showLoadingText?string?html},<#t/>
</#if>
<#if parameters.handler?if_exists != "">
"handler": "${parameters.handler?html}"
"handler": "${parameters.handler?html}",<#t/>
</#if>
<#if parameters.highlightColor?if_exists != "">
"highlightColor" : "${parameters.highlightColor?html}"<#rt/>
"highlightColor" : "${parameters.highlightColor?html}",<#t/>
</#if>
<#if parameters.highlightDuration?if_exists != "">
"highlightDuration" : "${parameters.highlightDuration?html}"<#rt/>
"highlightDuration" : ${parameters.highlightDuration?html},<#t/>
</#if>
<#if parameters.validate?exists>
"validate": ${parameters.validate?string?html},<#t/>
<#else>
"validate": false,
</#if>
<#if parameters.ajaxAfterValidation?exists>
"ajaxAfterValidation": ${parameters.ajaxAfterValidation?string?html},<#t/>
<#else>
"ajaxAfterValidation": false,
</#if>
});
});
@@ -1,87 +0,0 @@
</table>
<#if (parameters.customOnsubmitEnabled?default(false))>
<script type="text/javascript">
<#--
Enable auto-select of optiontransferselect tag's entries upon containing form's
submission.
-->
dojo.require("dojo.event.connect");
<#if (parameters.optiontransferselectIds?if_exists?size > 0)>
var containingForm = document.getElementById("${parameters.id}");
<#assign selectObjIds = parameters.optiontransferselectIds.keySet() />
<#list selectObjIds as selectObjectId>
dojo.event.connect(containingForm, "onsubmit",
function(evt) {
var selectObj = document.getElementById("${selectObjectId}");
<#if parameters.optiontransferselectIds.get(selectObjectId)?exists>
<#assign selectTagHeaderKey = parameters.optiontransferselectIds.get(selectObjectId)/>
selectAllOptionsExceptSome(selectObj, "key", "${selectTagHeaderKey}");
<#else>
selectAllOptionsExceptSome(selectObj, "key", "");
</#if>
});
</#list>
</#if>
<#if (parameters.inputtransferselectIds?if_exists?size > 0)>
var containingForm = document.getElementById("${parameters.id}");
<#assign selectObjIds = parameters.inputtransferselectIds.keySet() />
<#list selectObjIds as selectObjectId>
dojo.event.connect(containingForm, "onsubmit",
function(evt) {
var selectObj = document.getElementById("${selectObjectId}");
<#if parameters.inputtransferselectIds.get(selectObjectId)?exists>
<#assign selectTagHeaderKey = parameters.inputtransferselectIds.get(selectObjectId)/>
selectAllOptionsExceptSome(selectObj, "key", "${selectTagHeaderKey}");
<#else>
selectAllOptionsExceptSome(selectObj, "key", "");
</#if>
});
</#list>
</#if>
<#if (parameters.optiontransferselectDoubleIds?if_exists?size > 0)>
var containingForm = document.getElementById("${parameters.id}");
<#assign selectDoubleObjIds = parameters.optiontransferselectDoubleIds.keySet() />
<#list selectDoubleObjIds as selectObjId>
dojo.event.connect(containingForm, "onsubmit",
function(evt) {
var selectObj = document.getElementById("${selectObjId}");
<#if parameters.optiontransferselectDoubleIds.get(selectObjId)?exists>
<#assign selectTagHeaderKey = parameters.optiontransferselectDoubleIds.get(selectObjId)/>
selectAllOptionsExceptSome(selectObj, "key", "${selectTagHeaderKey}");
<#else>
selectAllOptionsExceptSome(selectObj, "key", "");
</#if>
});
</#list>
</#if>
<#--
Enable auto-select of all elements of updownselect tag upon its containing form
submission
-->
<#if (parameters.updownselectIds?if_exists?size > 0)>
var containingForm = document.getElementById("${parameters.id}");
<#assign tmpIds = parameters.updownselectIds.keySet() />
<#list tmpIds as tmpId>
dojo.event.connect(containingForm, "onsubmit",
function(evt) {
var updownselectObj = document.getElementById("${tmpId}");
<#if parameters.updownselectIds.get(tmpId)?exists>
<#assign tmpHeaderKey = parameters.updownselectIds.get(tmpId) />
selectAllOptionsExceptSome(updownselectObj, "key", "${tmpHeaderKey}");
<#else>
selectAllOptionsExceptSome(updownselectObj, "key", "");
</#if>
});
</#list>
</#if>
</script>
</#if>
<#--
Code that will add javascript needed for tooltips
--><#t/>
<#lt/><!-- javascript that is needed for tooltips -->
<#lt/><script type="text/javascript">dojo.require("dojo.widget.Tooltip");dojo.require("dojo.fx.html");</script>
</form>
@@ -1,40 +0,0 @@
<#if parameters.validate?exists>
<script type="text/javascript" src="${base}/struts/validationClient.js"></script>
<script type="text/javascript" src="${base}/dwr/interface/validator.js"></script>
<script type="text/javascript" src="${base}/dwr/engine.js"></script>
<script type="text/javascript" src="${base}/struts/ajax/validation.js"></script>
<script type="text/javascript" src="${base}/struts/ajax/validation.js"></script>
</#if>
<form<#rt/>
<#if parameters.namespace?exists>
namespace="${parameters.namespace?html}"<#rt/>
</#if>
<#if parameters.id?exists>
id="${parameters.id?html}"<#rt/>
</#if>
<#if parameters.name?exists>
name="${parameters.name?html}"<#rt/>
</#if>
<#if parameters.action?exists>
action="${parameters.action?html}"<#rt/>
</#if>
<#if parameters.target?exists>
target="${parameters.target?html}"<#rt/>
</#if>
<#if parameters.method?exists>
method="${parameters.method?html}"<#rt/>
</#if>
<#if parameters.enctype?exists>
enctype="${parameters.enctype?html}"<#rt/>
</#if>
<#if parameters.cssClass?exists>
class="${parameters.cssClass?html}"<#rt/>
</#if>
<#if parameters.acceptcharset?exists>
accept-charset="${parameters.acceptcharset?html}"<#rt/>
</#if>
<#if parameters.cssStyle?exists>
style="${parameters.cssStyle?html}"<#rt/>
</#if>
${tag.addParameter("ajaxSubmit", "true")}
>
@@ -7,8 +7,8 @@
baseRelativePath: "<@s.url value='${parameters.baseRelativePath}' includeParams='none' encode='false' />",
baseScriptUri: "<@s.url value='${parameters.baseRelativePath}' includeParams='none' encode='false' />",
<#else>
baseRelativePath: "<@s.url value='/struts/dojo/' includeParams='none' encode='false' />",
baseScriptUri: "<@s.url value='/struts/dojo/' includeParams='none' encode='false' />",
baseRelativePath: "${base}/struts/dojo/",
baseScriptUri: "${base}/struts/dojo/",
</#if>
<#if parameters.locale?if_exists != "">
locale: "${parameters.locale}",
@@ -40,10 +40,14 @@
src="<@s.url value='${parameters.baseRelativePath}/${profile}${dojoFile}' includeParams='none' encode='false' />"></script>
<#else>
<script language="JavaScript" type="text/javascript"
src="<@s.url value='/struts/dojo/${profile}${dojoFile}' includeParams='none' encode='false' />"></script>
src="${base}/struts/dojo/${profile}${dojoFile}"></script>
</#if>
<script language="JavaScript" type="text/javascript"
src="<@s.url value='/struts/ajax/dojoRequire.js' includeParams='none' encode='false' />"></script>
src="${base}/struts/ajax/dojoRequire.js"></script>
<script language="JavaScript" type="text/javascript"
src="<@s.url value='/struts/CommonFunctions.js' includeParams='none' encode='false'/>"></script>
src="${base}/struts/CommonFunctions.js"></script>
<link rel="stylesheet" href="${base}/struts/xhtml/styles.css" type="text/css"/>
<script language="JavaScript" src="${base}/struts/utils.js" type="text/javascript"></script>
<script language="JavaScript" src="${base}/struts/xhtml/validation.js" type="text/javascript"></script>
<script language="JavaScript" src="${base}/struts/css_xhtml/validation.js" type="text/javascript"></script>
@@ -1,3 +1,25 @@
<#if parameters.parentTheme?default('') == 'xhtml'>
<tr>
<td colspan="2"><div <#rt/>
<#if parameters.align?exists>
align="${parameters.align?html}"<#t/>
</#if>
><#t/>
<#elseif parameters.parentTheme?default('') == 'css_xhtml'>
<#if parameters.labelposition?default("top") == 'top'>
<div <#rt/>
<#else>
<span <#rt/>
</#if>
<#if parameters.align?exists>
align="${parameters.align?html}"<#t/>
</#if>
<#if parameters.id?exists>
id="wwctrl_${parameters.id}"<#rt/>
</#if>
><#t/>
</#if>
<#if parameters.type?exists && parameters.type=="button">
<input type="button" dojoType="struts:Bind" events="onclick"<#rt/>
<#include "/${parameters.templateDir}/ajax/ajax-common.ftl"/>
@@ -25,8 +47,28 @@
<#if parameters.value?if_exists != "">
value="${parameters.value?html}"<#rt/>
</#if>
<#if parameters.validate?exists>
validate="${parameters.validate?string?html}"<#rt/>
<#else>
validate="false"<#rt/>
</#if>
<#if parameters.ajaxAfterValidation?exists>
ajaxAfterValidation="${parameters.ajaxAfterValidation?string?html}"<#rt/>
<#else>
ajaxAfterValidation="false"
</#if>
<#include "/${parameters.templateDir}/ajax/ajax-common.ftl"/>
<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
<#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
/>
</#if>
<#if parameters.parentTheme?default('') == 'xhtml'>
</div><#t/>
<#include "/${parameters.templateDir}/xhtml/controlfooter.ftl" />
<#elseif parameters.parentTheme?default('') == 'css_xhtml'>
<#if parameters.labelposition?default("top") == 'top'>
</div> <#t/>
<#else>
</span> <#t/>
</#if>
</#if>
@@ -1,26 +0,0 @@
var strutsValidator = new ValidationClient("$!base/validation");
strutsValidator.onErrors = function(input, errors) {
var form = input.form;
clearErrorMessages(form);
clearErrorLabels(form);
if (errors.fieldErrors) {
for (var fieldName in errors.fieldErrors) {
if (form.elements[fieldName].touched) {
for (var i = 0; i < errors.fieldErrors[fieldName].length; i++) {
addError(form.elements[fieldName], errors.fieldErrors[fieldName][i]);
}
}
}
}
}
function validate(element) {
// mark the element as touch
element.touched = true;
var namespace = element.form.attributes['namespace'].nodeValue;
var actionName = element.form.attributes['name'].nodeValue;
strutsValidator.validate(element, namespace, actionName);
}
@@ -50,6 +50,8 @@ public class AnchorTest extends AbstractUITagTest {
tag.setErrorNotifyTopics("l");
tag.setHighlightColor("m");
tag.setHighlightDuration("n");
tag.setValidate("true");
tag.setAjaxAfterValidation("true");
tag.doStartTag();
tag.doEndTag();
@@ -26,6 +26,7 @@ public class BindTest extends AbstractUITagTest {
tag.setEvents("o");
tag.setHighlightColor("p");
tag.setHighlightDuration("q");
tag.setValidate("true");
tag.doStartTag();
tag.doEndTag();
@@ -46,6 +46,8 @@ public class SubmitAjaxTest extends AbstractUITagTest {
tag.setErrorNotifyTopics("m");
tag.setHighlightColor("n");
tag.setHighlightDuration("o");
tag.setValidate("true");
tag.setAjaxAfterValidation("true");
tag.doStartTag();
tag.doEndTag();
@@ -73,6 +75,7 @@ public class SubmitAjaxTest extends AbstractUITagTest {
tag.setNotifyTopics("k");
tag.setIndicator("l");
tag.setErrorNotifyTopics("m");
tag.setValidate("true");
tag.doStartTag();
tag.doEndTag();
@@ -101,6 +104,7 @@ public class SubmitAjaxTest extends AbstractUITagTest {
tag.setNotifyTopics("k");
tag.setIndicator("l");
tag.setErrorNotifyTopics("m");
tag.setValidate("true");
tag.doStartTag();
tag.doEndTag();
@@ -9,11 +9,17 @@
"errorText":"d",
"listenTopics":"e",
"notifyTopics":"k",
"beforeNotifyTopics":"f",
"afterNotifyTopics":"g",
"errorNotifyTopics":"m",
"indicator":"l",
"showError":"true",
"handler":"h"
"highlightColor":"p"
"highlightDuration":"q"
"showError":true,
"showLoading":true,
"handler":"h",
"highlightColor":"p",
"highlightDuration":q,
"validate": true,
"ajaxAfterValidation":false,
});
});
</script>
@@ -21,4 +21,15 @@
</script>
<script language="JavaScript" type="text/javascript" src="/struts/CommonFunctions.js">
</script>
<link rel="stylesheet" href="/struts/xhtml/styles.css" type="text/css"/>
<script language="JavaScript" src="/struts/utils.js" type="text/javascript">
</script>
<script language="JavaScript" src="/struts/xhtml/validation.js" type="text/javascript">
</script>
<script language="JavaScript"src="/struts/css_xhtml/validation.js" type="text/javascript">
</script>
@@ -21,4 +21,15 @@
</script>
<script language="JavaScript" type="text/javascript" src="/struts/CommonFunctions.js">
</script>
<link rel="stylesheet" href="/struts/xhtml/styles.css" type="text/css"/>
<script language="JavaScript" src="/struts/utils.js" type="text/javascript">
</script>
<script language="JavaScript" src="/struts/xhtml/validation.js" type="text/javascript">
</script>
<script language="JavaScript"src="/struts/css_xhtml/validation.js" type="text/javascript">
</script>
@@ -1,5 +1,7 @@
<a
dojoType="struts:BindAnchor"
validate="true"
ajaxAfterValidation="true"
id="mylink"
href="a"
loadingText="d"
@@ -3,6 +3,8 @@
dojoType="struts:Bind"
events="onclick"
value="Submit"
validate="true"
ajaxAfterValidation="true"
id="a"
label="i"
href="b"
@@ -5,6 +5,8 @@
alt="i"
src="j"
value="Submit"
validate="true"
ajaxAfterValidation="false"
id="a"
label="i"
href="b"