Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate a form with multiple checkboxes in spring
    text
    copied!<p>I have a game and a developer. The game has a set of developers. I want to create a form where I can add a game to the database. In the form I enter the name, price and check the developers. So i create a checkbox for every developer. However when I check those the page just seems to refresh. When I debug it seems that my controller never gets to the doSubmitAction function. When I leave out the checkboxes everything works as it is supposed to. Is spring unable to create the collection? I don't understand fully what is happening behind the scenes of Spring. This is my first project I'm creating using spring.</p> <p>Here is my form:</p> <pre><code> &lt;form:form method="POST" commandName="game" &gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; Name &lt;/td&gt; &lt;td&gt; &lt;form:input path="gameNaam" size="20" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Choose Developers&lt;/td&gt; &lt;td&gt; &lt;form:checkboxes id="selectdeveloper" items="${developers}" path="developers" itemLabel="naam" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Price &lt;/td&gt; &lt;td&gt; &lt;form:input path="prijs" size="10" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="submit" value="Add" /&gt; &lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form:form&gt; </code></pre> <p>And the formController:</p> <pre><code>public class GameFormController extends SimpleFormController { private GameOrganizer gameOrganizer; public GameFormController() { setCommandClass(Game.class); setCommandName("game"); setFormView("AddGame"); setSuccessView("forward:/Gamedatabase.htm"); } public void setGameOrganizer(GameOrganizer gameOrganizer){ this.gameOrganizer=gameOrganizer; } @Override protected Object formBackingObject(HttpServletRequest request) throws Exception { Game game = null; long id = ServletRequestUtils.getLongParameter(request, "id"); if(id&lt;=0){ game = new Game(); }else{ game = gameOrganizer.getGame(id); } return game; } @Override protected void doSubmitAction(Object command) throws Exception { Game game = (Game) command; if(game.getId()&lt;=0){ gameOrganizer.addGame(game); }else{ gameOrganizer.update(game); } } @Override protected Map referenceData(HttpServletRequest request) throws Exception { Set&lt;Developer&gt; developers = gameOrganizer.getAllDevelopers(); HashMap&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;(); map.put("developers", developers); return map; } } </code></pre>
 

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