Page 1 of 1

Using @AdminPresentationDataDrivenEnumeration

Posted: Wed May 22, 2013 3:55 pm
by tlerma909
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.

Re: Using @AdminPresentationDataDrivenEnumeration

Posted: Wed May 29, 2013 3:58 pm
by tlerma909
I'll go ahead and provide the answer to my own question. I figured out that the answer was to use a different annotation entirely. Basically the annotation I was looking for was "@AdminPresentationToOneLookup"

By adding the annotation below to my ItemType field, I am able to get the list of entities all rendered, selected and saving correctly.

@ManyToOne
@JoinColumn(name="item_type_id")
@AdminPresentation(friendlyName = "Item Type")
@AdminPresentationToOneLookup(lookupDisplayProperty = "name", lookupType = LookupType.DROPDOWN)
private ItemType itemType;

Hopefully this will save someone some time when working with these annotations.