Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » Element with Default Value(Automatic Creation of Elements with Default Values)
Element with Default Value [message #711806] Sat, 06 August 2011 17:13 Go to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member
I added the Default value annotation for a Property and i see the radio buttons appearing for it and default value being selected, but in my XML model i dont see the element created though i gave the @Required and @MustExist annotation. Unless and until i click on the element it does no create the element

Is there any way for adding the element tag automatically and populating it with DEFAULT value.

~Kamesh
Re: Element with Default Value [message #713606 is a reply to message #711806] Mon, 08 August 2011 16:36 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
The @DefaultValue, @Required and @MustExist annotations do not operate at the level of XML binding.

@DefaultValue - Specifies the property value if a null was read from the underlying store (XML file, etc.).

@Required - Specifies that it should be a validation error if the property value is null. Does not make sense in conjunction with @DefaultValue.

@MustExist - Used with properties that name an external resource such as a file or a Java type to signify that the referenced entity has to exist or it's a validation error.

Getting back to your scenario, there are no declarative facilities to make sure that new elements are created with pre-populated content, but you can achieve this by implementing a custom binding for your list property. See @CustomXmlListBinding, StandardXmlListBindingImpl (the addUnderlyingObject method in particular).

- Konstantin
Re: Element with Default Value [message #713781 is a reply to message #713606] Tue, 09 August 2011 03:36 Go to previous messageGo to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member
Thanks for the info Konstantin, I have implemented a class DefaultXmlBinding following StandardXmlListBindingImpl for this purpose. I feel that we can add an Annotation @Mandatory and make this implementation there. Right now this supported only for Non-list types, may be we could extend it for other types too.
Attaching the code here so that it might be useful for some one.

~Kamesh
Re: Element with Default Value [message #714028 is a reply to message #713781] Tue, 09 August 2011 16:21 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
I am certainly open to devising a way to incorporate this scenario into the framework. Go ahead an open an enhancement request and we can discuss this further there.

BTW, in your custom binding implementation, you are modifying the DOM tree during a read, which you shouldn't be doing. Applying the initial values should happen in the createUnderlyingObject method.

- Konstantin
Re: Element with Default Value [message #714038 is a reply to message #714028] Tue, 09 August 2011 16:37 Go to previous message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member
The bug is opened here https://bugs.eclipse.org/bugs/show_bug.cgi?id=354276
Previous Topic:Good idea, but ...
Next Topic:Content Assist
Goto Forum:
  


Current Time: Tue Apr 23 11:55:41 GMT 2024

Powered by FUDForum. Page generated in 0.02948 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top