-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from apache/master
update pull
- Loading branch information
Showing
14 changed files
with
736 additions
and
4 deletions.
There are no files selected for viewing
152 changes: 152 additions & 0 deletions
152
apps/showcase/src/main/java/org/apache/struts2/showcase/validation/AjaxFormSubmitAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package org.apache.struts2.showcase.validation; | ||
|
||
import java.sql.Date; | ||
|
||
import com.opensymphony.xwork2.validator.annotations.DateRangeFieldValidator; | ||
import com.opensymphony.xwork2.validator.annotations.EmailValidator; | ||
import com.opensymphony.xwork2.validator.annotations.FieldExpressionValidator; | ||
import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator; | ||
import com.opensymphony.xwork2.validator.annotations.RegexFieldValidator; | ||
import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator; | ||
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator; | ||
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator; | ||
import com.opensymphony.xwork2.validator.annotations.UrlValidator; | ||
|
||
/** | ||
* <!-- START SNIPPET: ajaxFormSubmit --> | ||
*/ | ||
/** | ||
* Example Action that shows how forms can be validated and submitted via AJAX | ||
* only. Form-submit-and-page-reload functionality of browsers is not used for | ||
* this action. | ||
* <p>Some things to note: | ||
* <ul> | ||
* <li>Depends on <code>json-plugin</code>.</li> | ||
* <li>Requires <code>jsonValidationInterceptor</code> to be on stack.</li> | ||
* <li>Uses result type <code>jsonActionRedirect</code>.</li> | ||
* <li>Uses http parameters <code>struts.enableJSONValidation=true</code> and <code>struts.validateOnly=false</code>.</li> | ||
* <li>Uses a customized theme to make sure html elements required as error containers are always present and easily selectable in JS.</li> | ||
* <li>Uses some custom JS code depending on jQuery to issue AJAX request and to render errors in html.</li> | ||
* <li>Shows visual feedback while waiting for AJAX response.</li> | ||
* </ul> | ||
* </p> | ||
* | ||
*/ | ||
public class AjaxFormSubmitAction extends AbstractValidationActionSupport { | ||
|
||
private String requiredValidatorField = null; | ||
private String requiredStringValidatorField = null; | ||
private Integer integerValidatorField = null; | ||
private Date dateValidatorField = null; | ||
private String emailValidatorField = null; | ||
private String urlValidatorField = null; | ||
private String stringLengthValidatorField = null; | ||
private String regexValidatorField = null; | ||
private String fieldExpressionValidatorField = null; | ||
|
||
@Override | ||
public void validate() { | ||
if (hasFieldErrors()) { | ||
addActionError("Errors present!"); | ||
} | ||
} | ||
|
||
public Date getDateValidatorField() { | ||
return dateValidatorField; | ||
} | ||
|
||
@DateRangeFieldValidator( | ||
min="01/01/1990", | ||
max="01/01/2000", | ||
message="must be a min 01-01-1990 max 01-01-2000 if supplied") | ||
public void setDateValidatorField(Date dateValidatorField) { | ||
this.dateValidatorField = dateValidatorField; | ||
} | ||
|
||
public String getEmailValidatorField() { | ||
return emailValidatorField; | ||
} | ||
|
||
@EmailValidator(message="must be a valid email if supplied") | ||
public void setEmailValidatorField(String emailValidatorField) { | ||
this.emailValidatorField = emailValidatorField; | ||
} | ||
|
||
public Integer getIntegerValidatorField() { | ||
return integerValidatorField; | ||
} | ||
|
||
@IntRangeFieldValidator(min="1", max="10", message="must be integer min 1 max 10 if supplied") | ||
public void setIntegerValidatorField(Integer integerValidatorField) { | ||
this.integerValidatorField = integerValidatorField; | ||
} | ||
|
||
public String getRegexValidatorField() { | ||
return regexValidatorField; | ||
} | ||
|
||
@RegexFieldValidator( | ||
regex="[^<>]+", | ||
message="regexValidatorField must match a regexp (.*\\.txt) if specified") | ||
public void setRegexValidatorField(String regexValidatorField) { | ||
this.regexValidatorField = regexValidatorField; | ||
} | ||
|
||
public String getRequiredStringValidatorField() { | ||
return requiredStringValidatorField; | ||
} | ||
|
||
@RequiredStringValidator(trim=true, message="required and must be string") | ||
public void setRequiredStringValidatorField(String requiredStringValidatorField) { | ||
this.requiredStringValidatorField = requiredStringValidatorField; | ||
} | ||
|
||
public String getRequiredValidatorField() { | ||
return requiredValidatorField; | ||
} | ||
|
||
@RequiredFieldValidator(message="required") | ||
public void setRequiredValidatorField(String requiredValidatorField) { | ||
this.requiredValidatorField = requiredValidatorField; | ||
} | ||
|
||
public String getStringLengthValidatorField() { | ||
return stringLengthValidatorField; | ||
} | ||
|
||
@StringLengthFieldValidator( | ||
minLength="2", | ||
maxLength="4", | ||
trim=true, | ||
message="must be a String of a specific greater than 1 less than 5 if specified") | ||
public void setStringLengthValidatorField(String stringLengthValidatorField) { | ||
this.stringLengthValidatorField = stringLengthValidatorField; | ||
} | ||
|
||
public String getFieldExpressionValidatorField() { | ||
return fieldExpressionValidatorField; | ||
} | ||
|
||
@FieldExpressionValidator( | ||
expression = "(fieldExpressionValidatorField == requiredValidatorField)", | ||
message = "must be the same as the Required Validator Field if specified") | ||
public void setFieldExpressionValidatorField( | ||
String fieldExpressionValidatorField) { | ||
this.fieldExpressionValidatorField = fieldExpressionValidatorField; | ||
} | ||
|
||
public String getUrlValidatorField() { | ||
return urlValidatorField; | ||
} | ||
|
||
@UrlValidator(message="must be a valid url if supplied") | ||
public void setUrlValidatorField(String urlValidatorField) { | ||
this.urlValidatorField = urlValidatorField; | ||
} | ||
} | ||
|
||
/** | ||
* <!-- END SNIPPET: ajaxFormSubmit --> | ||
*/ | ||
|
||
|
7 changes: 7 additions & 0 deletions
7
...ase/src/main/java/org/apache/struts2/showcase/validation/AjaxFormSubmitSuccessAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.apache.struts2.showcase.validation; | ||
|
||
public class AjaxFormSubmitSuccessAction { | ||
public String execute() { | ||
return "success"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
apps/showcase/src/main/resources/template/ajaxErrorContainers/actionerror.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<#-- | ||
/* | ||
* $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. | ||
*/ | ||
--> | ||
<#-- | ||
Make sure element is always present. To be filled later via JS. | ||
--> | ||
<ul<#rt/> | ||
<#if parameters.id??> | ||
id="${parameters.id?html}"<#rt/> | ||
</#if> | ||
<#if parameters.cssClass??> | ||
class="${parameters.cssClass?html}"<#rt/> | ||
<#else> | ||
class="errorMessage"<#rt/> | ||
</#if> | ||
<#if parameters.cssStyle??> | ||
style="${parameters.cssStyle?html}"<#rt/> | ||
</#if> | ||
> | ||
<#if (actionErrors?? && actionErrors?size > 0)> | ||
<#list actionErrors as error> | ||
<#if error??> | ||
<li><span><#if parameters.escape>${error!?html}<#else>${error!}</#if></span><#rt/></li><#rt/> | ||
</#if> | ||
</#list> | ||
</#if> | ||
</ul> |
39 changes: 39 additions & 0 deletions
39
apps/showcase/src/main/resources/template/ajaxErrorContainers/controlfooter.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<#-- | ||
/* | ||
* $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. | ||
*/ | ||
--> | ||
${parameters.after!}<#t/> | ||
</td><#lt/> | ||
</tr> | ||
<#if (parameters.errorposition!"top") == 'bottom'> | ||
<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors[parameters.name]??/> | ||
<#if hasFieldErrors> | ||
<tr errorFor="${parameters.id}"> | ||
<td class="tdErrorMessage" colspan="2"><#rt/> | ||
<#if hasFieldErrors> | ||
<#list fieldErrors[parameters.name] as error> | ||
<div class="errorMessage">${error?html}</div><#t/> | ||
</#list> | ||
</#if> | ||
</td><#lt/> | ||
</tr> | ||
</#if> | ||
</#if> |
80 changes: 80 additions & 0 deletions
80
apps/showcase/src/main/resources/template/ajaxErrorContainers/controlheader-core.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<#-- | ||
/* | ||
* $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. | ||
*/ | ||
--> | ||
<#-- | ||
Always include elements to show errors. They may be filled later via AJAX. | ||
--> | ||
<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors[parameters.name]??/> | ||
<#if (parameters.errorposition!"top") == 'top'> | ||
<tr errorFor="${parameters.id}"> | ||
<td class="tdErrorMessage" colspan="2" data-error-for-fieldname="${parameters.name}"><#rt/> | ||
<#if hasFieldErrors> | ||
<#list fieldErrors[parameters.name] as error> | ||
<div class="errorMessage">${error?html}</div><#t/> | ||
</#list> | ||
</#if> | ||
</td><#lt/> | ||
</tr> | ||
</#if> | ||
<#if !parameters.labelposition?? && (parameters.form.labelposition)??> | ||
<#assign labelpos = parameters.form.labelposition/> | ||
<#elseif parameters.labelposition??> | ||
<#assign labelpos = parameters.labelposition/> | ||
</#if> | ||
<#-- | ||
if the label position is top, | ||
then give the label it's own row in the table | ||
--> | ||
<tr> | ||
<#if (labelpos!"") == 'top'> | ||
<td class="tdLabelTop" colspan="2"><#rt/> | ||
<#else> | ||
<td class="tdLabel"><#rt/> | ||
</#if> | ||
<#if parameters.label??> | ||
<label <#t/> | ||
<#if parameters.id??> | ||
for="${parameters.id?html}" <#t/> | ||
</#if> | ||
<#if hasFieldErrors> | ||
class="errorLabel"<#t/> | ||
<#else> | ||
class="label"<#t/> | ||
</#if> | ||
><#t/> | ||
<#if parameters.required!false && parameters.requiredPosition!"right" != 'right'> | ||
<span class="required">*</span><#t/> | ||
</#if> | ||
${parameters.label?html}<#t/> | ||
<#if parameters.required!false && parameters.requiredPosition!"right" == 'right'> | ||
<span class="required">*</span><#t/> | ||
</#if> | ||
${parameters.labelseparator!":"?html}<#t/> | ||
<#include "/${parameters.templateDir}/${parameters.expandTheme}/tooltip.ftl" /> | ||
</label><#t/> | ||
</#if> | ||
</td><#lt/> | ||
<#-- add the extra row --> | ||
<#if (labelpos!"") == 'top'> | ||
</tr> | ||
<tr> | ||
</#if> |
21 changes: 21 additions & 0 deletions
21
apps/showcase/src/main/resources/template/ajaxErrorContainers/theme.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# $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. | ||
# | ||
parent = xhtml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.