Hi all,

What is the status on this functionality. Will it be included in the next Stripes release? I like the idea of being able to validate independently of the binding process to avoid having 'dirty' hibernate objects.

Thanks,
Abdullah

James Stangler <[EMAIL PROTECTED]> wrote:
I looked at the interceptor functionality and I don't think it will work well for what I'm trying to do.  All I want to do is add some additional functionality at specific places in the validation and binding process.  With an interceptor I would have to duplicate 90% of the validation/binding code/functionality and keep it in sync with new releases.

I started refactoring the binder to see if I could structure it to allow me to extend the class to add in the hibernate validation.  I created JIRA enhancement STS-183 to attach the classes to.

Any class ending in "1_3" is a class where I would have made changes to the existing class bundled with stripes v1.3.  This allows the classes to be dropped in and run in parallel with the current OGNL binder.  The class "DefaultActionBeanPropertyBinder" is the replacement for the existing "OgnlActionBeanPropertyBinder".  You should be able to specify this class in the web.xml and have everything work as before.  The class "HibernateActionBeanPropertyBinder" is the subclass that also does Hibernate validation in addition to any validation that would have been performed in the parent class.

Thoughts?

jim

Tim Fennell <[EMAIL PROTECTED]> wrote:
Right.� Yeah, so the documentation isn't there yet.� It'll be getting written in the next week (or maybe two).� It's actually fairly simple, the classes you'll want to take a look at would be:
net.sourceforge.stripes.controller.Interceptor (which you already found)
net.sourceforge.stripes.controller.LifecycleStage (defines the lifecyclcle in Stripes and intercept points)
net.sourceforge.stripes.controller.Interceptors (defines where your interceptor intercepts)

and then maybe some examples:
net.sourceforge.stripes.integration.spring.SpringInterceptor
net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor

The configuration is pretty simple.� In web.xml you need to add an init param for the StripesFilter:
<init-param>
�� �<param-name>Interceptor.Classes</param-name>
�� �<param-value>
� � �� �com.myco.MyInterceptor,
� � �� �net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor
�� �</param-value>
</init-param>

The ordering of the classes in the web.xml is used to determine the execution order of the interceptors if/when they intercept at the same lifecycle stage.� If you don't list the BeforeAfterMethodInterceptor here it will get disabled when you specify this parameter.

-t


On Apr 7, 2006, at 12:21 PM, James Stangler wrote:

I think what you've described is heading exactly where I want to go.� I haven't been following the interceptor work that's been done and I didn't find any documentation on the web site.� If you could point me to the best starting point to learn the stripes interceptor structure it would save me some time.� I've found the net.sourceforge.stripes.controller.Interceptor interface.� Is that the best place to start?

I'm not sure if the interceptor approach will work as cleanly as being able to subclass the propertybinder class, but I guess I'll have to read up on stripes interceptors first.

jim

Tim Fennell <[EMAIL PROTECTED]> wrote:
One alternative (and forgive me if this doesn't fit, I've been looking for an opportunity to explore this) might be to use Hibernate's validator for some of the validation.� If I've followed this conversation correctly you're main problem is that you have attached hibernate objects which are in an invalid state because some validations are not applied until after binding has been completed.

The strategy so far has been to re-load dirty objects and that's expensive.� If the user continues through the flow and completes, they'll be forced to correct their errors right?� It's only if the user abandons the flow that dirty values might get flushed to the database?

So I'm wondering, could most/all of the validations that need to be enforced at the data layer be written using the annotations available in the hibernate validator?� It's pretty slick, and seems to offer lots of different validations - and has a mechanism to add your own.� If you could do this, I think it has a couple of advantages:
� 1) You can express real "constraints" right on your domain objects
� 2) You can plug in the validator as a before-flush/save event in hibernate�
� 3) You/I/we could write a HibernateValidatorInterceptor for Stripes to leverage those validations

The first two steps are well documented in the hibernate doco.� The last step would, I think, be relatively straightforward.� The only thing that would require much thinking is how to deal with the error messages (do you let the validator produce them, or do you try to map them into Stripes errors?).

I think if you took this route though, that you'd be able to validate in the request cycle just like you want, and you'd also be able to prevent saving of invalid data if/when the user abandons what they're doing.� What do you think?

-t


On Apr 6, 2006, at 10:44 PM, James Stangler wrote:

Dan/Aaron,

I read your responses and read your blog entry discussing some of the strategies.� While I think it helps (especially the idea of storing the versioning field in the jsp to facilitate versioning), I think there are still some issues remaining.� Primarily, anytime a field in a hibernate object gets updated with a value that I may not want to get to the database, I have to throw out all of the objects in the hibernate session.� I don't want to have to do that because my application can/will load a large graph of hibernate objects to work with and it's time consuming to load them.� Also, because it's a large number of objects, I want to use hibernate's versioning to ensure that multiple users don't update them and overwrite changes.� I believe Aaron's approach is to use the session-per-request-with-detached-objects pattern as described in the hibernate documentation in section 11.1.2 (Long conversations) <http://www.hibernate.org/hib_docs/v3/reference/en/html_single/>.� My preference is to use the session-per-conversation pattern as described in the same section.� That fits my needs to best as I don't have to merge a large number of objects before committing.� I keep a thread-safe hibernate session in the http session for the duration of the logical transaction across many screens so I don't have to deal with detached objects (I would keep it in a stateful ejb session bean if I was using an application server that supported them).

Ideally, I think the solution would be to do as much validation as possible before doing any binding.� This reduces the cases where I have to worry about invalid data being persisted.� I've been prototyping with the following steps:

1.� Validate all required fields
2.� Loop through all parameters
2a.� do pre conversion validations
2b.� convert values
2c.� do post conversion values excluding _expression_ language validations
2d.� enable some hook or overridable method where I can do hibernate validation
2e.� save this as a bindable value but don't bind it yet
3.� If there are no errors, bind all of the values saved from step 2e.
4.� If there are no errors, perform _expression_ language validations

The lifecycle annotations that have been introduced recently could work very well for allowing the action bean to know what's happening and to abort or continue at the various stages.

Also, the _expression_ language validations could possibly be performed before binding into the action bean by binding to fake objects and invoking the _expression_ language evaluator.� Thus step for could be moved before step 3.� This would be possible assuming that all of the fields in the _expression_ are passed as parameters.

This would reduce the cases where there's validation errors of some kind but data got bound into the hibernate objects and let the action bean know if any data was bound or not.

Thoughts?

jim

PS:� Sorry for the long posts.� I don't post much, but when I do I like to get my money's worth.

Dan Hayes <[EMAIL PROTECTED]> wrote:
Jim,

You are getting into complicated waters :-) . First of all, please read
my blog on a related issue for background on Stripes, Hibernate and
Transaction handling:

http://www.jroller.com/page/dan19460?entry=stripes_spring_hibernate_and_transactions

In my example I rehydrate domain objects in the setContext method of the
Stripes Action Bean. "Rehydrading" objects could be from the database
(via a DAO) or from the HttpSession. If you use the latter technique,
be sure you use the "merge" feature of Hibernate when you update
(somewhere in the business tier). This will insure the object in the
Hibernate Session is synchronized with the database.

As for the versioning issue, you do not have to store an object in
session in order to use versioning. By placing a hidden field in the
form (jsp?) for the version attribute, Hibernate will use this when it
tries to update. If the version passed in does not match the version
column in the database (i.e. someone else updated the record in the
meantime), then a Hibernate exception is thrown. You can catch this an
render an appropriate message if so desired. This is the way I do it
because I don't like keeping around alot of session state unless
absolutely necessary. However, I would assume that it would work the
same way if you stored/retrieved the object from HttpSession.

But after re-reading your post, I think the issue may be related to
transactions and beginning hibernate sessions/transactions in the web
tier rather than in the business tier and how to prevent Hibernate from
updating domain graphs upon validation failures. For that,
clarification may come from reading my blog post.

Good luck. Feel free to clarify your question if this doesn't help.

Dan.

James Stangler wrote:

> I have a question regarding the proper way to handle validation when
> using hibernate and stripes. There's two related scenarios that I'm
> trying to get to work.
>
> The first is to handle cases where 2 users pull up the same record for
> updating. If user A loads a persisted object with their browser and
> then goes on lunch break, user B loads the same object and makes a
> change and saves it, then user A returns and makes a change and
> overwrites user B. Hibernate has support for this with versioned
> fields. To take advantage of this, the object must be read in when
> the user first displays the information, kept in the session, and then
> the same object updated with the new information. Then hibernate is
> able to detect if someone else changed the object between the time it
> was read and the time it was updated. However, the problem comes in
> when validation is applied. Because the validation and binding occur
> simultaneously/interlaced, several/all of the attributes in the
> hibernate object may have been updated with invalid data. If I know
> the user will correct the data and save the object with valid data I
> can keep the hibernate object in the hibernate session. But if the
> user hits their back button or a bookmark or something, the hibernate
> session has invalid data that will be persisted with the next flush.
>
> A related example is when my application needs to load a large graph
> of hibernate objects. I want to keep them in the session so that I
> don't have to reload them everytime since it's resource intensive. If
> the user submits any invalid data, it'll make it into the hibernate
> object forcing me to reload the entire object graph.
>
> How does the rest of the world handle these issues? Is there
> something I'm missing? It seems like it could be resolved or at least
> reduced if the validation and binding occurred as two separate steps
> (or at least as much validation as possible without binding) and some
> way to let the application know whether any binding has occurred. But
> if there's another way that's considered a best practice, I'd be happy
> to use it.
>
> jim
>
> ------------------------------------------------------------------------
> Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great
> rates starting at 1�/min.
>


--
Dan Hayes
Chariot Solutions, LLC
[EMAIL PROTECTED]
610-716-2292



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development



How low will we go? Check out Yahoo! Messenger�s low PC-to-Phone call rates.




Love cheap thrills? Enjoy PC-to-Phone calls to 30+ countries for just 2�/min with Yahoo! Messenger with Voice.



Get amazing travel prices for air and hotel in one click on Yahoo! FareChase

Reply via email to