Yeah, you should inject a ValidationDelegate into your page and pass
it to your form as the delegate.  Then, you can stick any arbitrary
error messages in the delegate, attached to particular fields or not.
So long as your error handling in the template renders every error,
rather than just the first one, you should see it, and if you attached
the error to a field, the field will be marked as being in error (the
default is to slap a couple of asterisks after it and place the field
in a div marked with a "red" class, if I remember correctly).  Any
messages from validation or translation errors are also automatically
added to the delegate. There are some nice examples of this in the
freely available chapters (chapter 3, specifically) of the "Enjoy Web
Development with Tapestry" e-book.

--sam

On 12/6/06, Malin Ljungh <[EMAIL PROTECTED]> wrote:
Guys - you're great!

Acually Sam was right - by overriding the getAcceptsNull in my validator and
returning true did the trick.
I also tried overriding the isRequired method but this method never gets
called it seems (?)

Though - the other solution from Francesco is very intresting also!
But I don't really get it - I don't have the "getDelegate" method in my
page... is there some injection missing here, or how do I do it?


Malin


On 12/5/06, Sam Gendler <[EMAIL PROTECTED]> wrote:
>
> Yes, even if you can't get your validator itself to work (and you
> should be able to), you should definitely just add an error message to
> your existing validation delegate, rather than making a custom method
> for each field you want to validate.  That will allow your standard
> error handling mechanism in the view to render the error rather than
> requiring special conditionals within your template.
>
> --sam
>
>
> On 12/4/06, fdegrassi <[EMAIL PROTECTED]> wrote:
> > I think you can add  custom validation messages to your
> > ValidationDelegate and display them along with your validators errors.
> > It should work more or less like this.
> >
> > public void doRegister() {
> >     if (getStart() > getStop()) {
> >         getDelegate().record(getStartField(), "Start should be less than
> > Stop");
> >         return;
> >     }
> >     if (getDelegate().getHasErrors())
> >         return;
> >
> >     // to register stuff ....
> >     // ......
> > }
> >
> > Good luck
> >
> > Francesco Degrassi
> >
> >
> > Malin Ljungh wrote:
> > > Thank you guys! You've been very helpful.
> > >
> > > I now make the validation in submit but it's not pretty; in the submit
> > > listener I have this:
> > >
> > > if(!validateFieldX()) {
> > >   setFieldXValid(false);
> > >   return null;
> > > }
> > >
> > > and in the html I have an @If to display validation message if
> validation
> > > has failed.
> > > Is there a neater way or is this "how it is done"?
> > >
> > > Malin
> > >
> > > On 12/3/06, Sam Gendler <[EMAIL PROTECTED]> wrote:
> > >>
> > >> Why not just build the set of validators for the field dynamically?
> > >> Assuming you can determine whether the field should be required by
> the
> > >> time the field rewinds (rather than being dependant on something not
> > >> yet rewound), then you can include the required validator in the list
> > >> only if it is actually required.  However, since the 'required'
> > >> validator is obviously called whether the field has a value or not, I
> > >> would suggest taking a look at the source for that validator to
> > >> determine where you have gone wrong with yours.  It is clearly
> > >> possible. Without seeing your source, that's about the best I can
> > >> suggest.
> > >>
> > >> --sam
> > >>
> > >>
> > >> On 12/2/06, Malin Ljungh <[EMAIL PROTECTED]> wrote:
> > >> > Good evening!
> > >> >
> > >> > I have written my own validator which works excellent - as long as
> a
> > >> value
> > >> > is submitted in the field to be validated. Have I missed something
> > >> here?
> > >> > What should I do?
> > >> >
> > >> > To add a required validator may seem to be the obvious solution but
> > >> the
> > >> > thing is that the field is not always required - it depends.
> > >> >
> > >> > Cheers
> > >> > Malin
> > >> >
> > >> >
> > >>
> > >> ---------------------------------------------------------------------
> > >> 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]
> >
> >
>
> ---------------------------------------------------------------------
> 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]

Reply via email to