SmartURLs and Validation Annotations...

2007-10-08 Thread Eric D Nielsen
I've been trying to figure out how to use Validation Annotations with the
SmartURLs plugin.  I'm not sure which half I'm not understanding properly, but
I can't get the validations to fire at all.  I've seen several similiar posts
in the archives and have tried tweaking things in a variety of directions. 
I've also tried emulating Ted Husted's Zero-Configuration Mail-Reader demo app.

I've even tried adding what I think should be an always failing
ExpressionValidator to help make sure that its not some other subsystem
throwing off my expected results.

The failure mode I'm seeing is that execure is getting called regardless of the
validation success or failure.  I'm adding my action, struts.xml,
struts.properties, and web.xml.  What am I missing about how the validations
are supposed to work?

Here's my action
-
package com.ballroomregistrar.compinabox.web.action.account;

import com.ballroomregistrar.compinabox.data.User;
import com.ballroomregistrar.compinabox.data.service.UserDAO;
import com.ballroomregistrar.compinabox.web.action.Unsecured;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.EmailValidator;
import com.opensymphony.xwork2.validator.annotations.ExpressionValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;

import org.texturemedia.smarturls.ActionName;
import org.texturemedia.smarturls.ActionNames;
import org.texturemedia.smarturls.Result;


@ActionNames({
@ActionName(name=login, method=execute),
@ActionName(name=login-input,method=input)
})
@Result(name=success, location=pendingActivation, type=redirect-action)
@SuppressWarnings(serial)
@Unsecured
public class Create  extends ActionSupport {
private String username;
private String email;
private String password;
private String password_confirm;
private UserDAO userDAO;


public String input() {
return INPUT;
}

@Validations(
requiredStrings = {

@RequiredStringValidator(fieldName=username,message=Please enter a
username),

@RequiredStringValidator(fieldName=password,message=Please enter a
password),

@RequiredStringValidator(fieldName=password_confim,message=Please
confirm your password)},
emails = [EMAIL 
PROTECTED](fieldName=email,message=Please enter your e-mail
address)},
expressions = {

@ExpressionValidator(expression=password eq password_confirm,message=The
two passwords must be the same),
@ExpressionValidator(expression=true 
eq false, message=Forcing
validation failed)}
)
public String execute() {
User user = new User();
user.setUsername(getUsername());
user.setEmail(getEmail());
user.setPassword(getPassword());
userDAO.makePersistent(user);
return SUCCESS;
}

public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}

public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setPassword_confirm(String password_confirm) {
this.password_confirm = password_confirm;
}
public String getPassword_confirm() {
return password_confirm;
}
public void setUserService(UserDAO service) {
userDAO=service;
}
public void setSubmit(String dummy) {}

public static final String CANCEL = cancel;

}
-
My struts.xml
?xml version=1.0 encoding=UTF-8 ?
!DOCTYPE struts PUBLIC
-//Apache Software Foundation//DTD Struts Configuration 2.0//EN
http://struts.apache.org/dtds/struts-2.0.dtd;
struts
  constant name=struts.objectFactory value=spring /
  constant name=struts.devMode value=true /

  package name=cib-default extends=struts-default
interceptors
  interceptor name=authentication
class=com.ballroomregistrar.compinabox.web.interceptors.AuthenticationInterceptor
/
  interceptor name=authorization
class=com.ballroomregistrar.compinabox.web.interceptors.AuthorizationInterceptor
/
  interceptor-stack name=cibStack
interceptor-ref name=authentication /
interceptor-ref name=authorization /
interceptor-ref name

Re: SmartURLs and Validation Annotations...

2007-10-08 Thread Dave Newton
Is validation firing at *all*? I had been under the
impression that classes needed to be annotated with
the Validation annotation.

http://struts.apache.org/2.x/docs/validation-annotation.html

--- Eric D Nielsen [EMAIL PROTECTED] wrote:

 I've been trying to figure out how to use Validation
 Annotations with the
 SmartURLs plugin.  I'm not sure which half I'm not
 understanding properly, but
 I can't get the validations to fire at all.  I've
 seen several similiar posts
 in the archives and have tried tweaking things in a
 variety of directions. 
 I've also tried emulating Ted Husted's
 Zero-Configuration Mail-Reader demo app.
 
 I've even tried adding what I think should be an
 always failing
 ExpressionValidator to help make sure that its not
 some other subsystem
 throwing off my expected results.
 
 The failure mode I'm seeing is that execure is
 getting called regardless of the
 validation success or failure.  I'm adding my
 action, struts.xml,
 struts.properties, and web.xml.  What am I missing
 about how the validations
 are supposed to work?
 
 Here's my action
 -
 package
 com.ballroomregistrar.compinabox.web.action.account;
 
 import com.ballroomregistrar.compinabox.data.User;
 import

com.ballroomregistrar.compinabox.data.service.UserDAO;
 import

com.ballroomregistrar.compinabox.web.action.Unsecured;
 import com.opensymphony.xwork2.ActionSupport;
 import

com.opensymphony.xwork2.validator.annotations.EmailValidator;
 import

com.opensymphony.xwork2.validator.annotations.ExpressionValidator;
 import

com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
 import

com.opensymphony.xwork2.validator.annotations.Validations;
 
 import org.texturemedia.smarturls.ActionName;
 import org.texturemedia.smarturls.ActionNames;
 import org.texturemedia.smarturls.Result;
 
 
 @ActionNames({
   @ActionName(name=login, method=execute),
   @ActionName(name=login-input,method=input)
 })
 @Result(name=success,
 location=pendingActivation,
 type=redirect-action)
 @SuppressWarnings(serial)
 @Unsecured
 public class Create  extends ActionSupport {
   private String username;
   private String email;
   private String password;
   private String password_confirm;
   private UserDAO userDAO;
 
 
   public String input() {
   return INPUT;
   }
 
   @Validations(
   requiredStrings = {
   

@RequiredStringValidator(fieldName=username,message=Please
 enter a
 username),
   

@RequiredStringValidator(fieldName=password,message=Please
 enter a
 password),
   

@RequiredStringValidator(fieldName=password_confim,message=Please
 confirm your password)},
   emails =
 [EMAIL PROTECTED](fieldName=email,message=Please
 enter your e-mail
 address)},
   expressions = {
   
 @ExpressionValidator(expression=password eq
 password_confirm,message=The
 two passwords must be the same),
   @ExpressionValidator(expression=true eq
 false, message=Forcing
 validation failed)}
   )
   public String execute() {
   User user = new User();
   user.setUsername(getUsername());
   user.setEmail(getEmail());
   user.setPassword(getPassword());
   userDAO.makePersistent(user);
   return SUCCESS;
   }
 
   public void setUsername(String username) {
   this.username = username;
   }
   public String getUsername() {
   return username;
   }
 
   public void setEmail(String email) {
   this.email = email;
   }
   public String getEmail() {
   return email;
   }
   public void setPassword(String password) {
   this.password = password;
   }
   public String getPassword() {
   return password;
   }
   public void setPassword_confirm(String
 password_confirm) {
   this.password_confirm = password_confirm;
   }
   public String getPassword_confirm() {
   return password_confirm;
   }
   public void setUserService(UserDAO service) {
   userDAO=service;
   }
   public void setSubmit(String dummy) {}
 
 public static final String CANCEL = cancel;
 
 }
 -
 My struts.xml
 ?xml version=1.0 encoding=UTF-8 ?
 !DOCTYPE struts PUBLIC
 -//Apache Software Foundation//DTD Struts
 Configuration 2.0//EN
 http://struts.apache.org/dtds/struts-2.0.dtd;
 struts
   constant name=struts.objectFactory
 value=spring /
   constant name=struts.devMode value=true /
 
   package name=cib-default
 extends=struts-default
 interceptors
 interceptor name=authentication

class=com.ballroomregistrar.compinabox.web.interceptors.AuthenticationInterceptor
 /
 interceptor name

Re: SmartURLs and Validation Annotations...

2007-10-08 Thread Ted Husted
On 10/8/07, Dave Newton [EMAIL PROTECTED] wrote:
 Is validation firing at *all*? I had been under the
 impression that classes needed to be annotated with
 the Validation annotation.

 http://struts.apache.org/2.x/docs/validation-annotation.html

True.

First, @Validations() tags the class, and then the individual
annotations specify the validations as a separate statement or
statements.

-Ted.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: SmartURLs and Validation Annotations...

2007-10-08 Thread Eric D Nielsen
On 10/8/07, Ted Husted wrote:
On 10/8/07, Dave Newton [EMAIL PROTECTED] wrote:
 Is validation firing at *all*? I had been under the
 impression that classes needed to be annotated with
 the Validation annotation.

 http://struts.apache.org/2.x/docs/validation-annotation.html

True.

First, @Validations() tags the class, and then the individual
annotations specify the validations as a separate statement or
statements.


I'm confused.  You say True, but then seem to imply that the class doesn't need
an extra explicit annotation in addition to the annotation on the method?  I've
been looking at the Login class inthe mailreader-zero app and it doesn't tag the
class in addition to the method.

However, it almost working now and it looks like the primary problem was that
something in my build chain is misbehaving -- changes to annotations are only
getting picked up by every other build/deployment.

Other minor issue:
  I was suprised that @EmailValidator doesn't appear to detect a missing email,
it seems like you have to also use @RequiredStringValidator.  And this
indirectly caused most of my problems since I my initial automated tests for
seeing how to hook up validations was only testing a missing email field.

Thank you.
Eric

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]