struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David G (JIRA)" <>
Subject [jira] Created: (WW-3532) client validation isn't generated when using a VisitorFieldValidator annotation
Date Sun, 21 Nov 2010 13:19:13 GMT
client validation isn't generated when using a VisitorFieldValidator annotation

                 Key: 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");

        var errors = false;
        var continueValidation = true;

        return !errors;

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 ;-) )

public class AccountManagementAction extends ActionSupport
	private Account account;

	public Account getAccount()
		return account;

	public void setAccount(Account account)
		this.account = account;

public class Account
	private String username;

	public String getUsername()
		return username;

		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;


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

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

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

View raw message