• Post Reply Bookmark Topic Watch Topic
  • New Topic

Big form data passed  RSS feed

 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
My problem is as follows and i hope you will help me find the appropriate solution.
I have an html form with 200 input fields of type text. The first input field contains the name of a book author and the remaining 199 fields hold each a title of a book that he or she has written. I also have a servlet that processes the form data and sends it to a file. The entered data is restricted to a combination of the characters "a...z A...Z". Please note the white space. Now, how do i go about with creating my html page. I started it like this but got stuck. The input fields are just too many and i have no idea on how to retrieve the 200 values in servlet.


I am so impatient to hear from you.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of using "bookTitle" for several titles you could use "bookTitle1", "bookTitle2" etc. Instead of adding all those empty fields no matter what, I would only maybe show 10 at the beginning, and then add more via JavaScript as needed. Otherwise the page gets unwieldy (not that anyone wants to enter 200 titles manually).
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,
Thanks for your reply. But the 200 text fields have to show at a go ready for entry.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You (or whoever set that requirement) may want to rethink that, it's a bad UI. How many web pages can you recall that allowed you to enter 200 data items all on the same page? There's a reason for that.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,
I think it is something doable but i cannot figure it out yet. I am going from the principle that if it can be done for 50 why not 200? I also want to mention that entry can be made at random inside the page. Just that an empty field must not be accounted for during writing to file.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going from the principle that if it can be done for 50 why not 200?

That's not really a principle. It certainly *can* be done, it's just not a good UI. But I take your point that this is a complication that you are not ready to tackle.

I also want to mention that entry can be made at random inside the page. Just that an empty field must not be accounted for during writing to file.

Well, that's easy to check in the servlet code - call trim() on the title string, and if its length is 0, don't save it.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But I take your point that this is a complication that you are not ready to tackle.

I am presently pondering it and any help is most welcome.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,
Somebody hinted me to rather use a jsp for the entry page. These experienced people, they never tell in details how things work. They just give some clues and that's it.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't really matter how you generate the HTML page; JSPs are a common approach. But the processing would happen in a servlet, not a JSP (which do no such processing).
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From a human engineering / user interface point of view, the whole idea of expecting a user to type a hundred lines of form entry without error or interruption is preposterous.

Imagine the frustration when on the 99th line your power drops for a second due to a lightning stroke or you get called to the phone!

I would say it is time to back off thinking about the servlet / form mechanics and think about the user experience. Use the power of the technology to support your user not make the user a slave to the interface.

Let the application support entering one book at a time, building a list that is backed up to storage and displayed as part of the HTML .

Think of the support you could add - look up ISBN numbers on Amazon for example....

Bill
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Let the application support entering one book at a time

Hi William,
I thank you for your suggestions and your interest to the topic. I have no other way than to obey to what i have been tasked. Though I know that is very poor design.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no other way than to obey to what i have been tasked. Though I know that is very poor design.


That is rather sad, you have my sympathy. Hopefully, future projects will let you have more freedom.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi William,
Thanks a lot for your support. They have reviewed the specs to a reasonable point. Now the form should contain 70 input fields. One for the author name and 69 for the book titles. Ulf suggested to change the input text fields names to bookTitle1, bookTile2, etc... But still they are just too many. I will have to test each of them in my servlet and that may take me hours. Do you have any more efficient mehod?
Kind regards.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
70 is still bad, but let's leave that aside.

I will have to test each of them in my servlet and that may take me hours.

What about this will take hours? It's not like any piece of code will be replicated 70 times ... I think I'm missing something.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It's not like any piece of code will be replicated 70 times ... I think I'm missing something.

Hello Ulf,
I am glad to hear from you. You are always there when i post a message, ready to give help. I also do not seem to understand you. Do you suggest that i create 69 input fields with names bookTitle1, bookTitle2,...,bookTitle69?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting confused now. Your latest post seems to have nothing to do with your post before that. Or if it does, I don't understand the connection.

My last post was in response to yours, where you were talking about server-side code, and how it would take long. To which I replied I didn't understand why, and could you elaborate - which you have not done so far, so I can't add anything to that.

Now you're talking about the client-side. One way to handle 70 otherwise identical fields on the server is to give them predictable names like "bookTitle1" etc., precisely so that you don't have to duplicate code on the server, but can process them in a loop. (And since you ask specifically whether *I* would suggest that - well, only in so far as it solves your problem. I still think it's bad design, but I feel like a hung record saying that over and over, so I will stop saying it now.)
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTML supports arrays for attributes. In other words, a GET URL such as "/mywebapp/titleform.do?author=Charles+Dickens&title=A+Take+of+Two+Cities&title=David+Copperfield&title=A+Christmas+Carol"

would return an array for "title", with each element being one title. The same is true for POST, but it was easier to illustrate as a GET.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

HTML supports arrays for attributes.

Hi Tim,
I thank you for your contribution. If i get you well, i can use the same name for all my input fields. But how am i going to retrieve them in my servlet?
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Ngom wrote:
But how am i going to retrieve them in my servlet?

There's a getParameterValues() method on the request object which returns a array of String values. See http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getParameterValues%28java.lang.String%29
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Jaikiran,
I thank you so much. My problem is now solved. I also thank all those who have participated in this topic.
KInd regards
 
Daniel Val
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Ngom wrote:Ulf,
Thanks for your reply. But the 200 text fields have to show at a go ready for entry.


I can guarantee that if somebody expects to enter 200 book names and then hit submit, probably the session will expire and the headache will be major. I would suggest you allow entering 10 at a time, and keep adding a number of times.

Otherwise: you generate the page from the servlet, in a for loop you generate the html code with the fields, and that will do the rendering. Personally, considering you have 200 times one field and not one collection of fields, you can give the same name and then retrieve them as an array with request.getParameterValues where you put a name and then you get a String array with all the values.

But again, 200 fields before you submit is an issue and if this is the requirement you have to talk to the business person out of this approach.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, Daniel. Thanks for your guidance.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!