Something else that might work for you is using validation expressions:

@Validate(expression = "(not includeName) or (includeName ne null)")
public String getName() {return name;}

(See http://mc4j.org/confluence/display/stripes/Validation+Reference)

The disadvantage, however, is that you have to express all of your
validations in expressions, which could lead to rather complex
expressions (and pretty generic error messages).

On your other point, I don't think omitting property accessors is
something Stripes supports. It would be nice if Stripes could bind
public/protected fields, though.

Regards,
  Levi

On Wed, Jun 11, 2008 at 10:18 PM, Ross Sargant <[EMAIL PROTECTED]> wrote:
> Hi Dave,
>    Thanks for the snippet, it is helpful assuming the only option I have is
> to write code myself to handle this. I was curious if it was possible to set
> up dependencies on validation rules between fields solely using annotations
> and have stripes handle everything.  I remember playing around wtih the
> Struts validator back in the day and it had something along those lines.
>
> Thinking out loud here but something along lines of
>
> @Validate(on="search",when="useRoom=true")
> private String roomCriteria_;
>
> Of course, it is a big can of worms to say how much flexibility "when" could
> have and how this works if "when" fields also need validation, but  simply
> checking that one (or possibly more) other parameter have a certain value
> would handle my scenario.
>
> On a side note, is there anything special I need to do to have validation
> work directly with fields?
> I'm using 1.5.0 RC1 and binding doesn't work at all if the fields are
> private, if the fields are public binding works but not validation. If I use
> traditional get/set pairs..everything works fine.
>
> Using Jetty as my web-container..
>
>
>
> On Wed, Jun 11, 2008 at 11:56 AM, DaveMark <[EMAIL PROTECTED]> wrote:
>>
>> Hi Ross,
>>
>> Would this be of use to you?
>>
>>
>> @ValidationMethod(on="division")
>> public void avoidDivideByZero(ValidationErrors errors) {
>>    String skip = getContext().getRequest().getParameter("skip");
>>    if( skip != null  &&  !"".equals(skip) )
>>    {
>>        return; //do not validate
>>    }
>>
>>    if (this.numberTwo == 0) {
>>        errors.add("numberTwo",
>>            new SimpleError("/ by zero not allowed.")
>>        );
>>    }
>> }
>>
>> Cheers,
>>
>> DJDaveMark
>>
>>
>>
>>
>> > ----------------------------------------------------------------------
>> > Date: Tue, 10 Jun 2008 13:49:48 -0400
>> > From: "Ross Sargant" <[EMAIL PROTECTED]>
>> > Subject: Conditional Validation
>> > To: Stripes-users@lists.sourceforge.net
>> >
>> > Hi,
>> >   Is it possible to have validation in stripes run conditionally based
>> > on
>> > other request parameters?
>> >
>> > My scenario is that I have a search form with several different search
>> > options.
>> > Each search option has a checkbox which activates that criteria for the
>> > search and a corresponding input control (either a text-box or
>> > drop-down)
>> > for the criteria value.
>> >
>> > Is there a way, without writing much code myself ,to have stripes handle
>> > the
>> > validation of the free-form text entry ONLY when the corresponding
>> > check-box
>> > is selected?
>> > I looked at DontValidate and the "on" annotation but neither seems like
>> > it
>> > would fit the bill here. I know I can write my own code to run stripes
>> > validators based on the checkbox state but obviously I'd like to avoid
>> > that.
>> >
>> > This seems like a pretty common way of building a search form with
>> > different
>> > options so I'm suprised I'm having difficulty with it.
>> >
>> > Is there something I've missed here that would make this easier? Another
>> > way
>> > of setting up the page controls perhaps?
>> >
>> > Thanks,
>> >
>> > --
>> > Ross Sargant
>> >
>> > TVR Communications LLC
>> > Software Engineer
>> > 3275 W Hillsboro Blvd,Suite 300,Deerfield Beach, Florida,33442
>> >
>> > http://www.tvrc.com
>> _
>>
>>
>>
>>
>>
>>
>>
>>
>> _
>>
>>
>>      __________________________________________________________
>> Sent from Yahoo! Mail.
>> A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html
>>
>> -------------------------------------------------------------------------
>> Check out the new SourceForge.net Marketplace.
>> It's the best place to buy or sell services for
>> just about anything Open Source.
>> http://sourceforge.net/services/buy/index.php
>> _______________________________________________
>> Stripes-users mailing list
>> Stripes-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
>
>
> --
> Ross Sargant
>
> TVR Communications LLC
> Software Engineer
> 3275 W Hillsboro Blvd,Suite 300,Deerfield Beach, Florida,33442
>
> http://www.tvrc.com
>
> p: 954-571-2017 x2108
>
> email: [EMAIL PROTECTED]
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
>

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to