aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Beans binding with local variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Beans binding with local variable" Watch "Beans binding with local variable" New topic
Author

Beans binding with local variable

Mahesh Kedari
Ranch Hand

Joined: Nov 28, 2009
Posts: 111
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.


Regards,
Mahesh Kedari - Fidus Technologies Ltd.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mahesh Kedari
Ranch Hand

Joined: Nov 28, 2009
Posts: 111
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

Joined: Nov 28, 2009
Posts: 111
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Beans binding with local variable