I have a ListView full of POJOs and want the label in the GUI to display information from the selected item.
My POJO looks something like this:
class Customer { private String name; ... public String getName() { return name; }
Now, when the user selects a customer from the list, I want the name of the selected customer to appear on the label.
Obviously, I cannot bind to name directly, because this is not Property . (And I don't want to replace my clients with String StringProperty objects, because SimpleStringProperty not serializable , and I need to pass Customer through RMI.)
I tried the BeanPathAdapter from JFXtras (which looks really nice by the way) as follows:
BeanPathAdapter<MultipleSelectionModel> customerBeanPathAdapter; customerBeanPathAdapter = new BeanPathAdapter<>(lstCustomers.getSelectionModel()); customerBeanPathAdapter.bindBidirectional("selectedItem.name", lblCustomerName.textProperty());
But this solution only throws me an exception:
... Caused by: java.lang.IllegalArgumentException: Unable to resolve accessor getSelectedItem at jfxtras.labs.scene.control.BeanPathAdapter$FieldHandle.buildAccessor(BeanPathAdapter.java:3062) at jfxtras.labs.scene.control.BeanPathAdapter$FieldHandle.buildAccessorWithLikelyPrefixes(BeanPathAdapter.java:3022) at jfxtras.labs.scene.control.BeanPathAdapter$FieldHandle.updateMethodHandles(BeanPathAdapter.java:2986) at jfxtras.labs.scene.control.BeanPathAdapter$FieldHandle.<init>(BeanPathAdapter.java:2977) at jfxtras.labs.scene.control.BeanPathAdapter$FieldBean.performOperation(BeanPathAdapter.java:1348) at jfxtras.labs.scene.control.BeanPathAdapter$FieldBean.performOperation(BeanPathAdapter.java:1186) at jfxtras.labs.scene.control.BeanPathAdapter.bindBidirectional(BeanPathAdapter.java:567) at jfxtras.labs.scene.control.BeanPathAdapter.bindBidirectional(BeanPathAdapter.java:369) at at.gs1.sync.qm.client.gui.MainWindowController.initialize(MainWindowController.java:61) ... 22 more Caused by: java.lang.IllegalAccessException: symbolic reference class is not public: class javafx.scene.control.ListView$ListViewBitSetSelectionModel, from jfxtras.labs.scene.control.BeanPathAdapter$FieldHandle at java.lang.invoke.MemberName.makeAccessException(MemberName.java:512) at java.lang.invoke.MethodHandles$Lookup.checkSymbolicClass(MethodHandles.java:1113) at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1094) at java.lang.invoke.MethodHandles$Lookup.findVirtual(MethodHandles.java:626) at jfxtras.labs.scene.control.BeanPathAdapter$FieldHandle.buildAccessor(BeanPathAdapter.java:3049) ... 30 more
So, I was hoping there would be a better solution than using lstCustomers.getSelectionModel().selectedItemProperty().addListener(...) and manually handle the tag population there.
source share