InitialValue vs DefaultValue and persistence [message #1635852] |
Thu, 26 February 2015 00:49  |
Jason Pell Messages: 55 Registered: February 2011 |
Member |
|
|
Hi,
I have a field which is backed by an enumeration. It must have a value in the XML that gets written. I would like to ensure that a default value is specified in the UI and that even if no one changes that value it gets written out.
I tried using @InitialValue but it seems to have no impact on what is selected in the UI and also does not appear in the xml anyway.
This DuplicateConfig is referenced from the root element object:
@Label( standard = "Duplicate Config" )
@Type( base = DuplicateConfig.class )
@XmlBinding( path = "DuplicateConfig" )
ImpliedElementProperty PROP_DUPLICATE_CONFIG = new ImpliedElementProperty( TYPE, "DuplicateConfig" );
DuplicateConfig getDuplicateConfig();
Should I just use a @DefaultValue and a custom XML binder? Or is there something fundamental I am not understanding.
public interface DuplicateConfig extends Element {
ElementType TYPE = new ElementType(DuplicateConfig.class);
@Type( base = DuplicateMatching.class )
@XmlBinding(path = "duplicateMatching")
@Label(standard = "Duplicate Matching")
@InitialValue( text = "IgnoreNumericSuffix" )
ValueProperty PROP_DUPLICATE_MATCHING = new ValueProperty(TYPE, "DuplicateMatching");
Value<DuplicateMatching> getDuplicateMatching();
void setDuplicateMatching(String value);
void setDuplicateMatching(DuplicateMatching value);
@Label( standard = "Ignore Fqns" )
@XmlListBinding( path = "" )
@Type( base = IgnoreFqn.class )
ListProperty PROP_IGNORE_FQNS = new ListProperty( TYPE, "IgnoreFqns" );
ElementList<IgnoreFqn> getIgnoreFqns();
}
Edit - I also tried to add a @CustomXmlValueBinding but the write method is never called. I am not sure how to override the @CustomXmlElementBinding at the parent level to ensure a value gets written.
[Updated on: Thu, 26 February 2015 03:25] Report message to a moderator
|
|
|
Re: InitialValue vs DefaultValue and persistence [message #1635974 is a reply to message #1635852] |
Thu, 26 February 2015 02:14   |
Jason Pell Messages: 55 Registered: February 2011 |
Member |
|
|
So I added a hack to my Editor class to write out the default value, but its so nasty and I want to know if there is a way to add this code only to certain Elements.
@Override
protected Element createModel() {
GeneratorConfig config = GeneratorConfig.TYPE.instantiate(new RootXmlResource(
new XmlEditorResourceStore(this, this.sourcePage)));
setDefaultValues(config);
return config;
}
private void setDefaultValues(Element element) {
for( Property property : element.properties( "*" ) ) {
if( property instanceof Element ) {
setDefaultValues((Element) property);
} else if( property instanceof Value ) {
Value<?> value = (Value<?>) property;
if (value.content() == null && value.getDefaultContent() != null) {
value.write(value.getDefaultContent());
}
}
}
}
[Updated on: Thu, 26 February 2015 10:44] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03562 seconds