Forums Register Login
Enumeration of parameterValues and shopping cart behavior
I'm seeking some experienced advice on handling the behavior of a shopping cart related to how parameter values are pulled off the request object in an Enumeration.
Given a shopping cart form--admire the ASCII art--:

Currently each line item has a form that provides a text element to change the quantity, a hidden field that provides the "SKU" and a submit button. In this manner the query string is practically guaranteed never to contain more than one item and SKU when updating the quantity ordered. For example:

This works well but complicates the usability of the order form in a production environment. So, following the lead of larger operations I have been toying with a new layout:

Now the page is just two forms. The first form encompasses the body and the recalculate button. The secord submits the form.
Now, instead of pulling a single parameter of the query string I should use getParameterValues() which returns an Enumeration. However, and the crux of my problem, the Enuneration interface does not provide a guarantee of order. Hence there is a very real possibly of incorrect orders being submitted. Now I have considered using instead getParameterMap(). Order is guaranteed, only base on the natural order of the key! Argh. So given a query string:

The Map might look like:

The context of the order form is lost. Any suggestions?
PS. I'm using beans and other backend objects in assistance, its the initial processing that I'm trying to sort out.
One approach could be: rather than naming all your elements the same, when you generate the page give them unique indexes. Perhaps something along the lines of 'sku_0', 'sku_1', 'sku_2' and so on. Then it'd be an easy matter to associate the line item values that belong together when you pull everything out of the enumeration.
[ June 09, 2003: Message edited by: Bear Bibeault ]
A good and simple solution. Eluded me probably because I was seeking to make it more complicated that it needed to be. Thank you for the suggestion.
permaculture is giving a gift to your future self. After reading this tiny ad:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter

This thread has been viewed 772 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 22, 2018 15:40:31.