• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to retrieve “Grouped” items from HTML form using Servlet?

 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christian Taylor
Greenhorn
Posts: 8
1
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rgeardless, they are completely unnecessary and overcomplicate the markup needlessly, and the name attribute usage upon them is invalid.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christian Taylor wrote:
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.
 
Christian Taylor
Greenhorn
Posts: 8
1
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. Kevin Robbins wrote:
Christian Taylor wrote:
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.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer in SO really worked. Thanks for the help guys.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!