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 <s:actionerror /> 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:[email protected]]
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: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]