forked from apache/struts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bean-validation-plugin'
- Loading branch information
Showing
25 changed files
with
303 additions
and
125 deletions.
There are no files selected for viewing
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
170 changes: 170 additions & 0 deletions
170
...ase/src/main/java/org/apache/struts2/showcase/validation/BeanValidationExampleAction.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,170 @@ | ||
/* | ||
* $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.showcase.validation; | ||
|
||
import com.opensymphony.xwork2.ActionSupport; | ||
import org.apache.struts.beanvalidation.constraints.FieldMatch; | ||
import org.apache.struts2.convention.annotation.Action; | ||
import org.apache.struts2.convention.annotation.Namespace; | ||
import org.apache.struts2.convention.annotation.ParentPackage; | ||
import org.apache.struts2.convention.annotation.Result; | ||
import org.apache.struts2.interceptor.validation.SkipValidation; | ||
import org.hibernate.validator.constraints.Email; | ||
import org.hibernate.validator.constraints.NotBlank; | ||
import org.hibernate.validator.constraints.ScriptAssert; | ||
import org.hibernate.validator.constraints.URL; | ||
|
||
import javax.validation.constraints.*; | ||
import java.sql.Date; | ||
|
||
/** | ||
* <!-- START SNIPPET: beanValidatationExample --> | ||
*/ | ||
@Namespace("/bean-validation") | ||
@ParentPackage("bean-validation") | ||
@Action(results = { | ||
@Result(name = "input", location = "bean-validation.jsp"), | ||
@Result(name = "success", location = "/WEB-INF/validation/successFieldValidatorsExample.jsp") | ||
}) | ||
@FieldMatch(first = "fieldExpressionValidatorField", second = "requiredValidatorField", message = "requiredValidatorField and fieldExpressionValidatorField are not matching") | ||
@ScriptAssert(lang = "javascript", script = "_this.dateValidatorField != null && _this.dateValidatorField.before(new java.util.Date())", message = "Date need to before now") | ||
public class BeanValidationExampleAction extends ActionSupport { | ||
|
||
@NotNull | ||
private String requiredValidatorField = null; | ||
|
||
@NotBlank | ||
private String requiredStringValidatorField = null; | ||
|
||
@NotNull | ||
@Min(1) | ||
@Max(10) | ||
private Integer integerValidatorField = null; | ||
|
||
@NotNull | ||
private Date dateValidatorField = null; | ||
|
||
@NotNull | ||
@Size(min = 4, max = 64) | ||
private String emailValidatorField = null; | ||
|
||
@NotNull | ||
@Size(min = 4, max = 64) | ||
@URL | ||
private String urlValidatorField = null; | ||
|
||
@NotNull | ||
@Size(min = 2, max = 4) | ||
private String stringLengthValidatorField = null; | ||
|
||
@Pattern(regexp = "[^<>]+") | ||
private String regexValidatorField = null; | ||
|
||
private String fieldExpressionValidatorField = null; | ||
|
||
@Action(value = "bean-validation", results = { | ||
@Result(name = "success", location = "bean-validation.jsp") | ||
}) | ||
@SkipValidation | ||
public String beanValidation(){ | ||
return SUCCESS; | ||
} | ||
|
||
public Date getDateValidatorField() { | ||
return dateValidatorField; | ||
} | ||
|
||
public void setDateValidatorField(Date dateValidatorField) { | ||
this.dateValidatorField = dateValidatorField; | ||
} | ||
|
||
public String getEmailValidatorField() { | ||
return emailValidatorField; | ||
} | ||
|
||
public void setEmailValidatorField(String emailValidatorField) { | ||
this.emailValidatorField = emailValidatorField; | ||
} | ||
|
||
public Integer getIntegerValidatorField() { | ||
return integerValidatorField; | ||
} | ||
|
||
public void setIntegerValidatorField(Integer integerValidatorField) { | ||
this.integerValidatorField = integerValidatorField; | ||
} | ||
|
||
public String getRegexValidatorField() { | ||
return regexValidatorField; | ||
} | ||
|
||
public void setRegexValidatorField(String regexValidatorField) { | ||
this.regexValidatorField = regexValidatorField; | ||
} | ||
|
||
public String getRequiredStringValidatorField() { | ||
return requiredStringValidatorField; | ||
} | ||
|
||
public void setRequiredStringValidatorField(String requiredStringValidatorField) { | ||
this.requiredStringValidatorField = requiredStringValidatorField; | ||
} | ||
|
||
public String getRequiredValidatorField() { | ||
return requiredValidatorField; | ||
} | ||
|
||
public void setRequiredValidatorField(String requiredValidatorField) { | ||
this.requiredValidatorField = requiredValidatorField; | ||
} | ||
|
||
public String getStringLengthValidatorField() { | ||
return stringLengthValidatorField; | ||
} | ||
|
||
public void setStringLengthValidatorField(String stringLengthValidatorField) { | ||
this.stringLengthValidatorField = stringLengthValidatorField; | ||
} | ||
|
||
public String getFieldExpressionValidatorField() { | ||
return fieldExpressionValidatorField; | ||
} | ||
|
||
public void setFieldExpressionValidatorField( | ||
String fieldExpressionValidatorField) { | ||
this.fieldExpressionValidatorField = fieldExpressionValidatorField; | ||
} | ||
|
||
public String getUrlValidatorField() { | ||
return urlValidatorField; | ||
} | ||
|
||
public void setUrlValidatorField(String urlValidatorField) { | ||
this.urlValidatorField = urlValidatorField; | ||
} | ||
} | ||
|
||
/** | ||
* <!-- END SNIPPET: beanValidatationExample --> | ||
*/ | ||
|
||
|
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
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
57 changes: 57 additions & 0 deletions
57
apps/showcase/src/main/webapp/WEB-INF/bean-validation/bean-validation.jsp
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,57 @@ | ||
<%@taglib prefix="s" uri="/struts-tags" %> | ||
<html> | ||
<head> | ||
<title>Struts2 Showcase - Validation - Bean Validation Example</title> | ||
<s:head theme="xhtml"/> | ||
</head> | ||
<body> | ||
|
||
<div class="page-header"> | ||
<h1>Field Validation Examples</h1> | ||
</div> | ||
|
||
<div class="container-fluid"> | ||
<div class="row-fluid"> | ||
<div class="span12"> | ||
|
||
<!-- START SNIPPET: beanValidatationExample --> | ||
|
||
<h3>All Action Errors Will Appear Here</h3> | ||
<s:actionerror/> | ||
<hr/> | ||
|
||
<h3>All Field Errors Will Appear Here</h3> | ||
<s:fielderror/> | ||
<hr/> | ||
|
||
<h3>Field Error due to 'Required String Validator Field' Will Appear Here</h3> | ||
<s:fielderror> | ||
<s:param value="%{'requiredStringValidatorField'}"/> | ||
</s:fielderror> | ||
<hr/> | ||
|
||
<h3>Field Error due to 'String Length Validator Field' Will Appear Here</h3> | ||
<s:fielderror> | ||
<s:param>stringLengthValidatorField</s:param> | ||
</s:fielderror> | ||
<hr/> | ||
|
||
<s:form action="bean-validation-example" namespace="/bean-validation" method="POST" theme="xhtml"> | ||
<s:textfield label="Required Validator Field" name="requiredValidatorField"/> | ||
<s:textfield label="Required String Validator Field" name="requiredStringValidatorField"/> | ||
<s:textfield label="Integer Validator Field" name="integerValidatorField"/> | ||
<s:textfield label="Date Validator Field" name="dateValidatorField"/> | ||
<s:textfield label="Email Validator Field" name="emailValidatorField"/> | ||
<s:textfield label="URL Validator Field" name="urlValidatorField"/> | ||
<s:textfield label="String Length Validator Field" name="stringLengthValidatorField"/> | ||
<s:textfield label="Regex Validator Field" name="regexValidatorField"/> | ||
<s:textfield label="Field Expression Validator Field" name="fieldExpressionValidatorField"/> | ||
<s:submit label="Submit" cssClass="btn btn-primary"/> | ||
</s:form> | ||
|
||
<!-- END SNIPPET: beanValidatationExample --> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.