• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple Form Buttons

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I am using java beans. As well as sessions.

I want to have more than 1 form buttons in one of my jsp files. For example 2 submit types called: "Back to Step 1"(input1.jsp) and "Proceed to Step 3" (input3.jsp) in a filed called input2.jsp

I want these to be in the form such that when we click "Back to Step 1" (input1.jsp) we go back one step, however, the data in the input fields on the input1.jsp is still visible, so user can edit the data.

and when after editing fields on input1.jsp the "Proceed to Step 2" (input2.jsp) button is pressed , the input2.jsp page appears, with the data we had entered before going back to input1.jsp still visible, so user can proceed with the form.

Also, i was wondering how can we have more than 2 buttons in logic,
as when we declare a form we use method="post" and action="input3.jsp"
So it seems only 1 button is supported:s. which i dont want.

But if i use 2 different forms for the two buttons the data on input1.jsp will not be visible in the form on input1.jsp.

Please help. Sorry Im a bit confused here:s Hope I have make myself cleared.

Cheers,
SA
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"S Ali" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy. User names cannot be obviously fake and must constist of a first name and a last name.

You can change your user name here.

To sucessfully track values through your "wizard"-like forms, all you need to do is create a JavaBean that can hold the values of all the forms you will need to go through, put this bean into the session before you start progressing through the forms, and remove it only when completely done.

Forms can also have multiple submit buttons... you just give each submit button a different "name" value and check for that specific value in the request parameters of whatever resource is specified in the "action" of your form. However, for this to work, you can't specify the next page as the "action"... you really have to use the MVC approach and use a controller servlet. (Or use an MVC framework such as Struts or JSF.)

Thanks! and welcome to the JavaRanch!
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a quick and dirty solution this can be achieved thru JavaScript too. (Although not recommended)
In JavaScript you can check what button was pressed and based on that, you can change the action servlet name (or JSP ) before submit.
Ex: If the form name is FaxForm, the code required to change the action target would like:


To show the previous page from the caches (when user submits back button) you can use following JS

[ October 08, 2004: Message edited by: Manoj Gundawar ]
 
Sana Ali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
would this mean the out put will be stored still in the fields, while we are moving back and forth the pages?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sana,

Another solution might be to save yourself the trouble of having to travel to-and-from the server for each of the steps of your wizard...

Instead, consider using the magic of CSS and DHTML to construct each of the panels of the wizard in a separate <div> container that is hidden/shown upon proper validation of the previous panel...

1. Page loads, shows <div id='first'>
2. User fills out form elements in div#first; clicks [next] button
3. [next] button calls a validate/update function that first verifies the data and then hides div#first and shows div#second.
4. continue for as many panels as necessary.

All of the elements are contained in a single form. The last button ([save]) or whatever can then submit the form.

The primary benefit is not having to perform trips to the server just to break the content up into manageable chunks.

Two biggest downsides are:
1) It requires some work to properly deal with which <div> should be shown when the server detects errors in the form data. This isn't impossible, but it's an issue that has to be addressed.
2) If div#third has form element data that is dependent upon the content provided in div#second, this could be tricky. For example, page one selects continent, page two selects country (based on continent), page three selects state or municipality (based on country), etc.

Good luck!

-daniel
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic