aspose file tools*
The moose likes JSF and the fly likes Find Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Find "who triggered" from actionListener" Watch "Find "who triggered" from actionListener" New topic
Author

Find "who triggered" from actionListener

Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

Im using a dataTable in which I created several components.
One of the component is a Button with different display value for each row.

However, all my buttons are set with the same id and actionListener.
How can I know which button was pushed by the user ?



Lets say that my *myBean.myVendors* collection contains 4 entries : 4 buttons will be created and I would like to know which one was hit in my listener.

How can I do that ? I tried a whole bunch of stuff, looked at every property in debug... nothing will do. The value of my buttons are all diferrent though, but I can't access this property.

I'm certainly missing something big...

If anyone can help me, it would be appreciated.

Thanks,
Alex
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
You must be having the event object in the listener. Call getComponent() method on the event object to get the UIComponent. Once you get the hadnle of this UIComponent, you can easily find out which component by clicked. Check the api to see which all methods you can use.


- Varun
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

both, no matter what property I access via getComponent, all my buttons have the same value.

I want to know which button from which row was hit...

Do you see what I mean ?

Thanks,
Alex
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

You might want to take a look at this thread.


GenRocket - Experts at Building Test Data
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

I saw your post, but the answers seem to talk about something else.

I cant believe there is no way to know which row was selected !

Or no way to dynamically set different id for each of my buttons.
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Originally posted by Alex Turcot:
Hi,

both, no matter what property I access via getComponent, all my buttons have the same value.

I want to know which button from which row was hit...

Do you see what I mean ?

Thanks,
Alex


Does all the component have same id? That isn't possible else you would get "Duplicate Component Id", anyways I believe in your scenario those id wont be of any help as they are normally like id_27 etc. which cant help much.

Now as Gregg pointed, table.getRowData() method returns the selected row in the data table. This way you can find out the index of selected row and hence the buton which was clicked.
That can help you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Find "who triggered" from actionListener