In Stripes 1.5, there is the new (and highly recommended -- by me, at 
least) @StrictBinding annotation. You can apply it to your ActionBean 
class and then only properties that are explicitly annotated with 
@Validate are allowed to bind. So basically, if you do this:

@StrictBinding
public class UserViewActionBean extends BaseActionBean {
        @Validate(required=true)
        private User user;
        public User getUser() { return user; }
        public void setUser(User user) { this.user = user; }

        @DefaultHandler
        public Resolution view() {
                return new ForwardResolution("/user/view.jsp");
        }
}


Then you can be reasonably sure that none of your User properties will 
be changed by the request parameters. You can also use a bare @Validate 
annotation if it happens that a property is allowed to be bound but is 
not required or otherwise validated. And even though it is usually not 
necessary, you can also use the "policy," "allow" and "deny" elements of 
@StrictBinding to define which properties may be bound. E.g.:

@StrictBinding(allow="**", deny="user.password")
public class ...

Or the equivalent:

@StrictBinding(policy=Policy.ALLOW, deny="user.password")
public class ...

This new feature evolved from its initial incarnation in Stripes Extras 
(http://www.bengunter.com/stripex). I know some people are using that 
with 1.4.3 and are happy with it. The usage differs, but it's pretty 
well documented.

-Ben

Morten Matras wrote:
> Hi fellow stripers
>
> Stripes early binding to objects from the database makes it possible 
> to do things like:
>
> http://whatever/user/User.action?user=9&user.name=Kurt 
> <http://whatever/user/User.action?user=9&user.name=Kurt>
>
> and automatically let Stripes make sure that the user with id=9 from 
> the database get the name="Kurt". This is fine if we want to allow the 
> end user to make such a change.
>
> It is possible to limit this by not comitting the hibernate session if 
> the user is to see an object - not change it, but that is not always 
> enough.
>
> I only commit when the request is a "save" request.
>
> So I commit an action to: 
> http://whatever/user/SAVE.action?user=9&user.name=Kurt 
> <http://whatever/user/SAVE.action?user=9&user.name=Kurt>
>
> While I do not commit an action to: 
> http://whatever/user/VIEW.action?user=9&user.name=Kurt 
> <http://whatever/user/VIEW.action?user=9&user.name=Kurt>
> ensuring that the user.setName("Kurt") is not committed to the database.
>
> Now I introduced a small statistics entity using hibernate, so that I 
> create and save a new entity when I go to the VIEW action. This means 
> I have to commit the hibernate session on view. This exposes the user 
> object to be editable in the VIEW action.
>
> I hope to be able to limit what objects must be comitted and what 
> changes must be transient.
>
> Any hints?
>
> -- 
> Morten Matras

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to