java - JavaFX extending PropertyValueFactory -
i have tableview of objects contain ids mapped other objects of other types. need tablecolumn which, instead of showing id, shows object mapped id. thought maybe creating own propertyvaluefactory, so:
public class somepropertyvaluefactory extends propertyvaluefactory<someobject, string> { public somepropertyvaluefactory(string property) { super(property); } @override public observablevalue<string> call(celldatafeatures<someobject, string> parameter) { someotherobject obj = function(parameter.getvalue().getid()); return obj.tostring(); } } is viable solution? function properly? i've tried loadexception thrown:
caused by: java.lang.instantiationexception: ui.view.somepropertyvaluefactory @ java.lang.class.newinstance(unknown source) @ sun.reflect.misc.reflectutil.newinstance(unknown source) ... 21 more caused by: java.lang.nosuchmethodexception: ui.view.somepropertyvaluefactory.<init>() @ java.lang.class.getconstructor0(unknown source) ... 23 more
if intending class used fxml, must either has no-argument constructor, or (in javafx 8) must have constructor parameters annotated @namedarg. do
public class somepropertyfactory ... { public somepropertyfactory(@namedarg("property") string property) { // ... } // ... } additionally, code posted won't compile since return value of call method string, should observablevalue<string>.
however, don't see point in making subclass of propertyvaluefactory @ all. why not implement callback directly? use class in setcellvaluefactory(...) , parameter type there callback. , don't seem inheriting @ superclass.
Comments
Post a Comment