This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes Enumeration or a better way Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Enumeration or a better way" Watch "Enumeration or a better way" New topic
Author

Enumeration or a better way

Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
I have a Form with 15 inputs that is processed and sent in an email.

I am using Enumeration to process and display the information. But I need exact order of how the information is displayed and Enumerations do not guarantee order so I have to do this:





Any better way to do this? Please advise because I dont have Struts and probably wont be allowed to get it for a long time.
[ October 25, 2007: Message edited by: Mike Jenkins ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

HTTP itself doesn't guarentee an order, so using the enumeration isn't adding anymore uncertainty than you are already faced with.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57

HTTP itself doesn't guarentee an order, so using the enumeration isn't adding anymore uncertainty than you are already faced with.

Thank you.
I should continue using Enumeration?
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
I am not clear

Why do you process the elements in a loop? Aren't you suppose to read the 15 parameters once and compose the message text? I think you must be doing
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

Originally posted by Mike Jenkins:
I should continue using Enumeration?


If the order of the fields is important to you, you need to back up and figure out a way to guarantee that. The order that the fields appear in the form is not guarenteed to be the order that they are submitted to the server, and on top of that the Enumeration could further jumble them up.

So what I am saying is that if order is important, you need a new design.
[ October 25, 2007: Message edited by: Bear Bibeault ]
Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
Very interesting. Thanks to both of you.

Any links or tutorials on the web you can suggest that I view to guide me with a design that will help me in this situation?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

Why don't we just explore it more here?

Start by explaining what the order is. Is it the order of the fields on the form? If so, is the list of field names dynamic, or are they known in advance?
Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57

Start by explaining what the order is. Is it the order of the fields on the form? If so, is the list of field names dynamic, or are they known in advance?


Thanks for your time on this!

I want it listed in the order of fields as shown on the form as seen below and the list of field names are known in advance.

Here is my JSP Form page with 6 out of the 15 field inputs listed:

[ October 25, 2007: Message edited by: Mike Jenkins ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

Since the field names are known in advance you can do one of the following:

1) Hard-code an array of the expected names in the desired order in the servlet and retrieve the parameters in the order specified.

2) if you want to be a bit more flexible, create a hidden param in the form with a comma-delimted list of the names in the desired order. The servlet can obtain and split this value to determine the names to retrieve in order.

I'd opt for the de-coupling that the second solution provides even though it's a tad more work.
Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
2) if you want to be a bit more flexible, create a hidden param in the form with a comma-delimted list of the names in the desired order. The servlet can obtain and split this value to determine the names to retrieve in order.

I'd opt for the de-coupling that the second solution provides even though it's a tad more work.


I like this info.
Thanks for your time and guidance!
[ October 25, 2007: Message edited by: Mike Jenkins ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enumeration or a better way