diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/AbstractRemoteCallUIBean.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/AbstractRemoteBean.java similarity index 97% rename from plugins/dojo/src/main/java/org/apache/struts2/dojo/components/AbstractRemoteCallUIBean.java rename to plugins/dojo/src/main/java/org/apache/struts2/dojo/components/AbstractRemoteBean.java index 9e8d3057d..4b1e4ba47 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/AbstractRemoteCallUIBean.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/AbstractRemoteBean.java @@ -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); } diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/AbstractValidateBean.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/AbstractValidateBean.java new file mode 100644 index 000000000..abab16543 --- /dev/null +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/AbstractValidateBean.java @@ -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; + } +} \ No newline at end of file diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Anchor.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Anchor.java index ba0f96f7a..6eb60dc61 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Anchor.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Anchor.java @@ -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)); } diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Bind.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Bind.java index 953c43126..bd583821e 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Bind.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Bind.java @@ -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; + } } diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Div.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Div.java index 9724b7fd5..ac2608008 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Div.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Div.java @@ -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"; diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Form.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Form.java deleted file mode 100644 index 25a3305e6..000000000 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Form.java +++ /dev/null @@ -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"; - } -} diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/RemoteUICallBean.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/RemoteBean.java similarity index 98% rename from plugins/dojo/src/main/java/org/apache/struts2/dojo/components/RemoteUICallBean.java rename to plugins/dojo/src/main/java/org/apache/struts2/dojo/components/RemoteBean.java index def35f7d5..5f7e0fa1a 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/RemoteUICallBean.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/RemoteBean.java @@ -21,7 +21,7 @@ package org.apache.struts2.dojo.components; -public interface RemoteUICallBean { +public interface RemoteBean { void setListenTopics(String topics); diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Submit.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Submit.java index 564428a67..fecb5fdef 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Submit.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Submit.java @@ -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; + } } diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/DojoTagLibrary.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/DojoTagLibrary.java index b30bfccea..385de0588 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/DojoTagLibrary.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/DojoTagLibrary.java @@ -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 }; diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/DojoModels.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/DojoModels.java index 8c6cc03f7..454acecbf 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/DojoModels.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/DojoModels.java @@ -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); } diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/FormModel.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/FormModel.java deleted file mode 100644 index 056c10505..000000000 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/FormModel.java +++ /dev/null @@ -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); - } -} \ No newline at end of file diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AbstractRemoteCallUITag.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AbstractRemoteTag.java similarity index 95% rename from plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AbstractRemoteCallUITag.java rename to plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AbstractRemoteTag.java index b33ce380f..8883e403c 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AbstractRemoteCallUITag.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AbstractRemoteTag.java @@ -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); diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AbstractValidateTag.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AbstractValidateTag.java new file mode 100644 index 000000000..6d06e4a1e --- /dev/null +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AbstractValidateTag.java @@ -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; + } + +} diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AnchorTag.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AnchorTag.java index ef0edbddf..0f87b9c98 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AnchorTag.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/AnchorTag.java @@ -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) { diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/BindTag.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/BindTag.java index 154f355ab..c14bf4d07 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/BindTag.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/BindTag.java @@ -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); } diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/DivTag.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/DivTag.java index 7dc844d13..f487ff72d 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/DivTag.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/DivTag.java @@ -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; diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/FormTag.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/FormTag.java deleted file mode 100644 index 08d3ba385..000000000 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/FormTag.java +++ /dev/null @@ -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); - } - -} diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/SubmitTag.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/SubmitTag.java index 6b4242c0e..fcabcf662 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/SubmitTag.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/SubmitTag.java @@ -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; + } } diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/velocity/components/FormDirective.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/velocity/components/FormDirective.java deleted file mode 100644 index 637973894..000000000 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/velocity/components/FormDirective.java +++ /dev/null @@ -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); - } -} diff --git a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js index 5b923719e..f89d9aa6c 100644 --- a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js +++ b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js @@ -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, diff --git a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js index 1f217a80b..1627542a3 100644 --- a/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js +++ b/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js @@ -13599,7 +13599,7 @@ self.addKeyHandler(item[1]?item[1]:item[0].charAt(0),item[2]==undefined?self.KEY }); }}); dojo.provide("struts.widget.Bind"); -dojo.widget.defineWidget("struts.widget.Bind",dojo.widget.HtmlWidget,{widgetType:"Bind",executeScripts:false,targets:"",targetsArray:null,href:"",handler:"",loadingText:"Loading...",errorText:"",showError:true,showLoading:true,listenTopics:"",notifyTopics:"",notifyTopicsArray:null,beforeNotifyTopics:"",beforeNotifyTopicsArray:null,afterNotifyTopics:"",afterNotifyTopicsArray:null,errorNotifyTopics:"",errorNotifyTopicsArray:null,formId:"",formFilter:"",formNode:null,events:"",indicator:"",parseContent:true,highlightColor:"",highlightDuration:2000,postCreate:function(){ +dojo.widget.defineWidget("struts.widget.Bind",dojo.widget.HtmlWidget,{widgetType:"Bind",executeScripts:false,targets:"",targetsArray:null,href:"",handler:"",loadingText:"Loading...",errorText:"",showError:true,showLoading:true,listenTopics:"",notifyTopics:"",notifyTopicsArray:null,beforeNotifyTopics:"",beforeNotifyTopicsArray:null,afterNotifyTopics:"",afterNotifyTopicsArray:null,errorNotifyTopics:"",errorNotifyTopicsArray:null,formId:"",formFilter:"",formNode:null,events:"",indicator:"",parseContent:true,highlightColor:"",highlightDuration:2000,validate:false,ajaxAfterValidation:false,postCreate:function(){ var self=this; if(!dojo.string.isBlank(this.listenTopics)){ this.log("Listening to "+this.listenTopics+" to refresh"); @@ -13683,66 +13683,79 @@ self.log("Unable to find target: "+node); dojo.html.hide(this.indicator); this.notify(data,type,e); if(type=="load"){ +if(this.validate){ +StrutsUtils.clearValidationErrors(this.formNode); +var _b86=StrutsUtils.getValidationErrors(data); +if(_b86&&_b86.fieldErrors){ +StrutsUtils.showValidationErrors(this.formNode,_b86); +return; +}else{ +if(!this.ajaxAfterValidation&&this.formNode){ +this.formNode.submit(); +return; +} +} +} if(this.executeScripts){ -var _b86=this.parse(data); -if(_b86.scripts&&_b86.scripts.length>0){ -var _b87=""; -for(var i=0;i<_b86.scripts.length;i++){ -_b87+=_b86.scripts[i]; +var _b87=this.parse(data); +if(_b87.scripts&&_b87.scripts.length>0){ +var _b88=""; +for(var i=0;i<_b87.scripts.length;i++){ +_b88+=_b87.scripts[i]; } -(new Function("_container_",_b87+"; return this;"))(this); +(new Function("_container_",_b88+"; return this;"))(this); } -this.setContent(_b86.text); +this.setContent(_b87.text); }else{ this.setContent(data); } this.highlight(); }else{ if(this.showError){ -var _b89=dojo.string.isBlank(this.errorText)?e.message:this.errorText; -this.setContent(_b89); +var _b8a=dojo.string.isBlank(this.errorText)?e.message:this.errorText; +this.setContent(_b8a); } } },notify:function(data,type,e){ var self=this; if(this.notifyTopicsArray){ -dojo.lang.forEach(this.notifyTopicsArray,function(_b8e){ +dojo.lang.forEach(this.notifyTopicsArray,function(_b8f){ try{ -dojo.event.topic.publish(_b8e,data,type,e); +dojo.event.topic.publish(_b8f,data,type,e); } catch(ex){ self.log(ex); } }); } -var _b8f=null; +var _b90=null; switch(type){ case "before": -_b8f=this.beforeNotifyTopicsArray; +_b90=this.beforeNotifyTopicsArray; break; case "load": -_b8f=this.afterNotifyTopicsArray; +_b90=this.afterNotifyTopicsArray; break; case "error": -_b8f=this.errorNotifyTopicsArray; +_b90=this.errorNotifyTopicsArray; break; } -this.notifyTo(_b8f,data,type,e); -},notifyTo:function(_b90,data,type,e){ +this.notifyTo(_b90,data,type,e); +},notifyTo:function(_b91,data,type,e){ var self=this; -if(_b90){ -dojo.lang.forEach(_b90,function(_b95){ +if(_b91){ +dojo.lang.forEach(_b91,function(_b96){ try{ -dojo.event.topic.publish(_b95,data,type,e); +dojo.event.topic.publish(_b96,data,type,e); } catch(ex){ self.log(ex); } }); } -},onDownloadStart:function(_b96){ +},onDownloadStart:function(_b97){ if(this.showLoading&&!dojo.string.isBlank(this.loadingText)){ -_b96.text=this.loadingText; +_b97.text=this.loadingText; } },reloadContents:function(evt){ if(!dojo.string.isBlank(this.handler)){ @@ -13751,18 +13764,18 @@ window[this.handler](this,this.domNode); }else{ try{ var self=this; -var _b99={cancel:false}; -this.notify(this.widgetId,"before",_b99); -if(_b99.cancel){ +var _b9a={cancel:false}; +this.notify(this.widgetId,"before",_b9a); +if(_b9a.cancel){ this.log("Request canceled"); return; } if(dojo.string.isBlank(this.href)){ return; } -if(this.formNode&&this.formNode.onsubmit!=null){ -var _b9a=this.formNode.onsubmit.call(evt); -if(_b9a!=null&&!_b9a){ +if(!this.validate&&this.formNode&&this.formNode.onsubmit!=null){ +var _b9b=this.formNode.onsubmit.call(evt); +if(_b9b!=null&&!_b9b){ this.log("Request canceled by 'onsubmit' of the form"); return; } @@ -13771,29 +13784,33 @@ dojo.html.show(this.indicator); if(this.showLoading){ this.setContent(this.loadingText); } -dojo.io.bind({url:this.href,useCache:false,preventCache:true,formNode:self.formNode,formFilter:window[self.formFilter],handler:function(type,data,e){ +var _b9c=this.href; +if(!this.ajaxAfterValidation){ +_b9c=_b9c+(_b9c.indexOf("?")>-1?"&":"?")+"validateOnly=true"; +} +dojo.io.bind({url:_b9c,useCache:false,preventCache:true,formNode:self.formNode,formFilter:window[self.formFilter],handler:function(type,data,e){ dojo.lang.hitch(self,"bindHandler")(type,data,e); },mimetype:"text/html"}); } catch(ex){ if(this.showError){ -var _b9e=dojo.string.isBlank(this.errorText)?ex:this.errorText; -this.setContent(_b9e); +var _ba0=dojo.string.isBlank(this.errorText)?ex:this.errorText; +this.setContent(_ba0); } } } },parse:function(s){ this.log("Parsing: "+s); -var _ba0=[]; -var tmp=[]; var _ba2=[]; -while(_ba0){ -_ba0=s.match(/ -#if> - -<#-- - Code that will add javascript needed for tooltips ---><#t/> - <#lt/> - <#lt/> - diff --git a/plugins/dojo/src/main/resources/template/ajax/form.ftl b/plugins/dojo/src/main/resources/template/ajax/form.ftl deleted file mode 100644 index 25a72f98a..000000000 --- a/plugins/dojo/src/main/resources/template/ajax/form.ftl +++ /dev/null @@ -1,40 +0,0 @@ -<#if parameters.validate?exists> - - - - - -#if> -
-<#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")} -> diff --git a/plugins/dojo/src/main/resources/template/ajax/head.ftl b/plugins/dojo/src/main/resources/template/ajax/head.ftl index 291c93851..7e1b12f8b 100644 --- a/plugins/dojo/src/main/resources/template/ajax/head.ftl +++ b/plugins/dojo/src/main/resources/template/ajax/head.ftl @@ -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' />"> <#else> + src="${base}/struts/dojo/${profile}${dojoFile}"> #if> + src="${base}/struts/ajax/dojoRequire.js"> + src="${base}/struts/CommonFunctions.js"> + + + + \ No newline at end of file diff --git a/plugins/dojo/src/main/resources/template/ajax/submit.ftl b/plugins/dojo/src/main/resources/template/ajax/submit.ftl index 0ce7d4eb3..886c8d434 100644 --- a/plugins/dojo/src/main/resources/template/ajax/submit.ftl +++ b/plugins/dojo/src/main/resources/template/ajax/submit.ftl @@ -1,3 +1,25 @@ +<#if parameters.parentTheme?default('') == 'xhtml'> +