I think you have it. The JavaBean spec defines the relationship between a "property name" and the accessor/mutator methods for that property. In this case if you have a property called "name" then the accessor methods would be called getName()/setName (unless name was a boolean of course).

While the property name does not necessarily have to match the /field/ name in the class, this is what Stripes expects. I.e. if you place annotations on a field, Stripes assumes that the field name == property name. Stripes can then access the property in one of two ways: 1) using public methods name as per the JavaBean spec or 2) using field level access /if/ the field is public. In either case you can put the annotation on the field or one of the methods.

-t

On Jun 11, 2008, at 9:22 PM, Ross Sargant wrote:

After I asked the question, I realized that getters are probably always required so EL expressions can access them during view rendering (I could be wrong about that though)

What threw me off was that a couple of the examples in the stripes validation reference show the Validation annotations on the field definitions. I assumed this meant it could bind to fields directly. If not, how do annotations on fields relate to the property accessors? Is there an implicit assumption that the name of the field and the accessors match (or is that part of javabean spec?) Example:

@Validate(required=true)
private String name_;

public String getName(){return name_;}

public void setName(String name){ name_=name;}

I don't get how stripes would know what validation rules to run in this case...(the request would have a "name" parameter and therefore binding would call the setName right?) but since I've annotated the field and not the setter.. how would it know what to do?

I tried removing the accessors and using "name_" as a request parameter but that didn't work either. No binding, no validation. This isn't a serious issue or drawback, I would just like to understand how it works.


On Wed, Jun 11, 2008 at 4:54 PM, Levi Hoogenberg <[EMAIL PROTECTED] > wrote: 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



--
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