Closed MFlisar closed 8 years ago
We don't have something that will do this automatically, but it's actually pretty easy to accomplish with @ModelMethod
alone.
Every model has the ability to attach what we call "transitory" metadata. This is basically a key/value store where the keys are strings and the values are any objects. The relevant methods are things like getTransitory()
, putTransitory()
, hasTransitory()
, etc., and exist on all model classes. Transitory metadata is ignored when persisting to the database.
I'd suggest implementing your getters and setters as model methods to store the value as a transitory value. You actually wouldn't even need the FolderGroup field if you did it this way, as you'd be accessing everything via the getters and setters you defined. It would look something like this:
@ModelMethod
public static FolderGroup getFolderGroup(GroupedFolder item) {
if (!item.hasTransitory(FOLDER_GROUP_TRANSITORY_KEY)) {
return null; // Or populate it somehow
}
return (FolderGroup) item.getTransitory(FOLDER_GROUP_TRANSITORY_KEY);
}
@ModelMethod
public static void setFolderGroup(GroupedFolder item, FolderGroup group) {
item.putTransitory(FOLDER_GROUP_TRANSITORY_KEY, group);
}
Thanks. That works.
I want to define a variable in my table with getter and setter (via a
ModelMethod
). But I want the field to be accessible only and not part of the table itself.Something like following (I added two comments to describe what I want):