• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

PropertyValueFactory cannot read from unreadable property

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again,

Thank you for the all the replies on my previous post, I managed to make some progress with my application but I found myself stuck once again. So I'm working on this student management application that stores and retrieves data from a database. I have 2 tables, students and modules. My first table 'Students' was working as intended, I was able to get the user to input student details and store them on the database and then display the table to the user using a TableView, now I added the second table 'Modules' and while I'm still able to insert data onto the table, when I try to display it back to the user using the same method as I do for table now, the student ID column is not displaying any data and I'm getting that annoying PropertyValueFactory error again. I don't know if this is relevant but student_id is a foreign key from students table. I feel like I mistyped something somewhere but I triple checked my code and I don't seem to find anything. The student_id is no longer displaying anything on the student tableView either since I added the second table insert statements, I almost forgot to mention.

My code
Student Class


Module Class


The show modules method



The error message

 
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
   protected StringProperty student_id = student.student_id;
   private StringProperty code;
   private StringProperty module_name;
   private SimpleIntegerProperty semester;
   private StringProperty grade;


Do all of these fields in Module have public getters? I believe the default behavior should be able to find those automatically. Also since you're using a StringProperty, you MIGHT need that to return a plain String instead of the property (I forget). Usually FX property getters are named something like getStudentIdProperty() if I'm recalling that convention correctly.

(Also student_id would normally be named studentId to follow more standard camelCase Java coding conventions, and same idea for module_name.)
 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, or name it studentIdProperty() (after refactoring student_id to studentId). See the Javadoc below which explains what it's doing. The getStudentId() is just a fallback so I'd just return the property object you've got.

https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/cell/PropertyValueFactory.html


In this example, the "firstName" string is used as a reference to an assumed firstNameProperty() method in the Person class type (which is the class type of the TableView items list). Additionally, this method must return a Property instance. If a method meeting these requirements is found, then the TableCell is populated with this ObservableValue. In addition, the TableView will automatically add an observer to the returned value, such that any changes fired will be observed by the TableView, resulting in the cell immediately updating.

If no method matching this pattern exists, there is fall-through support for attempting to call get<property>() or is<property>() (that is, getFirstName() or isFirstName() in the example above). If a method matching this pattern exists, the value returned from this method is wrapped in a ReadOnlyObjectWrapper and returned to the TableCell. However, in this situation, this means that the TableCell will not be able to observe the ObservableValue for changes (as is the case in the first approach above).


 
Do you want ants? Because that's how you get ants. And a tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic