• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Beans binding with local variable

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic