Announcement Announcement Module
Collapse
No announcement yet.
@ModelAttribute returns null when it shouldn't Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ModelAttribute returns null when it shouldn't

    Hi,

    I have a set of controllers that use an AbstractBaseController like this

    PHP Code:
    public abstract BaseController{

       @
    ModelAttribute("user")
       public 
    User getUser(NativeWebRequest request){
           return (
    Userrequest.getAttribute("user"RequestAttributes.SESSION);
      }
    }

    @
    Controller
    @RequestMapping("/account")
    public 
    MyController extends BaseController{

         @
    RequestMapping
         
    public String getIt(
              
    ModelMap model,
             
    NativeWebRequest request
         
    ){
                
    User user = (User)  model.get("user");
               
    //user is sometimes null

       
    }

    Security is setup in such a way as to required a loggedin user for the /account area which is put in the session during the login process.

    I personally never saw any issues with this, but I'm seeing in the logs that in some unclear cases, end users run into situations where the user ends up being null.

    I've always assumed that @ModelAttribute would always execute before Controller methods.

    Any ideas on why this might happen?

    Cheers,
    Marc
    Last edited by mschipperheyn; May 16th, 2014, 12:24 PM.

  • #2
    Are you using Spring Security?
    Could you provide us more details on the actual HTTP requests and logs?

    This question is probably a better candidate for StackOverflow, perhaps with the "spring-mvc" and/or "spring-security" tags.
    Could you post your question there?

    The forums are moving to stackoverflow, a page explaining all this will be available there in a few days: http://spring.io/questions

    Comment

    Working...
    X