I am creating a list on my first JSP by typing in values, clicking a button an appending the value to a list. I would like to take this list from this JSP and populate a list on a second JSP. The first list establishes a main directory list. The second adds data to each category.
Originally posted by Steve Dyke: I am creating a list on my first JSP by typing in values, clicking a button an appending the value to a list. I would like to take this list from this JSP and populate a list on a second JSP. The first list establishes a main directory list. The second adds data to each category.
Are you doing this by posting back to the server or with Javascript on the client?
Yes I am posting back to server. I have this issue resolved. Thanks for the help.
I now have another JSP List issue. Again I am building the List on the fly with in the JSP buy user inputing text, clicking a button an adding to list control using JavaScript. When I submit how can I use the list content as an array on my servlet? The items in the list are delimited strings that I will need to parse also example: 861766-401,1,1,45. This is a part number, qty, config, associated seq number.
If something like 861766-401,1,1,55 were the value in the select list options, then sure, you could split it after retrieving it with request.getParameter.
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1261
posted
0
In my JSP I have a ListBox. How do I pass this List to the Servlet so the Servlet treats it as an Array?
Well, only the selected ones get posted so, you could either select them all using Javascript from the onsubmit event of the form, or, you could store them as hidden input fields in the form and they would all get sent up that way. This would allow you to use the select list to find out which one the user really wanted to select.
Another alternative would be to store them on the server as session variables so that the servlet already has access to them and they don't need to make the round trip to the browser and back.
Without knowing more of your requirement, it's hard to say what the best approach will be for you.
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1261
posted
0
Here goes my best explanation.
The user opens up a form(JSP). It prompts them to supply a list of part numbers that will eventually populate a Buyer Furnished Equipment List(a report that will be displayed in an excel format). On this form there is three input boxes and one listbox and two buttons.
The inputboxes: one for part number, one for configuration, one for quantity.
The Listbox: used for recieving and displaying user input.
The buttons: One button is a general button and is used after the three input boxes are populated to populate the listbox with one item that is a concatination of the values. Then the three input boxes are cleared. The user can type in another set of values, click the button and this set of values are added to the listbox thus creating a list(not a select list in this case but an input array of values).
The second button is a submit button that calls the servlet.
How do I pass the contents of the list that was just created(all of it) to my servlet so the items will be treated as an array of values?
With HTML forms, if multiple form fields have the same name or in the case of a multiple select list item, the servlet api will present the items to the developer as an array.
Are you posting an HTML form parameter named 'tclist' to the servlet? If not, getParameterValues will return null.
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1261
posted
0
Yes, the html has parameter names tcList. If I execute the following javascript on my submit I get undefined eventhough there are several items in the list:
var tcList = document.getElementById('tcsal'); alert(tcList.listCount);
I think I have figured it out. 1. I had to turn the Allow Multiple Choice on 2. I had to step through the list to select each item
Thanks for all the help. I am sure I will back with another issue shortly.
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1261
posted
0
Well I thought I had it done until I started working with my AJAX portion of code. How do I use the listbox as a parameter in my url string for the AJAX call?
Originally posted by Steve Dyke: Well I thought I had it done until I started working with my AJAX portion of code. How do I use the listbox as a parameter in my url string for the AJAX call?
Something like this would be done with Javascript, on the client.
Normally, I'd move the thread to our HTML/Javascript forum but it is already very long and full of non Javascript questions.