Using @AdminPresentationDataDrivenEnumeration
Posted: Wed May 22, 2013 3:55 pm
I have an entity "Item" which contains a type object which is also an entity in the database. In the admin, I want to allow the user to edit the type using a dropdown which should contain all of the possible "ItemType" values in the database. So my class is as follows:
@AdminPresentationClass(friendlyName = "Item", populateToOneFields=PopulateToOneFieldsEnum.FALSE)
public class Item {
//bi-directional many-to-one association to ItemType
@ManyToOne
@JoinColumn(name="item_type_id")
@AdminPresentationDataDrivenEnumeration(optionListEntity = ItemType.class, optionValueFieldName = "id", optionDisplayFieldName = "name")
private ItemType itemType;
...
I am aware that the datadriven enum is supposed to operate on a string type and not an object, however, I am not aware of any other way to do this. My item type is automatically populated for me by JPA. How can I modify this scenario to operate on a string instead of the "ItemType" object? From what I have read, the datadrivenenumeration is the only way to list other entities in the drop-down. What I have above actually renders the drop-down, however, the drop down doesn't pre-select the value corresponding to the saved type, and upon trying to save, I get a failure as blc tries to store the selected string value to "ItemType" which obviously won't work. I would appreciate any suggestions to help be get this issue resolved. Thank you.
@AdminPresentationClass(friendlyName = "Item", populateToOneFields=PopulateToOneFieldsEnum.FALSE)
public class Item {
//bi-directional many-to-one association to ItemType
@ManyToOne
@JoinColumn(name="item_type_id")
@AdminPresentationDataDrivenEnumeration(optionListEntity = ItemType.class, optionValueFieldName = "id", optionDisplayFieldName = "name")
private ItemType itemType;
...
I am aware that the datadriven enum is supposed to operate on a string type and not an object, however, I am not aware of any other way to do this. My item type is automatically populated for me by JPA. How can I modify this scenario to operate on a string instead of the "ItemType" object? From what I have read, the datadrivenenumeration is the only way to list other entities in the drop-down. What I have above actually renders the drop-down, however, the drop down doesn't pre-select the value corresponding to the saved type, and upon trying to save, I get a failure as blc tries to store the selected string value to "ItemType" which obviously won't work. I would appreciate any suggestions to help be get this issue resolved. Thank you.