This has been talked about before on this mailing list and on IRC. The
problem is that there are 2 different thoughts on where validation
should be defined; in the controller or in the model. I don't believe
anyone is right or wrong. Tim believes it belongs in the controller
which is why its done the way it is. So there is that.
I agree that reusing validation logic would be a really cool thing for
Stripes but no one has been able to come up with a good solution though
we've tried.
Gregg
Simon wrote:
> Hello all,
>
> I really love that I can write an action bean and have parameters
> directly map into fields on the bean - this is clean and simple and
> makes using stripes to create ad hoc pages a real pleasure. However
> as the application grows I find myself needing to separate a single
> stripes action into more find grained actions - to keep the design
> clean and maintainable. But then I meet a problem: now I have
> significant business knowledge tied up in the annotations that control
> validation and binding. Most of those I want to reuse (maybe not
> all) in all my fine grained actions. So the question is, how can I do
> that?
>
> I started doing simply using inheritance - I have a base action and
> all the child actions extend that one. But soon I meet the problem
> that I want to make a combined action that accepts input from two
> forms - it needs to inherit from two actions to reuse their
> annotations. Apart from the fact this is impossible in java there is
> a bad code smell about this - inheritance isn't really a good way to
> achieve code reuse at the best of times.
>
> So - I pose this mainly as a question, to ask if there is any better
> way, or perhaps just a starting point for discussion - is there some
> way to enhance stripes in the future to better meet this need?
>
> Just for comparison one can look at Django, and also Struts - in these
> cases the design separates the forms from the action and the problem
> I'm writing about is part of the reason. Stripes made things simpler,
> but did it lose some important power of abstraction along the way?
>
> Here's what I think I want - I might be wrong :-) What I would
> really like is to be able to tell stripes to look for binding and
> validation annotations on child objects embedded in my action.
> Fantasy pseudo code:
>
> class User {
> @Validate(required=true,maxlength=30)
> String name;
> }
>
> class MyAction implements ActionBean {
> @Validate(delegate=true)
> User user;
> }
>
> Validation will now be delegated to annotations on the User class
> itself. Now I can share my user around all my action beans and use
> validation from all of them! It also looks a bit neater to me than
> having to use ValidateNestedProperties annotations - they look verbose
> and out of place on my parent action. I write this just to
> stimulate conversation and see if there's a better idea, or any
> interest in implementing something like this. Thoughts?
>
> Cheers,
>
> Simon.
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Stripes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users