aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Form Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Form Problem" Watch "Form Problem" New topic
Author

Form Problem

naro pad
Ranch Hand

Joined: May 07, 2008
Posts: 58

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

Joined: Jan 10, 2002
Posts: 61756
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

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

Joined: May 07, 2008
Posts: 58

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

Joined: Jan 10, 2002
Posts: 61756
    
  67

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

Joined: May 13, 2008
Posts: 10
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

Joined: Jan 10, 2002
Posts: 61756
    
  67

"newbean", please check your private messages for an important administrative matter.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Form Problem