Note that there are some explanatory texts on larger screens.

plurals
  1. PO@ModelAttribute method isn't called again in a Portlet Spring MVC
    primarykey
    data
    text
    <p>My question boils down to: How you do get spring mvc to call <code>@ModelAttribute</code> after it has already been populated?</p> <p>To elaborate, I'm messing around with the BookCatalog example from chapter 8 from <em>Portlets in Action</em> by Ashish Sarin (Which is really good) and I've run into a problem where the method annotated with <code>@ModelAttribute</code> is only called once even upon successive loads. For instance:</p> <ol> <li>BookCatalog Portlet is displayed</li> <li>Click Edit Book1. Book1 is displayed in the edit form</li> <li>Click home</li> <li>Click Edit Book2. Book1 is <em>still</em> displayed in the edit form</li> </ol> <p>I've added sysouts to the begining of each method to see what is being called where. The results are as follows:</p> <pre><code>showBooks getBook! initBinder showEditBookForm showBooks initBinder &lt;- Where is getBook!? showEditBookForm </code></pre> <p>I read somewhere that <code>@ModelAttribute</code> methods are called whenever <code>@ModelAttribute</code> parameters are requested. So I tried adding <code>@ModelAttribute("book") Book book</code> to the showEditBookForm but that still doesn't seem to trigger the <code>@ModelAttribute</code> method.</p> <p>I'm using Spring 3.1.3.RELEASE and deploying with maven to Liferay 6.1.1.</p> <p>Any assistance would be appreciated!</p> <p>EditBookController:</p> <pre><code>@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); } ... } </code></pre> <p>BookController:</p> <pre><code>@Controller @RequestMapping(value = "VIEW") public class BookController { ... @RenderMapping public String showBooks(RenderResponse response,SessionStatus sessionStatus) { System.out.println("showBooks"); return "home"; } ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload