File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes retaining values in a posted form... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "retaining values in a posted form..." Watch "retaining values in a posted form..." New topic
Author

retaining values in a posted form...

Vin Man
Greenhorn

Joined: Jun 13, 2001
Posts: 26
An impass I recently encountered is how to retain the values in a posted form. Here is what I am trying to do: I have a form which acts as a data-entry form, but it also allows the user to narrow down valid entries based on his previous input (kind of like a search form on www.autotrader.com). So everytime the user selects a value on a drop-down(says Acura), I post the form to a servlet, which hits the database and narrows down the other dropdowns (for example, all the Acura Models) filtering, and forward back to the same form. How do I make it so that the values entered in any text input fields are retained?
Thanks in advance...
Roger Nelson
Ranch Hand

Joined: Feb 21, 2002
Posts: 95
From what I understand, ( applying the mvc pattern)I would prefer to have a bean that maps the information from the form.
For eg: when a make information of a car(acura) is supplied, the servlet populates the bean with information, queries the database, retrieves model information for the car( acura models), populate the bean with this information, and then use the bean while displaying the form with the additional information.
I hope the pattern applies to your problem.
Steve Granton
Ranch Hand

Joined: Jan 13, 2002
Posts: 200
Hi,
The main thing to keep in mind when you want the contents of a dropdown to change depending on user input is the speed that it needs to happen - obviously the round trip time back to the server introduces a delay that the user may not be willing to tolerate.
In fact the way we do this sort of this is through multidimensional javascript arrays - all the values are loaded once on the client side then the change is instantaneous.
The example you gave also uses this javascript approach. They have all the values stored in a javascript file that is included in the page - you can check by viewing the page source. You can check this by downloading the js file that they use as it isn't inlined into the page source - http://www.autotrader.com/newcar/modelarray.js
Personally, I'm not a fan of javascript as its a nightmare to debug and users can configure their browser to disable it.
I hope this helps,
Cheers,
Steve
Vin Man
Greenhorn

Joined: Jun 13, 2001
Posts: 26
Roger,
Thanks for the response... and yes, I am using beans to hold the values for each of the selection lists (i.e., car makes, and dependent on the car makes, the car models). The beans are being referenced by the same JSP, which gets forwarded to every time a car-make selection is changed. There are, however, free-form text information which the user has entered and which I want to retain each time the user changes the car-make selection. I was hoping for something easier than having to use a bean for this... any idea would help.
I like the idea of multi-dimensional javascript array, as suggested by Steve, but debugging it would be a nightmare.
Thanks guys...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: retaining values in a posted form...