You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "David G (JIRA)" <ji...@apache.org> on 2010/11/21 14:19:13 UTC

[jira] Created: (WW-3532) client validation isn't generated when using a VisitorFieldValidator annotation

client validation isn't generated when using a VisitorFieldValidator annotation
-------------------------------------------------------------------------------

                 Key: WW-3532
                 URL: https://issues.apache.org/jira/browse/WW-3532
             Project: Struts 2
          Issue Type: Bug
    Affects Versions: 2.2.1
         Environment: jboss 5, struts2-core-2.2.1.jar
            Reporter: David G
            Priority: Minor


When using a VisitorFieldValidator in an action, the generated Javascript doesn't validate fields on the referenced POJO, i.e. the example I have below would only generate:

<script type="text/javascript">
    function validateForm_createAccount() {
        form = document.getElementById("createAccount");
        clearErrorMessages(form);
        clearErrorLabels(form);

        var errors = false;
        var continueValidation = true;

        return !errors;
    }
</script>

I have two current workarounds, but they're a bit of a pain:
1) Using XML validation instead of annotations.
2) Not to use the VisitorFieldValidator model, and instead have the form fields referenced directly in the Action class.

Here's the code I've been using (a trimmed down version of it anyway ;-) )

AccountManagementAction.java:

public class AccountManagementAction extends ActionSupport
{
	private Account account;

	public Account getAccount()
	{
		return account;
	}

	@VisitorFieldValidator
	public void setAccount(Account account)
	{
		this.account = account;
	}

        ...
}

Account.java:
public class Account
{
	private String username;

	public String getUsername()
	{
		return username;
	}

	@Validations(
		requiredStrings = @RequiredStringValidator(trim = true, message = "Required"),
		stringLengthFields = @StringLengthFieldValidator(
			minLength = "2", maxLength = "10", trim = true,
			message = "This must be between ${minLength} and ${maxLength} letters"),
		regexFields = @RegexFieldValidator(expression = "^[0-9a-zA-Z]*$",
			message = "Only plain letters and numbers are allowed")
        )
	public void setUsername(String username)
	{
		this.username = username;
	}
}

registration.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
	<head>
		<s:head/>
	</head>
	<body>
		<s:form validate="true" action="createAccount">
			<s:textfield name="account.username" label="Username" />
			<s:submit/>
		</s:form>
	</body>
</html>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-3532) client validation isn't generated when using a VisitorFieldValidator annotation

Posted by "Maurizio Cucchiara (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12934717#action_12934717 ] 

Maurizio Cucchiara commented on WW-3532:
----------------------------------------

The main reason why it happens it's how form component obtains list of validators  from AnnotationValidationConfigurationBuilder.
IMHO AnnotationValidationConfigurationBuilder should yield, in case of VisitorFieldValidator, the entire  hierarchy of validators.
For example in the following use case, how many validator configurations did you expect (I'd say 2)?:

private class InnerClass {
        private InnerBean bean;

        @VisitorFieldValidator
        public InnerBean getBean() {
            return bean;
        }
    }

    private class InnerBean {

        private String name;

        @RequiredStringValidator
        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

> client validation isn't generated when using a VisitorFieldValidator annotation
> -------------------------------------------------------------------------------
>
>                 Key: WW-3532
>                 URL: https://issues.apache.org/jira/browse/WW-3532
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.2.1
>         Environment: jboss 5, struts2-core-2.2.1.jar
>            Reporter: David G
>            Priority: Minor
>
> When using a VisitorFieldValidator in an action, the generated Javascript doesn't validate fields on the referenced POJO, i.e. the example I have below would only generate:
> <script type="text/javascript">
>     function validateForm_createAccount() {
>         form = document.getElementById("createAccount");
>         clearErrorMessages(form);
>         clearErrorLabels(form);
>         var errors = false;
>         var continueValidation = true;
>         return !errors;
>     }
> </script>
> I have two current workarounds, but they're a bit of a pain:
> 1) Using XML validation instead of annotations.
> 2) Not to use the VisitorFieldValidator model, and instead have the form fields referenced directly in the Action class.
> Here's the code I've been using (a trimmed down version of it anyway ;-) )
> AccountManagementAction.java:
> public class AccountManagementAction extends ActionSupport
> {
> 	private Account account;
> 	public Account getAccount()
> 	{
> 		return account;
> 	}
> 	@VisitorFieldValidator
> 	public void setAccount(Account account)
> 	{
> 		this.account = account;
> 	}
>         ...
> }
> Account.java:
> public class Account
> {
> 	private String username;
> 	public String getUsername()
> 	{
> 		return username;
> 	}
> 	@Validations(
> 		requiredStrings = @RequiredStringValidator(trim = true, message = "Required"),
> 		stringLengthFields = @StringLengthFieldValidator(
> 			minLength = "2", maxLength = "10", trim = true,
> 			message = "This must be between ${minLength} and ${maxLength} letters"),
> 		regexFields = @RegexFieldValidator(expression = "^[0-9a-zA-Z]*$",
> 			message = "Only plain letters and numbers are allowed")
>         )
> 	public void setUsername(String username)
> 	{
> 		this.username = username;
> 	}
> }
> registration.jsp:
> <%@page contentType="text/html" pageEncoding="UTF-8"%>
> <%@ taglib prefix="s" uri="/struts-tags" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>    "http://www.w3.org/TR/html4/loose.dtd">
> <html>
> 	<head>
> 		<s:head/>
> 	</head>
> 	<body>
> 		<s:form validate="true" action="createAccount">
> 			<s:textfield name="account.username" label="Username" />
> 			<s:submit/>
> 		</s:form>
> 	</body>
> </html>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-3532) client validation isn't generated when using a VisitorFieldValidator annotation

Posted by "Maurizio Cucchiara (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Maurizio Cucchiara updated WW-3532:
-----------------------------------

    Attachment: AnnotationValidationConfigurationBuilderTest.java

> client validation isn't generated when using a VisitorFieldValidator annotation
> -------------------------------------------------------------------------------
>
>                 Key: WW-3532
>                 URL: https://issues.apache.org/jira/browse/WW-3532
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.2.1
>         Environment: jboss 5, struts2-core-2.2.1.jar
>            Reporter: David G
>            Priority: Minor
>         Attachments: AnnotationValidationConfigurationBuilderTest.java
>
>
> When using a VisitorFieldValidator in an action, the generated Javascript doesn't validate fields on the referenced POJO, i.e. the example I have below would only generate:
> <script type="text/javascript">
>     function validateForm_createAccount() {
>         form = document.getElementById("createAccount");
>         clearErrorMessages(form);
>         clearErrorLabels(form);
>         var errors = false;
>         var continueValidation = true;
>         return !errors;
>     }
> </script>
> I have two current workarounds, but they're a bit of a pain:
> 1) Using XML validation instead of annotations.
> 2) Not to use the VisitorFieldValidator model, and instead have the form fields referenced directly in the Action class.
> Here's the code I've been using (a trimmed down version of it anyway ;-) )
> AccountManagementAction.java:
> public class AccountManagementAction extends ActionSupport
> {
> 	private Account account;
> 	public Account getAccount()
> 	{
> 		return account;
> 	}
> 	@VisitorFieldValidator
> 	public void setAccount(Account account)
> 	{
> 		this.account = account;
> 	}
>         ...
> }
> Account.java:
> public class Account
> {
> 	private String username;
> 	public String getUsername()
> 	{
> 		return username;
> 	}
> 	@Validations(
> 		requiredStrings = @RequiredStringValidator(trim = true, message = "Required"),
> 		stringLengthFields = @StringLengthFieldValidator(
> 			minLength = "2", maxLength = "10", trim = true,
> 			message = "This must be between ${minLength} and ${maxLength} letters"),
> 		regexFields = @RegexFieldValidator(expression = "^[0-9a-zA-Z]*$",
> 			message = "Only plain letters and numbers are allowed")
>         )
> 	public void setUsername(String username)
> 	{
> 		this.username = username;
> 	}
> }
> registration.jsp:
> <%@page contentType="text/html" pageEncoding="UTF-8"%>
> <%@ taglib prefix="s" uri="/struts-tags" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>    "http://www.w3.org/TR/html4/loose.dtd">
> <html>
> 	<head>
> 		<s:head/>
> 	</head>
> 	<body>
> 		<s:form validate="true" action="createAccount">
> 			<s:textfield name="account.username" label="Username" />
> 			<s:submit/>
> 		</s:form>
> 	</body>
> </html>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] [Updated] (WW-3532) client validation isn't generated when using a VisitorFieldValidator annotation

Posted by "Lukasz Lenart (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart updated WW-3532:
------------------------------

    Fix Version/s: 3.x
    
> client validation isn't generated when using a VisitorFieldValidator annotation
> -------------------------------------------------------------------------------
>
>                 Key: WW-3532
>                 URL: https://issues.apache.org/jira/browse/WW-3532
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.2.1
>         Environment: jboss 5, struts2-core-2.2.1.jar
>            Reporter: David G
>            Priority: Minor
>             Fix For: 3.x
>
>         Attachments: AnnotationValidationConfigurationBuilderTest.java
>
>
> When using a VisitorFieldValidator in an action, the generated Javascript doesn't validate fields on the referenced POJO, i.e. the example I have below would only generate:
> <script type="text/javascript">
>     function validateForm_createAccount() {
>         form = document.getElementById("createAccount");
>         clearErrorMessages(form);
>         clearErrorLabels(form);
>         var errors = false;
>         var continueValidation = true;
>         return !errors;
>     }
> </script>
> I have two current workarounds, but they're a bit of a pain:
> 1) Using XML validation instead of annotations.
> 2) Not to use the VisitorFieldValidator model, and instead have the form fields referenced directly in the Action class.
> Here's the code I've been using (a trimmed down version of it anyway ;-) )
> AccountManagementAction.java:
> public class AccountManagementAction extends ActionSupport
> {
> 	private Account account;
> 	public Account getAccount()
> 	{
> 		return account;
> 	}
> 	@VisitorFieldValidator
> 	public void setAccount(Account account)
> 	{
> 		this.account = account;
> 	}
>         ...
> }
> Account.java:
> public class Account
> {
> 	private String username;
> 	public String getUsername()
> 	{
> 		return username;
> 	}
> 	@Validations(
> 		requiredStrings = @RequiredStringValidator(trim = true, message = "Required"),
> 		stringLengthFields = @StringLengthFieldValidator(
> 			minLength = "2", maxLength = "10", trim = true,
> 			message = "This must be between ${minLength} and ${maxLength} letters"),
> 		regexFields = @RegexFieldValidator(expression = "^[0-9a-zA-Z]*$",
> 			message = "Only plain letters and numbers are allowed")
>         )
> 	public void setUsername(String username)
> 	{
> 		this.username = username;
> 	}
> }
> registration.jsp:
> <%@page contentType="text/html" pageEncoding="UTF-8"%>
> <%@ taglib prefix="s" uri="/struts-tags" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>    "http://www.w3.org/TR/html4/loose.dtd">
> <html>
> 	<head>
> 		<s:head/>
> 	</head>
> 	<body>
> 		<s:form validate="true" action="createAccount">
> 			<s:textfield name="account.username" label="Username" />
> 			<s:submit/>
> 		</s:form>
> 	</body>
> </html>

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira