Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>formBackingObject()</code> is expected to set up the "command" Object that is supplied to <code>onSubmit()</code> on the next submission. The command Object is just a <a href="http://en.wikipedia.org/wiki/Plain_Old_Java_Object" rel="nofollow">POJO</a> that you can create and add attributes to as needed.</p> <p>Normally you populate the command Object with some data to be displayed on the screen from a service call (which ultimately comes from the DB) but there's nothing to stop you placing data that arrived in the request in <code>formBackingObject()</code> into the command Object and pulling it back off again when <code>onSubmit()</code> is called. The advantage of doing this is that you don't end up with <a href="http://en.wiktionary.org/wiki/cruft" rel="nofollow">cruft</a> floating around in your session.</p> <p>For example, put a boolean from the request in <code>MyCommand</code> in <code>formBackingObject()</code>:</p> <pre><code> protected Object formBackingObject(HttpServletRequest request) { boolean someBoolean = ServletRequestUtils.getBooleanParameter(request, "someBoolean"); MyCommand myCommand = new MyCommand(); myCommand.setSomeBoolean(someBoolean); // optionally get some data from the DB to set on myCommand here... return myCommand; } </code></pre> <p>Then find that boolean inside the request in <code>onSubmit()</code>:</p> <pre><code> protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) { MyCommand myCommand = (MyCommand) command; if (myCommand.getSomeBoolean()) { System.out.println("someBoolean was set in formBackingObject!"); } } </code></pre> <p>Note that myCommand is only visible to the session (so no other logged in users can see it, and it is destroyed when the session ends).</p>
    singulars
    1. This table or related slice is empty.
    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.
    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