You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@beehive.apache.org by Philipp Jardas <ph...@jardas.de> on 2008/04/17 11:17:22 UTC

Complex Form Bean Validation

Hi everyone,

I hope you might be able to help me with this issue. I want a form
bean to perform more complex validation than what is possible with the
property annotations. Think "if property A has the value X then
property B must not be greater than Y".

In Struts I would simply override the validate method. How do I do
this in Beehive?

Thanks for your help,
Philipp

Re: Complex Form Bean Validation

Posted by Carlin Rogers <ca...@gmail.com>.
Hi Philipp,

Looks like you may have found a bug. You can open a bug at Apache,
https://issues.apache.org/jira/browse/BEEHIVE
...and attach your simple reproducer/test for this issue.

Carlin

On Fri, Apr 18, 2008 at 3:37 AM, Philipp Jardas <ph...@jardas.de> wrote:
> Hi Carlin,
>
>  thanks a lot for the tip about the validator interface, this is
>  exactly what I was looking for.
>
>  Not a new problem arised, maybe hopefully you can help me out with
>  this as well. I am using page flow controller inheritance.
>
>  public class ParentController extends ... {
>   @Jpf.Action( ... validationErrorForward = Jpf.NavigateTo.currentPage )
>   public Forward submit(FormBean form) { ... }
>  }
>
>  The child flow controller has inheritLocalPaths set to true and does
>  not overwrite the action method.
>
>  When I submit the form bean, which has been enhanced with the
>  Validator interface, and the validation fails, I would expect the user
>  to be forwarded back to the input page. However, I receive an
>  exception:
>
>  org.apache.beehive.netui.pageflow.NoPreviousPageException: No relevant
>  page for return-to="currentPage"
>
>  If I use a path in the validationErrorForward instead of NavigateTo,
>  no exception occurs but no JSP is being rendered. =(
>
>  Do you have any ideas?
>
>  Thanks a lot,
>  <P>
>
>
>
>  On Fri, Apr 18, 2008 at 7:52 AM, Carlin Rogers <ca...@gmail.com> wrote:
>  > If you cannot come up with a the custom validator that works for you,
>  >  you can implement a validate() method as you inquired about in your
>  >  original post. Just make the super class form bean implement the
>  >  org.apache.beehive.netui.pageflow.Validatable interface and write a
>  >  general validate() method.
>  >
>  >  http://beehive.apache.org/docs/1.0.2/netui/apidocs/javadoc/org/apache/beehive/netui/pageflow/Validatable.html
>  >
>  >  The Validatable interface validate() method would be called when data
>  >  is posted to any page flow action that takes the given bean as its
>  >  argument (Note, the action needs validation turned on by including the
>  >  validationErrorForward in the @Jpf.Action annotation).
>  >
>  >  Or, if you extend your super class form bean from Struts ActionForm,
>  >  you could override its validate() method and it would be called by the
>  >  framework.
>  >
>  >  Kind regards,
>  >  Carlin
>  >
>  >
>  >
>  >  On Thu, Apr 17, 2008 at 6:21 AM, Phillippe Camus
>  >  <Ph...@imail.org> wrote:
>  >  >
>  >  >  Hi Philipp,
>  >  >
>  >  >  Not sure if that is what you are looking for, but you can create custom
>  >  >  validators.
>  >  >
>  >  >  You need to reference them in a deployment descriptor named
>  >  >  "custom-validator-rules.xml":
>  >  >
>  >  >  <form-validation>
>  >  >    <global>
>  >  >       <validator name="validateNameIsString"
>  >  >             classname="org.foo.portal.utils.customValidator.CustomRules"
>  >  >                method="validateNameIsString"
>  >  >                   msg="nameIsStringError"
>  >  >          methodParams="java.lang.Object,
>  >  >                        org.apache.commons.validator.ValidatorAction,
>  >  >                        org.apache.commons.validator.Field,
>  >  >                        org.apache.struts.action.ActionMessages,
>  >  >                        javax.servlet.http.HttpServletRequest,
>  >  >                        javax.servlet.ServletContext" >
>  >  >       </validator>
>  >  >    </global>
>  >  >  </form-validation>
>  >  >
>  >  >  Then in your CustomRules class you would implement your validation
>  >  >  method:
>  >  >
>  >  >  public static boolean validateNameIsString(Object bean, ValidatorAction
>  >  >  va, Field field,
>  >  >                         ActionMessages errors, HttpServletRequest
>  >  >  request,
>  >  >                         ServletContext servletContext)
>  >  >         {
>  >  >
>  >  >  You can access the fieds in your FormBeans like this:
>  >  >  ValidatorUtil.getValueAsString(bean, field.getProperty());
>  >  >
>  >  >  And then submit the error for the Netui tags: errors.add(field.getKey(),
>  >  >  Resources.getActionError(request, va, field));
>  >  >
>  >  >  Then in your form bean:
>  >  >
>  >  >  @Jpf.ValidatableProperty(validateCustomRules = {
>  >  >  @Jpf.ValidateCustomRule(rule = "validateNameIsString", messageKey =
>  >  >  "nameIsStringError") })
>  >  >                 public String getFirstName() {
>  >  >                         return firstName;
>  >  >                 }
>  >  >
>  >  >  You can pretty much do whatever you want in the CustomRules class. Hope
>  >  >  this helps.
>  >  >
>  >  >  Best regards,
>  >  >
>  >  >  Phil
>  >  >
>  >  >
>  >  >
>  >  >  -----Original Message-----
>  >  >  From: phjardas@gmail.com [mailto:phjardas@gmail.com] On Behalf Of
>  >  >  Philipp Jardas
>  >  >  Sent: Thursday, April 17, 2008 6:01 AM
>  >  >  To: Beehive Users
>  >  >  Subject: Re: Complex Form Bean Validation
>  >  >
>  >  >  Hi Zuber,
>  >  >
>  >  >  Thanks again for the swift response. However, I am not able to find the
>  >  >  base class "TaggedObject" you mentioned, neither in the Beehive nor in
>  >  >  the Struts libraries. Are you sure about the name?
>  >  >
>  >  >  Thanks,
>  >  >  <P>
>  >  >
>  >  >  >  I am not sure if this is correct way to do but you can do that by
>  >  >  > creating a  bean class by extending 'TaggedObject' class it has
>  >  >  > validate method which  you can override .
>  >  >  >
>  >  >  >
>  >  >  >
>  >  >  >  Hope this will help you.
>  >  >  >
>  >  >  >  Regards,
>  >  >  >  Zuber
>  >  >  >
>  >  >  >
>  >  >  >  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>  >  >  >  >
>  >  >  >  > Hi Zuber,
>  >  >  >  >
>  >  >  >  > thanks for your reply, though it didn't catch what I was thinking
>  >  >  of.
>  >  >  >  > I am, of course, aware of the property annotations. Let me give an
>  >  >
>  >  >  > > example of what I want to do:
>  >  >  >  >
>  >  >  >  > public class TestForm {
>  >  >  >  > public long getA() { ... }
>  >  >  >  > public long getB() { ... }
>  >  >  >  >
>  >  >  >  > public void validate() {
>  >  >  >  >    if (getA() > 3 && getB() < 4) {
>  >  >  >  >      // Add error message to B: "Must be smaller than 4 if A is
>  >  >  >  > greater than 3".
>  >  >  >  >    }
>  >  >  >  >
>  >  >  >  >    // even more complex validation scenarios...
>  >  >  >  > }
>  >  >  >  > }
>  >  >  >  >
>  >  >  >  > How could I possibly do this with annotations that always refer to
>  >  >  > a  > single property?
>  >  >  >  >
>  >  >  >  > Thanks,
>  >  >  >  > <P>
>  >  >  >  >
>  >  >  >  > On Thu, Apr 17, 2008 at 11:32 AM, zubair syed <zu...@gmail.com>
>  >  >  wrote:
>  >  >  >  > > Hi Philip ,
>  >  >  >  > >
>  >  >  >  > >  You can do this my putting validateProperty anotation of every
>  >  >  > getter  > of the  > >  property.
>  >  >  >  > >
>  >  >  >  > >  for ex:
>  >  >  >  > >
>  >  >  >  > >   @Jpf.ValidatableProperty(validateMaxLength =
>  >  >  >  > @Jpf.ValidateMaxLength(chars =
>  >  >  >  > >  20, messageKey = "error message you can set"), validateMinLength
>  >  >
>  >  >  > =  > >  @Jpf.ValidateMinLength(messageKey = "errror message you can
>  >  >  > set ",  > chars =  > >  5))  > >  public String getUser_id(){  > >
>  >  >  > return user_id;  > >  }  > >  > >  You can also get help  from beehive
>  >  >
>  >  >  > documentation . Hope this will help  > you.
>  >  >  >  > >
>  >  >  >  > >  Regards,
>  >  >  >  > >  Zuber
>  >  >  >  > >
>  >  >  >  > >
>  >  >  >  > >
>  >  >  >  > >
>  >  >  >  > >
>  >  >  >  > >
>  >  >  >  > >  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>  >  >  >  > >  >
>  >  >  >  > >  > Hi everyone,
>  >  >  >  > >  >
>  >  >  >  > >  > I hope you might be able to help me with this issue. I want a
>  >  >  > form  > >  > bean to perform more complex validation than what is
>  >  >  > possible with  > the  > >  > property annotations. Think "if property
>  >  >  > A has the value X then  > >  > property B must not be greater than Y".
>  >  >  >  > >  >
>  >  >  >  > >  > In Struts I would simply override the validate method. How do
>  >  >  > I do  > >  > this in Beehive?
>  >  >  >  > >  >
>  >  >  >  > >  > Thanks for your help,
>  >  >  >  > >  > Philipp
>  >  >  >  > >  >
>  >  >  >  > >
>  >  >  >  >
>  >  >  >
>  >  >
>  >  >
>  >
>

Re: Complex Form Bean Validation

Posted by Philipp Jardas <ph...@jardas.de>.
Hi Carlin,

thanks a lot for the tip about the validator interface, this is
exactly what I was looking for.

Not a new problem arised, maybe hopefully you can help me out with
this as well. I am using page flow controller inheritance.

public class ParentController extends ... {
  @Jpf.Action( ... validationErrorForward = Jpf.NavigateTo.currentPage )
  public Forward submit(FormBean form) { ... }
}

The child flow controller has inheritLocalPaths set to true and does
not overwrite the action method.

When I submit the form bean, which has been enhanced with the
Validator interface, and the validation fails, I would expect the user
to be forwarded back to the input page. However, I receive an
exception:

org.apache.beehive.netui.pageflow.NoPreviousPageException: No relevant
page for return-to="currentPage"

If I use a path in the validationErrorForward instead of NavigateTo,
no exception occurs but no JSP is being rendered. =(

Do you have any ideas?

Thanks a lot,
<P>

On Fri, Apr 18, 2008 at 7:52 AM, Carlin Rogers <ca...@gmail.com> wrote:
> If you cannot come up with a the custom validator that works for you,
>  you can implement a validate() method as you inquired about in your
>  original post. Just make the super class form bean implement the
>  org.apache.beehive.netui.pageflow.Validatable interface and write a
>  general validate() method.
>
>  http://beehive.apache.org/docs/1.0.2/netui/apidocs/javadoc/org/apache/beehive/netui/pageflow/Validatable.html
>
>  The Validatable interface validate() method would be called when data
>  is posted to any page flow action that takes the given bean as its
>  argument (Note, the action needs validation turned on by including the
>  validationErrorForward in the @Jpf.Action annotation).
>
>  Or, if you extend your super class form bean from Struts ActionForm,
>  you could override its validate() method and it would be called by the
>  framework.
>
>  Kind regards,
>  Carlin
>
>
>
>  On Thu, Apr 17, 2008 at 6:21 AM, Phillippe Camus
>  <Ph...@imail.org> wrote:
>  >
>  >  Hi Philipp,
>  >
>  >  Not sure if that is what you are looking for, but you can create custom
>  >  validators.
>  >
>  >  You need to reference them in a deployment descriptor named
>  >  "custom-validator-rules.xml":
>  >
>  >  <form-validation>
>  >    <global>
>  >       <validator name="validateNameIsString"
>  >             classname="org.foo.portal.utils.customValidator.CustomRules"
>  >                method="validateNameIsString"
>  >                   msg="nameIsStringError"
>  >          methodParams="java.lang.Object,
>  >                        org.apache.commons.validator.ValidatorAction,
>  >                        org.apache.commons.validator.Field,
>  >                        org.apache.struts.action.ActionMessages,
>  >                        javax.servlet.http.HttpServletRequest,
>  >                        javax.servlet.ServletContext" >
>  >       </validator>
>  >    </global>
>  >  </form-validation>
>  >
>  >  Then in your CustomRules class you would implement your validation
>  >  method:
>  >
>  >  public static boolean validateNameIsString(Object bean, ValidatorAction
>  >  va, Field field,
>  >                         ActionMessages errors, HttpServletRequest
>  >  request,
>  >                         ServletContext servletContext)
>  >         {
>  >
>  >  You can access the fieds in your FormBeans like this:
>  >  ValidatorUtil.getValueAsString(bean, field.getProperty());
>  >
>  >  And then submit the error for the Netui tags: errors.add(field.getKey(),
>  >  Resources.getActionError(request, va, field));
>  >
>  >  Then in your form bean:
>  >
>  >  @Jpf.ValidatableProperty(validateCustomRules = {
>  >  @Jpf.ValidateCustomRule(rule = "validateNameIsString", messageKey =
>  >  "nameIsStringError") })
>  >                 public String getFirstName() {
>  >                         return firstName;
>  >                 }
>  >
>  >  You can pretty much do whatever you want in the CustomRules class. Hope
>  >  this helps.
>  >
>  >  Best regards,
>  >
>  >  Phil
>  >
>  >
>  >
>  >  -----Original Message-----
>  >  From: phjardas@gmail.com [mailto:phjardas@gmail.com] On Behalf Of
>  >  Philipp Jardas
>  >  Sent: Thursday, April 17, 2008 6:01 AM
>  >  To: Beehive Users
>  >  Subject: Re: Complex Form Bean Validation
>  >
>  >  Hi Zuber,
>  >
>  >  Thanks again for the swift response. However, I am not able to find the
>  >  base class "TaggedObject" you mentioned, neither in the Beehive nor in
>  >  the Struts libraries. Are you sure about the name?
>  >
>  >  Thanks,
>  >  <P>
>  >
>  >  >  I am not sure if this is correct way to do but you can do that by
>  >  > creating a  bean class by extending 'TaggedObject' class it has
>  >  > validate method which  you can override .
>  >  >
>  >  >
>  >  >
>  >  >  Hope this will help you.
>  >  >
>  >  >  Regards,
>  >  >  Zuber
>  >  >
>  >  >
>  >  >  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>  >  >  >
>  >  >  > Hi Zuber,
>  >  >  >
>  >  >  > thanks for your reply, though it didn't catch what I was thinking
>  >  of.
>  >  >  > I am, of course, aware of the property annotations. Let me give an
>  >
>  >  > > example of what I want to do:
>  >  >  >
>  >  >  > public class TestForm {
>  >  >  > public long getA() { ... }
>  >  >  > public long getB() { ... }
>  >  >  >
>  >  >  > public void validate() {
>  >  >  >    if (getA() > 3 && getB() < 4) {
>  >  >  >      // Add error message to B: "Must be smaller than 4 if A is
>  >  >  > greater than 3".
>  >  >  >    }
>  >  >  >
>  >  >  >    // even more complex validation scenarios...
>  >  >  > }
>  >  >  > }
>  >  >  >
>  >  >  > How could I possibly do this with annotations that always refer to
>  >  > a  > single property?
>  >  >  >
>  >  >  > Thanks,
>  >  >  > <P>
>  >  >  >
>  >  >  > On Thu, Apr 17, 2008 at 11:32 AM, zubair syed <zu...@gmail.com>
>  >  wrote:
>  >  >  > > Hi Philip ,
>  >  >  > >
>  >  >  > >  You can do this my putting validateProperty anotation of every
>  >  > getter  > of the  > >  property.
>  >  >  > >
>  >  >  > >  for ex:
>  >  >  > >
>  >  >  > >   @Jpf.ValidatableProperty(validateMaxLength =
>  >  >  > @Jpf.ValidateMaxLength(chars =
>  >  >  > >  20, messageKey = "error message you can set"), validateMinLength
>  >
>  >  > =  > >  @Jpf.ValidateMinLength(messageKey = "errror message you can
>  >  > set ",  > chars =  > >  5))  > >  public String getUser_id(){  > >
>  >  > return user_id;  > >  }  > >  > >  You can also get help  from beehive
>  >
>  >  > documentation . Hope this will help  > you.
>  >  >  > >
>  >  >  > >  Regards,
>  >  >  > >  Zuber
>  >  >  > >
>  >  >  > >
>  >  >  > >
>  >  >  > >
>  >  >  > >
>  >  >  > >
>  >  >  > >  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>  >  >  > >  >
>  >  >  > >  > Hi everyone,
>  >  >  > >  >
>  >  >  > >  > I hope you might be able to help me with this issue. I want a
>  >  > form  > >  > bean to perform more complex validation than what is
>  >  > possible with  > the  > >  > property annotations. Think "if property
>  >  > A has the value X then  > >  > property B must not be greater than Y".
>  >  >  > >  >
>  >  >  > >  > In Struts I would simply override the validate method. How do
>  >  > I do  > >  > this in Beehive?
>  >  >  > >  >
>  >  >  > >  > Thanks for your help,
>  >  >  > >  > Philipp
>  >  >  > >  >
>  >  >  > >
>  >  >  >
>  >  >
>  >
>  >
>

Re: Complex Form Bean Validation

Posted by Carlin Rogers <ca...@gmail.com>.
If you cannot come up with a the custom validator that works for you,
you can implement a validate() method as you inquired about in your
original post. Just make the super class form bean implement the
org.apache.beehive.netui.pageflow.Validatable interface and write a
general validate() method.

http://beehive.apache.org/docs/1.0.2/netui/apidocs/javadoc/org/apache/beehive/netui/pageflow/Validatable.html

The Validatable interface validate() method would be called when data
is posted to any page flow action that takes the given bean as its
argument (Note, the action needs validation turned on by including the
validationErrorForward in the @Jpf.Action annotation).

Or, if you extend your super class form bean from Struts ActionForm,
you could override its validate() method and it would be called by the
framework.

Kind regards,
Carlin

On Thu, Apr 17, 2008 at 6:21 AM, Phillippe Camus
<Ph...@imail.org> wrote:
>
>  Hi Philipp,
>
>  Not sure if that is what you are looking for, but you can create custom
>  validators.
>
>  You need to reference them in a deployment descriptor named
>  "custom-validator-rules.xml":
>
>  <form-validation>
>    <global>
>       <validator name="validateNameIsString"
>             classname="org.foo.portal.utils.customValidator.CustomRules"
>                method="validateNameIsString"
>                   msg="nameIsStringError"
>          methodParams="java.lang.Object,
>                        org.apache.commons.validator.ValidatorAction,
>                        org.apache.commons.validator.Field,
>                        org.apache.struts.action.ActionMessages,
>                        javax.servlet.http.HttpServletRequest,
>                        javax.servlet.ServletContext" >
>       </validator>
>    </global>
>  </form-validation>
>
>  Then in your CustomRules class you would implement your validation
>  method:
>
>  public static boolean validateNameIsString(Object bean, ValidatorAction
>  va, Field field,
>                         ActionMessages errors, HttpServletRequest
>  request,
>                         ServletContext servletContext)
>         {
>
>  You can access the fieds in your FormBeans like this:
>  ValidatorUtil.getValueAsString(bean, field.getProperty());
>
>  And then submit the error for the Netui tags: errors.add(field.getKey(),
>  Resources.getActionError(request, va, field));
>
>  Then in your form bean:
>
>  @Jpf.ValidatableProperty(validateCustomRules = {
>  @Jpf.ValidateCustomRule(rule = "validateNameIsString", messageKey =
>  "nameIsStringError") })
>                 public String getFirstName() {
>                         return firstName;
>                 }
>
>  You can pretty much do whatever you want in the CustomRules class. Hope
>  this helps.
>
>  Best regards,
>
>  Phil
>
>
>
>  -----Original Message-----
>  From: phjardas@gmail.com [mailto:phjardas@gmail.com] On Behalf Of
>  Philipp Jardas
>  Sent: Thursday, April 17, 2008 6:01 AM
>  To: Beehive Users
>  Subject: Re: Complex Form Bean Validation
>
>  Hi Zuber,
>
>  Thanks again for the swift response. However, I am not able to find the
>  base class "TaggedObject" you mentioned, neither in the Beehive nor in
>  the Struts libraries. Are you sure about the name?
>
>  Thanks,
>  <P>
>
>  >  I am not sure if this is correct way to do but you can do that by
>  > creating a  bean class by extending 'TaggedObject' class it has
>  > validate method which  you can override .
>  >
>  >
>  >
>  >  Hope this will help you.
>  >
>  >  Regards,
>  >  Zuber
>  >
>  >
>  >  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>  >  >
>  >  > Hi Zuber,
>  >  >
>  >  > thanks for your reply, though it didn't catch what I was thinking
>  of.
>  >  > I am, of course, aware of the property annotations. Let me give an
>
>  > > example of what I want to do:
>  >  >
>  >  > public class TestForm {
>  >  > public long getA() { ... }
>  >  > public long getB() { ... }
>  >  >
>  >  > public void validate() {
>  >  >    if (getA() > 3 && getB() < 4) {
>  >  >      // Add error message to B: "Must be smaller than 4 if A is
>  >  > greater than 3".
>  >  >    }
>  >  >
>  >  >    // even more complex validation scenarios...
>  >  > }
>  >  > }
>  >  >
>  >  > How could I possibly do this with annotations that always refer to
>  > a  > single property?
>  >  >
>  >  > Thanks,
>  >  > <P>
>  >  >
>  >  > On Thu, Apr 17, 2008 at 11:32 AM, zubair syed <zu...@gmail.com>
>  wrote:
>  >  > > Hi Philip ,
>  >  > >
>  >  > >  You can do this my putting validateProperty anotation of every
>  > getter  > of the  > >  property.
>  >  > >
>  >  > >  for ex:
>  >  > >
>  >  > >   @Jpf.ValidatableProperty(validateMaxLength =
>  >  > @Jpf.ValidateMaxLength(chars =
>  >  > >  20, messageKey = "error message you can set"), validateMinLength
>
>  > =  > >  @Jpf.ValidateMinLength(messageKey = "errror message you can
>  > set ",  > chars =  > >  5))  > >  public String getUser_id(){  > >
>  > return user_id;  > >  }  > >  > >  You can also get help  from beehive
>
>  > documentation . Hope this will help  > you.
>  >  > >
>  >  > >  Regards,
>  >  > >  Zuber
>  >  > >
>  >  > >
>  >  > >
>  >  > >
>  >  > >
>  >  > >
>  >  > >  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>  >  > >  >
>  >  > >  > Hi everyone,
>  >  > >  >
>  >  > >  > I hope you might be able to help me with this issue. I want a
>  > form  > >  > bean to perform more complex validation than what is
>  > possible with  > the  > >  > property annotations. Think "if property
>  > A has the value X then  > >  > property B must not be greater than Y".
>  >  > >  >
>  >  > >  > In Struts I would simply override the validate method. How do
>  > I do  > >  > this in Beehive?
>  >  > >  >
>  >  > >  > Thanks for your help,
>  >  > >  > Philipp
>  >  > >  >
>  >  > >
>  >  >
>  >
>
>

RE: Complex Form Bean Validation

Posted by Phillippe Camus <Ph...@imail.org>.
Hi Philipp,

Not sure if that is what you are looking for, but you can create custom
validators.

You need to reference them in a deployment descriptor named
"custom-validator-rules.xml":

<form-validation>
   <global>
      <validator name="validateNameIsString"
            classname="org.foo.portal.utils.customValidator.CustomRules"
               method="validateNameIsString"
                  msg="nameIsStringError"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest,
                       javax.servlet.ServletContext" >
      </validator>
   </global>
</form-validation> 

Then in your CustomRules class you would implement your validation
method:

public static boolean validateNameIsString(Object bean, ValidatorAction
va, Field field,
			ActionMessages errors, HttpServletRequest
request,
			ServletContext servletContext)
	{

You can access the fieds in your FormBeans like this:
ValidatorUtil.getValueAsString(bean, field.getProperty());

And then submit the error for the Netui tags: errors.add(field.getKey(),
Resources.getActionError(request, va, field));

Then in your form bean:

@Jpf.ValidatableProperty(validateCustomRules = {
@Jpf.ValidateCustomRule(rule = "validateNameIsString", messageKey =
"nameIsStringError") })
		public String getFirstName() {
			return firstName;
		}

You can pretty much do whatever you want in the CustomRules class. Hope
this helps.

Best regards,
 
Phil

-----Original Message-----
From: phjardas@gmail.com [mailto:phjardas@gmail.com] On Behalf Of
Philipp Jardas
Sent: Thursday, April 17, 2008 6:01 AM
To: Beehive Users
Subject: Re: Complex Form Bean Validation

Hi Zuber,

Thanks again for the swift response. However, I am not able to find the
base class "TaggedObject" you mentioned, neither in the Beehive nor in
the Struts libraries. Are you sure about the name?

Thanks,
<P>

>  I am not sure if this is correct way to do but you can do that by 
> creating a  bean class by extending 'TaggedObject' class it has 
> validate method which  you can override .
>
>
>
>  Hope this will help you.
>
>  Regards,
>  Zuber
>
>
>  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>  >
>  > Hi Zuber,
>  >
>  > thanks for your reply, though it didn't catch what I was thinking
of.
>  > I am, of course, aware of the property annotations. Let me give an

> > example of what I want to do:
>  >
>  > public class TestForm {
>  > public long getA() { ... }
>  > public long getB() { ... }
>  >
>  > public void validate() {
>  >    if (getA() > 3 && getB() < 4) {
>  >      // Add error message to B: "Must be smaller than 4 if A is
>  > greater than 3".
>  >    }
>  >
>  >    // even more complex validation scenarios...
>  > }
>  > }
>  >
>  > How could I possibly do this with annotations that always refer to 
> a  > single property?
>  >
>  > Thanks,
>  > <P>
>  >
>  > On Thu, Apr 17, 2008 at 11:32 AM, zubair syed <zu...@gmail.com>
wrote:
>  > > Hi Philip ,
>  > >
>  > >  You can do this my putting validateProperty anotation of every 
> getter  > of the  > >  property.
>  > >
>  > >  for ex:
>  > >
>  > >   @Jpf.ValidatableProperty(validateMaxLength =
>  > @Jpf.ValidateMaxLength(chars =
>  > >  20, messageKey = "error message you can set"), validateMinLength

> =  > >  @Jpf.ValidateMinLength(messageKey = "errror message you can 
> set ",  > chars =  > >  5))  > >  public String getUser_id(){  > >  
> return user_id;  > >  }  > >  > >  You can also get help  from beehive

> documentation . Hope this will help  > you.
>  > >
>  > >  Regards,
>  > >  Zuber
>  > >
>  > >
>  > >
>  > >
>  > >
>  > >
>  > >  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>  > >  >
>  > >  > Hi everyone,
>  > >  >
>  > >  > I hope you might be able to help me with this issue. I want a 
> form  > >  > bean to perform more complex validation than what is 
> possible with  > the  > >  > property annotations. Think "if property 
> A has the value X then  > >  > property B must not be greater than Y".
>  > >  >
>  > >  > In Struts I would simply override the validate method. How do 
> I do  > >  > this in Beehive?
>  > >  >
>  > >  > Thanks for your help,
>  > >  > Philipp
>  > >  >
>  > >
>  >
>


Re: Complex Form Bean Validation

Posted by zubair syed <zu...@gmail.com>.
Hi Philip,

My aplogy for that , i gave wrong name  actual class name is
'BaseActionForm' under the package
'org.apache.beehive.netui.pageflow.internal'


Regards,
Zuber


On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>
> Hi Zuber,
>
> Thanks again for the swift response. However, I am not able to find
> the base class "TaggedObject" you mentioned, neither in the Beehive
> nor in the Struts libraries. Are you sure about the name?
>
> Thanks,
> <P>
>
> >  I am not sure if this is correct way to do but you can do that by
> creating a
> >  bean class by extending 'TaggedObject' class it has validate method
> which
> >  you can override .
> >
> >
> >
> >  Hope this will help you.
> >
> >  Regards,
> >  Zuber
> >
> >
> >  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
> >  >
> >  > Hi Zuber,
> >  >
> >  > thanks for your reply, though it didn't catch what I was thinking of.
> >  > I am, of course, aware of the property annotations. Let me give an
> >  > example of what I want to do:
> >  >
> >  > public class TestForm {
> >  > public long getA() { ... }
> >  > public long getB() { ... }
> >  >
> >  > public void validate() {
> >  >    if (getA() > 3 && getB() < 4) {
> >  >      // Add error message to B: "Must be smaller than 4 if A is
> >  > greater than 3".
> >  >    }
> >  >
> >  >    // even more complex validation scenarios...
> >  > }
> >  > }
> >  >
> >  > How could I possibly do this with annotations that always refer to a
> >  > single property?
> >  >
> >  > Thanks,
> >  > <P>
> >  >
> >  > On Thu, Apr 17, 2008 at 11:32 AM, zubair syed <zu...@gmail.com>
> wrote:
> >  > > Hi Philip ,
> >  > >
> >  > >  You can do this my putting validateProperty anotation of every
> getter
> >  > of the
> >  > >  property.
> >  > >
> >  > >  for ex:
> >  > >
> >  > >   @Jpf.ValidatableProperty(validateMaxLength =
> >  > @Jpf.ValidateMaxLength(chars =
> >  > >  20, messageKey = "error message you can set"), validateMinLength =
> >  > >  @Jpf.ValidateMinLength(messageKey = "errror message you can set ",
> >  > chars =
> >  > >  5))
> >  > >  public String getUser_id(){
> >  > >  return user_id;
> >  > >  }
> >  > >
> >  > >  You can also get help  from beehive documentation . Hope this will
> help
> >  > you.
> >  > >
> >  > >  Regards,
> >  > >  Zuber
> >  > >
> >  > >
> >  > >
> >  > >
> >  > >
> >  > >
> >  > >  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
> >  > >  >
> >  > >  > Hi everyone,
> >  > >  >
> >  > >  > I hope you might be able to help me with this issue. I want a
> form
> >  > >  > bean to perform more complex validation than what is possible
> with
> >  > the
> >  > >  > property annotations. Think "if property A has the value X then
> >  > >  > property B must not be greater than Y".
> >  > >  >
> >  > >  > In Struts I would simply override the validate method. How do I
> do
> >  > >  > this in Beehive?
> >  > >  >
> >  > >  > Thanks for your help,
> >  > >  > Philipp
> >  > >  >
> >  > >
> >  >
> >
>

Re: Complex Form Bean Validation

Posted by Philipp Jardas <ph...@jardas.de>.
Hi Zuber,

Thanks again for the swift response. However, I am not able to find
the base class "TaggedObject" you mentioned, neither in the Beehive
nor in the Struts libraries. Are you sure about the name?

Thanks,
<P>

>  I am not sure if this is correct way to do but you can do that by creating a
>  bean class by extending 'TaggedObject' class it has validate method which
>  you can override .
>
>
>
>  Hope this will help you.
>
>  Regards,
>  Zuber
>
>
>  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>  >
>  > Hi Zuber,
>  >
>  > thanks for your reply, though it didn't catch what I was thinking of.
>  > I am, of course, aware of the property annotations. Let me give an
>  > example of what I want to do:
>  >
>  > public class TestForm {
>  > public long getA() { ... }
>  > public long getB() { ... }
>  >
>  > public void validate() {
>  >    if (getA() > 3 && getB() < 4) {
>  >      // Add error message to B: "Must be smaller than 4 if A is
>  > greater than 3".
>  >    }
>  >
>  >    // even more complex validation scenarios...
>  > }
>  > }
>  >
>  > How could I possibly do this with annotations that always refer to a
>  > single property?
>  >
>  > Thanks,
>  > <P>
>  >
>  > On Thu, Apr 17, 2008 at 11:32 AM, zubair syed <zu...@gmail.com> wrote:
>  > > Hi Philip ,
>  > >
>  > >  You can do this my putting validateProperty anotation of every getter
>  > of the
>  > >  property.
>  > >
>  > >  for ex:
>  > >
>  > >   @Jpf.ValidatableProperty(validateMaxLength =
>  > @Jpf.ValidateMaxLength(chars =
>  > >  20, messageKey = "error message you can set"), validateMinLength =
>  > >  @Jpf.ValidateMinLength(messageKey = "errror message you can set ",
>  > chars =
>  > >  5))
>  > >  public String getUser_id(){
>  > >  return user_id;
>  > >  }
>  > >
>  > >  You can also get help  from beehive documentation . Hope this will help
>  > you.
>  > >
>  > >  Regards,
>  > >  Zuber
>  > >
>  > >
>  > >
>  > >
>  > >
>  > >
>  > >  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>  > >  >
>  > >  > Hi everyone,
>  > >  >
>  > >  > I hope you might be able to help me with this issue. I want a form
>  > >  > bean to perform more complex validation than what is possible with
>  > the
>  > >  > property annotations. Think "if property A has the value X then
>  > >  > property B must not be greater than Y".
>  > >  >
>  > >  > In Struts I would simply override the validate method. How do I do
>  > >  > this in Beehive?
>  > >  >
>  > >  > Thanks for your help,
>  > >  > Philipp
>  > >  >
>  > >
>  >
>

Re: Complex Form Bean Validation

Posted by zubair syed <zu...@gmail.com>.
Hi Philipp,

I am not sure if this is correct way to do but you can do that by creating a
bean class by extending 'TaggedObject' class it has validate method which
you can override .

Hope this will help you.

Regards,
Zuber


On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>
> Hi Zuber,
>
> thanks for your reply, though it didn't catch what I was thinking of.
> I am, of course, aware of the property annotations. Let me give an
> example of what I want to do:
>
> public class TestForm {
> public long getA() { ... }
> public long getB() { ... }
>
> public void validate() {
>    if (getA() > 3 && getB() < 4) {
>      // Add error message to B: "Must be smaller than 4 if A is
> greater than 3".
>    }
>
>    // even more complex validation scenarios...
> }
> }
>
> How could I possibly do this with annotations that always refer to a
> single property?
>
> Thanks,
> <P>
>
> On Thu, Apr 17, 2008 at 11:32 AM, zubair syed <zu...@gmail.com> wrote:
> > Hi Philip ,
> >
> >  You can do this my putting validateProperty anotation of every getter
> of the
> >  property.
> >
> >  for ex:
> >
> >   @Jpf.ValidatableProperty(validateMaxLength =
> @Jpf.ValidateMaxLength(chars =
> >  20, messageKey = "error message you can set"), validateMinLength =
> >  @Jpf.ValidateMinLength(messageKey = "errror message you can set ",
> chars =
> >  5))
> >  public String getUser_id(){
> >  return user_id;
> >  }
> >
> >  You can also get help  from beehive documentation . Hope this will help
> you.
> >
> >  Regards,
> >  Zuber
> >
> >
> >
> >
> >
> >
> >  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
> >  >
> >  > Hi everyone,
> >  >
> >  > I hope you might be able to help me with this issue. I want a form
> >  > bean to perform more complex validation than what is possible with
> the
> >  > property annotations. Think "if property A has the value X then
> >  > property B must not be greater than Y".
> >  >
> >  > In Struts I would simply override the validate method. How do I do
> >  > this in Beehive?
> >  >
> >  > Thanks for your help,
> >  > Philipp
> >  >
> >
>

Re: Complex Form Bean Validation

Posted by Philipp Jardas <ph...@jardas.de>.
Hi Zuber,

thanks for your reply, though it didn't catch what I was thinking of.
I am, of course, aware of the property annotations. Let me give an
example of what I want to do:

public class TestForm {
  public long getA() { ... }
  public long getB() { ... }

  public void validate() {
    if (getA() > 3 && getB() < 4) {
      // Add error message to B: "Must be smaller than 4 if A is
greater than 3".
    }

    // even more complex validation scenarios...
  }
}

How could I possibly do this with annotations that always refer to a
single property?

Thanks,
<P>

On Thu, Apr 17, 2008 at 11:32 AM, zubair syed <zu...@gmail.com> wrote:
> Hi Philip ,
>
>  You can do this my putting validateProperty anotation of every getter of the
>  property.
>
>  for ex:
>
>   @Jpf.ValidatableProperty(validateMaxLength = @Jpf.ValidateMaxLength(chars =
>  20, messageKey = "error message you can set"), validateMinLength =
>  @Jpf.ValidateMinLength(messageKey = "errror message you can set ", chars =
>  5))
>  public String getUser_id(){
>  return user_id;
>  }
>
>  You can also get help  from beehive documentation . Hope this will help you.
>
>  Regards,
>  Zuber
>
>
>
>
>
>
>  On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>  >
>  > Hi everyone,
>  >
>  > I hope you might be able to help me with this issue. I want a form
>  > bean to perform more complex validation than what is possible with the
>  > property annotations. Think "if property A has the value X then
>  > property B must not be greater than Y".
>  >
>  > In Struts I would simply override the validate method. How do I do
>  > this in Beehive?
>  >
>  > Thanks for your help,
>  > Philipp
>  >
>

Re: Complex Form Bean Validation

Posted by zubair syed <zu...@gmail.com>.
Hi Philip ,

You can do this my putting validateProperty anotation of every getter of the
property.

for ex:

 @Jpf.ValidatableProperty(validateMaxLength = @Jpf.ValidateMaxLength(chars =
20, messageKey = "error message you can set"), validateMinLength =
@Jpf.ValidateMinLength(messageKey = "errror message you can set ", chars =
5))
public String getUser_id(){
return user_id;
}

You can also get help  from beehive documentation . Hope this will help you.

Regards,
Zuber




On 4/17/08, Philipp Jardas <ph...@jardas.de> wrote:
>
> Hi everyone,
>
> I hope you might be able to help me with this issue. I want a form
> bean to perform more complex validation than what is possible with the
> property annotations. Think "if property A has the value X then
> property B must not be greater than Y".
>
> In Struts I would simply override the validate method. How do I do
> this in Beehive?
>
> Thanks for your help,
> Philipp
>