wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Same element name in a form to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Same element name in a form to servlet" Watch "Same element name in a form to servlet" New topic
Author

Same element name in a form to servlet

Arvind Subramanian
Ranch Hand

Joined: Jul 25, 2008
Posts: 84
In a form assume each row has 2 text box and totally 20 rows
so I have 2 X 20 =40 text boxes .

Each row means key - value pair , which i want to take to servlet.

wat i planned was naming all the element with 2 name as key and data
client side


server side


Doubt
whether in all times
id[1] == data[1]
Whether by index can we able to find the matching relation? is there any possiblility that index can be changed then order it was provided...

If its not understandable please post...

"Many of lifes failure are people who did not realize how close they were to success when they gave up."
-Thomas Edison
~ar~stutzen~
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Doubt
whether in all times
id[1] == data[1]

You can check this at server side by printing the values.
Whether by index can we able to find the matching relation? is there any possiblility that index can be changed then order it was provided..

If index changed, then on javascript change the value.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Arvind Subramanian
Ranch Hand

Joined: Jul 25, 2008
Posts: 84
I checked and getting correct order as displayed, but it seems completely depends on browser. If browser sents in different order then my business logic will crash.
Its actually not to check the value.
It will update the DB with the data for coresponding key. so based on the index i will form the query string, so if the order changes then wrong data will be updated for the wrong row in the db.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Form elements are normally submitted in the order defined--but you'd have to check the spec to see if this is enforced by the spec. Even then, like you, I'd be nervous about depending on the browser to always do the right thing. Personally I'd consider using an indexed notation.
Arvind Subramanian
Ranch Hand

Joined: Jul 25, 2008
Posts: 84
indexed notation ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

foo[1], foo[2], etc.

Not using a framework that handles things like this automatically makes for extra work. You might be able to use an existing EL implementation to make things easier, but I've never actually tried using one outside of a framework that already supports it.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

David Newton wrote:Form elements are normally submitted in the order defined--but you'd have to check the spec to see if this is enforced by the spec.


It is not.

A framework isn't really needed. Using indexed notation means that it'd be easy to use normal bean injection into indexed properties. For example, the Jakarata Commons BeanUtils utility class will handle indexed properties nicely.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Same element name in a form to servlet
 
Similar Threads
need help :: multiple rows update without primary key
how do I know Edit Database Record
Read JavaScript array values in Java class
JQuery: Problem with $(this).find('input'). serialize()
xsl: create href for one tag with value in param among multiple