• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Form Problem

 
naro pad
Ranch Hand
Posts: 58
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm new to jsp world so I want some help...is very important to me so I will explain it in details

I have a jsp which display a form to be filled out. I have some text fields where the user fills them and submit the form. The form next is passed to a jsp page where I'm using some beans, setProperties to save the data to database.

Now my problem is:
I want to add in my form a part where the user can add a book. A book may have author,title,edition,publisher. If it was to provide to fill only one book this it could be easy done by having the appropriate text fields and then in process jsp to get the approprite parameters and save the data into database.

I want to add more than one book. I want to have a button let say which it will give the chance to the user to enter the first book and next as many times the button is click to add as many books. (My Idea...)Shall I have to create another form inside the main and each time the button is click to create subforms.

How is this can be done... which mechanism... any reference?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by panayiotis panayiotou:
The form next is passed to a jsp page where I'm using some beans, setProperties to save the data to database.

This is not a good practice. Modern web applications do not use JSPs for data processing. Rather, your form should submit to a servlet that handles the data processing and delegates the database functions off to Java classes that have nothing to do with the UI.

Perhaps this article will be helpful.

The rest of your question is not JSP related, but are things that are related to the client (HTML and JavaScript). I have moved this post accordingly.
[ May 14, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by panayiotis panayiotou:
Shall I have to create another form inside the main and each time the button is click to create subforms

No. There are no such things as "subforms". It is not valid to place forms inside another form.

Rather, upon clicking the "add more" button (or whatever), you'd use JavaScript to create new sets of form elements that become part of the original form.
 
naro pad
Ranch Hand
Posts: 58
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you'd use JavaScript to create new sets of form elements that become part of the original form.

Ok...How can I do that?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the DOM manipulation API, or you could use the innerHTML properties of DOM elements. Grab a good JavaScript book or reference and these will be detailed.

Use of a JavaScript library such as Prototype or jQuery also makes this easier.
 
john adams
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I understand your challenge.
If your jsp page is used to imput two different things (e.g user info in the first part and book info in the second part; then you need two javabeans, each updating it's own database table. Set up a unique key for the user and include that unique user key for each book the user adds to the database, that way you can perform a multi table query using based on the key, to retrieve the user and all the books he added to the database table.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"newbean", please check your private messages for an important administrative matter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic