We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Question on how to capture a clicked item on a table and pass to a Servlet?

prain
prain asked
on
Medium Priority
214 Views
Last Modified: 2010-04-01
Hello,

How do I capure an item clicked on a table and send it to a Servelt? For example Say I have a table like this...

   item1      item2        item3
   item4      item5        item6
   ------       ------        ------

Say I click on item5. I need to pick this item and call a Servlet so that I pass the value 'item5' to the
servlet.

Thanks
prain
Comment
Watch Question

Commented:
Hi,

There are two options

1) When you click on a particular item, have a onclick event , set the hidden parameter in the form with this particular value and then submit the complete form (This means refresh complete page) and the action of the form should be the servlet.

2) Use AJAX and have an action make a java call (with servlet)

fargo

Author

Commented:
So do I have to attach an onClick event for each item in the table?

Commented:
Yes, how are you getting the items in thetable? You could use a scriptlet for doing this.

Author

Commented:
Within my servlet that prepares the table, I am having a variable. So the items that you see in the table are NOT
hard coded they are genrated dynamically. This is the line that I create each cell . the

displayName

is a java String variable.


out.println("<td>" + displayName + "</td> ");

So what I need is to pickup the value presented by t he displayName (visible in the table) and then
pass that value to a Servlet.

Thx.

Author

Commented:
Hello,
I am increasing the points to 125.

I am getting the whole table messed up when I attach onClick or any other in each cell.

Again, here is what I want.

My table is generated by a Servlet. The Servlet has a loop within which I have this code.

out.println("<td>" + displayName + "</td> ");

where displayName is a java String variable. So when the table is created, item visible on each cell is created dynamically.

So I will have a table like this....

  item1      item2        item3
  item4      item5        item6
  ------       ------        ------

This works nice and the table is generated nicely. Now I want add some spice to that. I want to make each item a selectable item and then when selected I want to call a Servelt and I want to pass that selected item to teh servlet. Any help?

Commented:
>> I want to make each item a selectable item
ok. What do u mean by selectable item?

Do you wish it to be a link?
Do you wish to add a checkbox to each item?

What exactly?

fargo

Author

Commented:
Actually it sould go to a Servlet. We we can say it s a link.
Commented:
well,

if it is a link, it makes the job quite easy.

<a href="/to/your/servlet?param1=itemValue">item1</a>

you click on this link in your table and you go to a servlet. Will this be of help?

fargo

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
fargo,

Goodie!. I got it. Thanks for all hints. a+

prain
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.