Hi Greg,
The annotation you are looking for is @CountConstraint( min = 1 ). That’s sufficient to achieve the effect you are after in the model. In UI, the situation is a bit more difficult. If you surface the list via a property editor, you will see the validation. If you surface the list via the content outline as you are doing, you will run into the following issue…
Bug 329076 - More extensive validation feedback on outline nodes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=329076
There is more detail on the difficulty in surfacing this validation in the content outline in the bug. If supporting this is important for your scenarios, jump on the bug and we can continue this conversation there.
- Konstantin
From: sapphire-dev-bounces@xxxxxxxxxxx [mailto:sapphire-dev-bounces@xxxxxxxxxxx] On Behalf Of Greg Amerson
Sent: Tuesday, April 12, 2011 3:40 PM
To: sapphire-dev@xxxxxxxxxxx
Subject: [sapphire-dev] Validation for empty list property
Hello Konstantin (or anyone other Sapphire experts),
In my model I have a List Property on the root model element. In the DTD this is specified as entity+ so it is expecting one or more of these elements to be valid. However, in the model or the sdef file I don't know how to make it show an Error marker on the Content Outline Node so the user knows something has to be fixed, some validation message like "At least on {0} must be specified" where {0} can be the ModelElement name.
Any thoughts? Oh, i have tried both @NonNullValue and @MustExist annotations on this property just to try it out if that would help, but neither produced an error marker on the Content Outilne Node.
For reference, here is the ListProperty definition in question below.
@Type(base = IEntity.class)
@Label(standard = "Entity")
@XmlListBinding(mappings = @XmlListBinding.Mapping(element = "entity", type = IEntity.class))
ListProperty PROP_ENTITIES = new ListProperty(TYPE, "Entities");
ModelElementList<IEntity> getEntities();
--
Greg Amerson
Liferay, Inc.