Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you model form changes under Spring MVC?
    primarykey
    data
    text
    <p>Please bare with me as I try to abstract this problem.</p> <p>Say your writing a web page for fruit vendors using Spring MVC's <a href="http://static.springsource.org/spring/docs/2.5.6/api/org/springframework/web/servlet/mvc/SimpleFormController.html" rel="nofollow noreferrer">SimpleFormController</a>, version 2.5.6. On this page the vendor can do simple things like change their name or their address. They can also change their inventory based on a drop down list filled with present inventory selections.</p> <p>When this drop down list selection changes, the entire form changes to match the inventory of what has been selected. So one stock selection may have bananas and pears, another may have melons, blueberries and grapefruit. <a href="http://i47.tinypic.com/15gwbow.png" rel="nofollow noreferrer">Image to demonstrate what I am talking about. http://i47.tinypic.com/15gwbow.png</a></p> <p>Inside each inventory selection is a input field that needs to be propagated back to the database, for the sake of this example let's say that the user enters the number of fruit.</p> <p>The way this is modeled in the database is that each Stock name is stored in a table, which has a one to many relationship with the contents of each stock, which would be the type of fruit in this example. Then the type of fruit has a one to many relationship with the quantity the vendor selects. Stock name and the type of fruit in each stock are stored in the database and are unchangeable by the user, with the connected fruit quantity table being editable.</p> <p>My question is, <strong>how do you model the form described above in Spring MVC?</strong> </p> <p>I've tried overriding the <a href="http://static.springsource.org/spring/docs/2.5.6/api/org/springframework/web/servlet/mvc/SimpleFormController.html#isFormChangeRequest%28javax.servlet.http.HttpServletRequest%29" rel="nofollow noreferrer">isFormChangeRequest</a> and <a href="http://static.springsource.org/spring/docs/2.5.6/api/org/springframework/web/servlet/mvc/SimpleFormController.html#onFormChange%28javax.servlet.http.HttpServletRequest,%20javax.servlet.http.HttpServletResponse,%20java.lang.Object,%20org.springframework.validation.BindException%29" rel="nofollow noreferrer">onFormChange</a> to facilitate the form change, but I think I may be misunderstanding the intent of these methods. When I change my backing command object the next time the page is post it tries to bind the request into the form, which breaks if you adjust the size of the Stock array (say from 3 to 2, it will try and bind into the 3rd value, even if it is empty).</p> <p>Can anyone help me out with this?</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.
 

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