1

I am designing an intranet application with Spring MVC3. I have to create a JSP page which has a data grid which is populated form the database and user and can add rows in the JSP data grid. I was considering the following two options:

  1. To use javascript function to add a row on an "Insert Row" button
  2. To submit the form on "Insert Row" button, go to Controller and return a model attribute with an extra row.

I am more bent towards the controller approach, as I feel I have better control on the datatable in the controller.

Can you please suggest which would be a better approach considering some of cells of the new row may need to be set with some default value.

Please note that I cannot use jQuery or any other javascript library.

arun
  • 86
  • 1
  • 5
  • Do you want your website to still work when the client has JS disabled? – BalusC Oct 18 '11 at 18:22
  • @BalusC: Yes I would want that, but then I cannot avoid JS altogether, meaning I still may have to use JS for some other functionality (say displaying the total of "Amount" column as soon as user moves out of an "Amount" cell) – arun Oct 18 '11 at 18:33
  • 1
    You don't necessarily need to avoid JS. You can just use it for progressive enhancement to improve user experience. – BalusC Oct 18 '11 at 18:52
  • @BalusC: Thanks, as I understand, its boils down to my preferences then :) I will be using the contoller approach then, and use JS to improve user exp. Thanks again – arun Oct 19 '11 at 05:54

2 Answers2

1

You can do it either way.

If you are binding the form to a backing object you will need to lazy initialize the form backing object(s).

This was helpful for me.

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
  • Thanks for your answer, I guess I will be adding the row in the Controller itself. Since its an intranet app with only a few users, I dont think an extra server trip should be an issue. – arun Oct 19 '11 at 06:07
0

I know this thread is old but it can help others. The elegant solution of this problem is to use AutoPopulatingList provided in spring core. With small small java tweak you can handle dynamic binding. A good tutorial explain this in detail is http://blog.richardadamdean.com/?p=12. Also checkout Issue Binding AutoPopulating List to a form Spring MVC that explain possible problem you might face while integration.

Community
  • 1
  • 1
Mohammad Adnan
  • 6,527
  • 6
  • 29
  • 47