Re: Required field only works with text fields?
The required attribute only paints the asterisk -- it has nothing to do with actually "requiring" input. Nice huh? Peace, Scott On Fri, Mar 13, 2009 at 4:14 PM, Griffith, Michael * < michael.griff...@fda.hhs.gov> wrote: > Hi all, > > I just noticed that the only required field validations that seem to be > working in my form are text field validations. > > Any HTML tag that renders a list, check box or radio button doesn't > validate, even though the template shows the field as required. > > In other words, this tag: > list="#{'Y':'Yes', 'N':'No'}" required="true" tabindex="7"/> > > Shows a radio button with the "*" required indicator, but the form is > allowed to be submitted without a button selected, which of course > breaks my request/response cycle... > > Do I need to do something special to make the required non-text inputs > to behave as I expect? > > Any help is appreciated. > > Best Regards, > > MG > >
RE: Required field only works with text fields?
Ok, So I am being a bone-head. When I added the @RequiredStringValidator to the model, the validation is in sync with what is being required on the form. That makes sense to me, but... How are relationships handled? I have a form control as such: And the relationship is being managed via a JPA @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER) @JoinColumn(name = "STATUS") public Status getStatus() { return status; } What sort of annotation should I use to validate the user selected an item from the list? Any reply is appreciated... MG -Original Message- From: stanl...@gmail.com [mailto:stanl...@gmail.com] Sent: Friday, March 13, 2009 6:01 PM To: Struts Users Mailing List Subject: Re: Required field only works with text fields? The required attribute only paints the asterisk -- it has nothing to do with actually "requiring" input. Nice huh? Peace, Scott On Fri, Mar 13, 2009 at 4:14 PM, Griffith, Michael * < michael.griff...@fda.hhs.gov> wrote: > Hi all, > > I just noticed that the only required field validations that seem to > be working in my form are text field validations. > > Any HTML tag that renders a list, check box or radio button doesn't > validate, even though the template shows the field as required. > > In other words, this tag: > list="#{'Y':'Yes', 'N':'No'}" required="true" tabindex="7"/> > > Shows a radio button with the "*" required indicator, but the form is > allowed to be submitted without a button selected, which of course > breaks my request/response cycle... > > Do I need to do something special to make the required non-text inputs > to behave as I expect? > > Any help is appreciated. > > Best Regards, > > MG > > - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: Required field only works with text fields?
Can anyone help me with this? By adding the @RequiredField annotation to the relationship field (status in my example below) the form did not submit, which is good because the status had not been specified from the list. However, the form did not present a message too the user saying why the form submission failed. I have the field annotated as: @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER) @JoinColumn(name = "STATUS") @RequiredFieldValidator(message="Validation Error",key="validate.notEmpty") public Status getStatus() { return status; } Any reply would be appreciated. Best Regards, MG -Original Message- From: Griffith, Michael * [mailto:michael.griff...@fda.hhs.gov] Sent: Monday, March 16, 2009 1:18 PM To: Struts Users Mailing List Subject: RE: Required field only works with text fields? Ok, So I am being a bone-head. When I added the @RequiredStringValidator to the model, the validation is in sync with what is being required on the form. That makes sense to me, but... How are relationships handled? I have a form control as such: And the relationship is being managed via a JPA @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER) @JoinColumn(name = "STATUS") public Status getStatus() { return status; } What sort of annotation should I use to validate the user selected an item from the list? Any reply is appreciated... MG -Original Message- From: stanl...@gmail.com [mailto:stanl...@gmail.com] Sent: Friday, March 13, 2009 6:01 PM To: Struts Users Mailing List Subject: Re: Required field only works with text fields? The required attribute only paints the asterisk -- it has nothing to do with actually "requiring" input. Nice huh? Peace, Scott On Fri, Mar 13, 2009 at 4:14 PM, Griffith, Michael * < michael.griff...@fda.hhs.gov> wrote: > Hi all, > > I just noticed that the only required field validations that seem to > be working in my form are text field validations. > > Any HTML tag that renders a list, check box or radio button doesn't > validate, even though the template shows the field as required. > > In other words, this tag: > list="#{'Y':'Yes', 'N':'No'}" required="true" tabindex="7"/> > > Shows a radio button with the "*" required indicator, but the form is > allowed to be submitted without a button selected, which of course > breaks my request/response cycle... > > Do I need to do something special to make the required non-text inputs > to behave as I expect? > > Any help is appreciated. > > Best Regards, > > MG > > - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Required field only works with text fields?
Griffith, Michael * wrote: Can anyone help me with this? By adding the @RequiredField annotation to the relationship field (status in my example below) the form did not submit, which is good because the status had not been specified from the list. However, the form did not present a message too the user saying why the form submission failed. I have the field annotated as: @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER) @JoinColumn(name = "STATUS") @RequiredFieldValidator(message="Validation Error",key="validate.notEmpty") public Status getStatus() { return status; } Any reply would be appreciated. My first assumption would be that you'd need to have a custom validator, depending on how Status objects are initialized/created. AFAIK "required" will only check for nullness. I'm not sure if a Status object will be created if no status properties are set, but if it is, then it probably won't work with a simple "required". If any status properties are set then it definitely won't--empty string fields aren't null; they're blank. I'm a little surprised "required" works with your textfields, since strings normally need a "requiredstring" validator to function properly. Dave - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: Required field only works with text fields?
Dave, Thanks for the reply. I've had some success...tinkering... The following validation annotation seems to work: @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER) @JoinColumn(name = "STATUS") @ExpressionValidator(message = "Default message", key="validate.status", expression = "status != null" ) public Status getStatus() { return status; } However, the validation message appears in block, not nicely next to the field that failed validation as does the other validators. I might have expected this if I had specified shortCircut=true, but I don't. I'm not really sure what the shortCircuit flag is supposed to do. Is there a way to make the validator work as the @RequiredString validator where the message appears above the label? Could this be a bug? Again, thanks for your help, I really appreciate it. Cheers! MG -Original Message- From: Dave Newton [mailto:newton.d...@yahoo.com] Sent: Tuesday, March 17, 2009 3:42 PM To: Struts Users Mailing List Subject: Re: Required field only works with text fields? Griffith, Michael * wrote: > Can anyone help me with this? > > By adding the @RequiredField annotation to the relationship field > (status in my example below) the form did not submit, which is good > because the status had not been specified from the list. However, the > form did not present a message too the user saying why the form > submission failed. I have the field annotated as: > > > @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, > fetch=FetchType.EAGER) > @JoinColumn(name = "STATUS") > @RequiredFieldValidator(message="Validation > Error",key="validate.notEmpty") > public Status getStatus() { > return status; > } > > Any reply would be appreciated. My first assumption would be that you'd need to have a custom validator, depending on how Status objects are initialized/created. AFAIK "required" will only check for nullness. I'm not sure if a Status object will be created if no status properties are set, but if it is, then it probably won't work with a simple "required". If any status properties are set then it definitely won't--empty string fields aren't null; they're blank. I'm a little surprised "required" works with your textfields, since strings normally need a "requiredstring" validator to function properly. Dave - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Required field only works with text fields?
Griffith, Michael * wrote: The following validation annotation seems to work: @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER) @JoinColumn(name = "STATUS") @ExpressionValidator(message = "Default message", key="validate.status", expression = "status != null" ) public Status getStatus() { return status; } However, the validation message appears in block, not nicely next to the field that failed validation as does the other validators. You'd probably need a @FieldExpressionValidator in order for it to be associated with a field, but this is just a guess. I might have expected this if I had specified shortCircut=true, but I don't. I'm not really sure what the shortCircuit flag is supposed to do. IIRC its intent is to prevent multiple validation errors for the same field. Dave - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: Required field only works with text fields?
Dave, Thanks for the suggestion, I changed the validator to read as: @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER) @JoinColumn(name = "STATUS") @FieldExpressionValidator(message = "Default message", key="validate.status", expression = "status != null") public Status getStatus() { return status; } The validation is applied, but no message is displayed. With: @ExpressionValidator(message = "Default message", key="validate.status", expression = "status != null") The validation is applied and the validation message appears at the top of my page where I have an tag. Is there something else I need to do to make the FieldExpressionValidator work? MG -Original Message- From: Dave Newton [mailto:newton.d...@yahoo.com] Sent: Tuesday, March 17, 2009 6:01 PM To: Struts Users Mailing List Subject: Re: Required field only works with text fields? Griffith, Michael * wrote: > The following validation annotation seems to work: > > @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, > fetch=FetchType.EAGER) > @JoinColumn(name = "STATUS") > @ExpressionValidator(message = "Default message", > key="validate.status", expression = "status != null" ) public Status > getStatus() { > return status; > } > > However, the validation message appears in block, > not nicely next to the field that failed validation as does the other > validators. You'd probably need a @FieldExpressionValidator in order for it to be associated with a field, but this is just a guess. > I might have expected this if I had specified shortCircut=true, but I > don't. I'm not really sure what the shortCircuit flag is supposed to do. IIRC its intent is to prevent multiple validation errors for the same field. Dave - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org