Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Beans binding with local variable

 
Mahesh Kedari
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Is it possible to bind a local variable with beans?

I have bound my JTable with binding expression as ${selectedElement.studentID} with my JTextField and in JTextField I am able to see the ID of selected element in table.

But I want to get this selected element in my local variable.
i.e. When user selects one record in table, my local variable
public Students selectedStudent should get updated to ${selectedElement} of JTable.

Hope my description is not confusing.
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The local variable does not exist outside the scope of that single method call. When you select a record in the table that variable only exists if from the event handler you call the method. If this is the case then simply pass the selected record as a parameter to the method.
 
Mahesh Kedari
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot Rob for your reply.
Sorry but i did not understand how exactly I should get that selected record for passing it to method. I am able to get the selected row, but I am unable to get its primary key of the record as it is not visible in table.
Could you please throw some more light on the method you are talking about. I'd be very much thankful if you give some example.

I'll try to explain the problem some more.
I have a table in database called actor



In this table, I am displaying only First_Name and Last_Name in JTable. I want to get an Entity bean object of Actor for selected record.
 
Mahesh Kedari
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got the solution. But not sure whether its a right way to get that.

I've created one more temporary entity class as shown below.



I have initialized a variable with this entity and bound the same with this entity class as shown below.



I hope this is the correct way to bind selected element in table to local variable. I would like to know if there is some other efficient way of doing so.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic