Thursday, January 08, 2009

Limiting What Model Attributes You Expose

In Spring, using the RedirectView is a great simple way to bounce users around without having to call response.redirect in a billion places.  But sometimes you have one attribute in the model that you want in the query string and a ton of stuff you don't.  Just copy this trivial class and customize your filtering however you want.  I suggest you not hardcode the attribute name(s).


public class CustomRedirectView extends org.springframework.web.servlet.view.RedirectView {
    @Override
    protected boolean isEligibleProperty(String key, Object value) {
        if(key == "theOnlyAttributeIActuallyWantInTheQueryString")
            return super.isEligibleProperty(key, value);
        else return false;
    }

}

No comments: