Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to achive server validation of a dynamic form

 
naro pad
Ranch Hand
Posts: 58
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I will try to explain hopefully:

I have a form where I have some text fields where the user has to fill. If not when the form is submitted I have create a bean where using


I set the values written from the form and then using a validate function

I display the appropriate error, if not the form is submitted. Now I have put into my form the ability to the user to add dynamically text box. (addind as many books he want) using DOM. Now I have manage to save how many books he has add using a variable increment each time he press the button to add a new book and pass it as hidden value. The new textbox created I name them appropriate book'1',book'2' and so on...

How can I continue my(server) validation for this... any ideas or links. I have think about of crating an array of objects book but then how can I validate them...

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's so different about validating values in an array over validating a single value? Just loop over the array values, validating each one.
 
naro pad
Ranch Hand
Posts: 58
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I agree with you but I have this:


Suppose that I have implement the array with all the books added how I will pass it to formHandler? With static textbox is ok because I have created variables in my FormBean and I assign them the values enter from the form them and validate them using function...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, to start off with I'd never be using a JSP for this.

Modern best practices dictate that data processing should take place in a servlet or classes delegated from a servlet.

That would simplify things considerably since you are just writing Java at that point rather than dealing with JSP stuff as well.

I'd advise this refactoring.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic