The version of commons validator (1.1.3 I think) that comes with the recently released Sruts 1.2.1 beta allows you to inherit from another form definition using the extends attribute
Niall ----- Original Message ----- From: "Erik Weber" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Monday, July 12, 2004 10:09 PM Subject: Re: Prepopulating forms & validation > Thanks a lot! I no doubt will find that very useful. > > I have another question for the group at large: > > I am now using the same form successfully for adds and updates. I am > using the Validator plugin for validation, which I find to be pretty > awesome. The problem I face though is, the fields I need to validate are > slightly different between add and update conditions. > > For example, when I add, there is a "disclaimer" checkbox that *must* be > checked. When I update, there is no longer any checkbox. I am trying to > share the <form> element in validation.xml, obviously, because the form > itself is (almost) the same. So the problem is that sometimes I need > "required", and sometimes not, for this checkbox field. > > Because of one or two fields being different between add and update > forms, I fear I'll have to do a nearly-redundant (and very long) <form> > element for my update condition in validation.xml. Does anyone have a > better solution? > > Thanks, > Erik > > > > Rick Reumann wrote: > > > On Mon, 12 Jul 2004 12:22:11 -0400, Erik Weber > > <[EMAIL PROTECTED]> wrote: > > > >> Using BeanUtils.copyProperties(), it's a piece of cake to update > >> your Form bean from the ValueObject properties. > >> > >> Do you have an example of this, or is there one on your site? I > >> indeed have some properties that are the same between form bean and > >> VO, but some are not (for example my form beans use only Strings, > >> but my VOs use some booleans, ints, etc.) > > > > > > Sorry was busy so unable to keep up with this thread. > > > > No, the types can all be different. BeanUtils will convert them for > > you, so your formBean can have all Strings (some would argue it > > should only be all Strings anyway) and your VO obviously will have > > different types. To copy the properties from your VO to your form > > bean it's as simple as: > > > > import org.apache.commons.beanutils.BeanUtils; > > > > BeanUtils.copyProperties(youFormBean, yourVO); > > > > If you are dealing with java.util.Dates you'll have one other thing to > > do (register a converter for your app) but I can explain that more if > > you need to go that route. > > > > --------------------------------------------------------------------- > 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]