First of all, I have posted this question in here but not satisfied with the answers.
I am having an issue with retrieving "grouped" data from HTML form to servlet. I will describe the scenario below.
In companies, they record the salary of the employees once a month.When they record it, they do not do it by visiting each an every employees personal "profile" (or whatever according to the system). Instead what they do is apply the salaries of all of them in one page.
To do the above thing they prefer excel like tabular sheets.
Now, I have a html form, where the form content is a table. One row is dedicated to a one employee.
Below is my form.
As you can see, I have wrapped every row with a `<tbody>`. The `value` attribute of the `<tbody>` will contain the employee id.
Once the form is submitted, the below servlet will capture it.
What I was trying is get the `value` attribute of `<tbody>` (so I can identify the id of the employee) and get the data inside that `<tbody>`. However this didn't work, because I ended up with `NullpointerException` because it failed to read the `<tbody>` value.
So, how can I pass the data from table to servlet where it can clearly understand that one row is representing data belong to a one employee? If this is not the way to do it, I am also open for other methods.
Are you better than me? Then please show me my mistakes..
Perhaps you should explain why you are not satisfied with the answers you got on SO. The first response explains it pretty clearly. You need unique name values for each field and appending an employee id as the table is built seems like the best way to me.
And incidentally, having multiple tbody elements in one table is invalid html and will only cause you problems.
"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
J. Kevin Robbins wrote:And incidentally, having multiple tbody elements in one table is invalid html and will only cause you problems.
This appears to be incorrect. According to the specs for both HTML 5 and HTML 4, a table may contain multiple tbody elements.
That's interesting. I stand corrected, but now I'm wondering why you would want to do that.
Grouping of rows could be useful in some scenarios, for styling purposes or possibly manipulating the DOM to sort or move groups of rows more easily than each related row individually. Bear is certainly correct that they don't help anything in this situation and they are being used in an invalid way, so I'll leave it at that and not take this any further off-topic from Yohan's original question.