Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8919611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:04:41+00:00 2026-06-15T06:04:41+00:00

My question boils down to: How you do get spring mvc to call @ModelAttribute

  • 0

My question boils down to: How you do get spring mvc to call @ModelAttribute after it has already been populated?

To elaborate, I’m messing around with the BookCatalog example from chapter 8 from Portlets in Action
by Ashish Sarin (Which is really good) and I’ve run into a problem where the method annotated with
@ModelAttribute is only called once even upon successive loads. For instance:

  1. BookCatalog Portlet is displayed
  2. Click Edit Book1. Book1 is displayed in the edit form
  3. Click home
  4. Click Edit Book2. Book1 is still displayed in the edit form

I’ve added sysouts to the begining of each method to see what is being called where. The results are as follows:

showBooks 
getBook!
initBinder
showEditBookForm
showBooks
initBinder <- Where is getBook!?
showEditBookForm

I read somewhere that @ModelAttribute methods are called whenever @ModelAttribute
parameters are requested. So I tried adding @ModelAttribute("book") Book book to the showEditBookForm but that still doesn’t seem to trigger the @ModelAttribute method.

I’m using Spring 3.1.3.RELEASE and deploying with maven to Liferay 6.1.1.

Any assistance would be appreciated!

EditBookController:

@Controller
@RequestMapping(value="VIEW")
@SessionAttributes({"book"})
public class EditBookController {

    ...

    @RenderMapping(params="myaction=editBookForm")
    public String showEditBookForm(@ModelAttribute("book") Book book) {
       System.out.println("showEditBookForm");
       return "editBookForm"
    }

    @InitBinder("book")
    public void initBinder(WebDataBinder binder) {
       System.out.println("initBinder");
       binder.registerCustomEditor(Long.class, new LongNumberPropertyEditor());
       binder.setDisallowedFields(new String[] {"isbnNumber"});
    }

    @ModelAttribute("book")
    public Book getBook(@RequestParam Long isbnNumber) {
       System.out.println("getBook!");
       return bookService.getBook(isbnNumber);
    }

    ...
}

BookController:

@Controller
@RequestMapping(value = "VIEW")
public class BookController {
    ...
    @RenderMapping
    public String showBooks(RenderResponse response,SessionStatus sessionStatus) {
       System.out.println("showBooks");
       return "home";
    }
    ...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:04:42+00:00Added an answer on June 15, 2026 at 6:04 am

    According to this line of code:

    @SessionAttributes({"book"})
    public class EditBookController {
    

    You’re using the “book” attribute as a Session Attribute. This implies that the first time a Request is made to the Portal, the framework will verify an attribute with that name is present in Portlet Session. If it is not, it will call the corresponding @ModelAttribute method to generate an instance and put it into Session. But if there’s already an attribute in Session with that name, the Controller will use the existing object.

    So, the first time you’re invoking the Book Catalog Portlet an instance of the Book Attribute is generated and stored in Session. But the second time -as an object is already in Session- the Portlet will use the object generated in the first request. If you want to clear every object stored in Session after a render or action request you just need to call SessionStatus.setComplete() to trigger a Session cleanup.

    That’s what theory and the book said, but there’s some buggy behaviour in SessionStatus.setComplete() and the Book Author has some thoghts about it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question is already been asked in title. Here is a code: (function($){ var filter
The answer to this question boils down to two things: 1) Will it be
My question boils down to this: is it standard structure in Swing programming to
I've been trying to get back into coding for a while, so I figured
SOLVED: Thanks figured it out thanks to dominic hamon. It all boils down to
Why does the connections table get updated when I call @user.connections for the following?
I'm writing a particularly troublesome query. It boils down to this: I obtain a
Ok I have some code that boils down to a pattern like this class
Im having an issue with an MDX query, and I think it boils down
Question Is it possible to stop a Message Driven Bean (programmatically), so that it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.