Trouble with custom Property [message #1826123] |
Sun, 19 April 2020 20:23  |
Eclipse User |
|
|
|
Hello,
I am playing with the helloworld example.
I added new property to: helloworld.ui.html.app.dev -> src/main/resources -> config.properties
# custom property
scout.custom.property=1
And now I am getting compile error:
2020-04-20 00:15:01,684 ERROR [scout-platform-starter] org.eclipse.scout.rt.platform.internal.PlatformImplementor.validateConfiguration(PlatformImplementor.java:192) - Config property with key 'scout.custom.property' does not exist or has an invalid value. - MDC[]
2020-04-20 00:15:01,688 ERROR [scout-platform-starter] org.eclipse.scout.rt.platform.internal.PlatformImplementor.start(PlatformImplementor.java:144) - Error during platform startup - MDC[]
org.eclipse.scout.rt.platform.exception.PlatformException: Cannot start platform due to 1 invalid config properties: [scout.custom.property]
I did chase it down to ConfigPropertyValidator class, where in the method getAllConfigProperties() there is a line with: BEANS.all(IConfigProperty.class)
It looks like "allowed" properties are loaded as Beans... but where are they defined? How do I define my own properties?
So, I have a feeling the way to go would be to create/override my own CustomValidator (how do I invoke/use it?), and define my properties somewhere else... (where and how?) (there will be couple dozens of them)
My platform:
Fedora 30
openjdk version "11.0.6" 2020-01-14
eclipse-scout-2020-03-R-linux-gtk-x86_64
node v12.16.2
Kind Regards,
|
|
|
|
Re: Trouble with custom Property [message #1826144 is a reply to message #1826123] |
Mon, 20 April 2020 04:05  |
Eclipse User |
|
|
|
Thank you for the example!
I got it working.
import org.eclipse.scout.rt.platform.config.AbstractStringConfigProperty;
public final class CustomProperties {
public static final String CUSTOM_PROPERTY_1 = "scout.custom.property1";
public static final String CUSTOM_PROPERTY_1_DESC = "Custom property 1";
public static final String CUSTOM_PROPERTY_1_DEFAULT = "0";
public static final String CUSTOM_PROPERTY_2 = "scout.custom.property2";
public static final String CUSTOM_PROPERTY_2_DESC = "Custom property 2";
private CustomProperties() {}
public static class CustomProperty_1 extends AbstractStringConfigProperty {
@Override
public String getKey() {
return CUSTOM_PROPERTY_1;
}
@Override
public String description() {
return CUSTOM_PROPERTY_1_DESC;
}
@Override
public String getDefaultValue() {
return CUSTOM_PROPERTY_1_DEFAULT;
}
}
public static class CustomProperty_2 extends AbstractStringConfigProperty {
@Override
public String getKey() {
return CUSTOM_PROPERTY_2;
}
@Override
public String description() {
return CUSTOM_PROPERTY_2_DESC;
}
}
}
and the validator class:
import org.eclipse.scout.rt.platform.config.IConfigurationValidator;
import org.eclipse.scout.rt.platform.exception.InitializationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CustomPropertyValidator implements IConfigurationValidator {
private static final Logger LOG = LoggerFactory.getLogger(CustomPropertyValidator.class);
@Override
public boolean isValid(String key, String value) {
if ( key.equalsIgnoreCase(CustomProperties.CUSTOM_PROPERTY_1) ) {
if (value != null && value.length() == 1 && "01".indexOf(value) >= 0) {
LOG.info("Property: [{}] value: [{}] is valid", key, value);
return true;
} else {
LOG.error("Incorrect value for property: {}", CustomProperties.CUSTOM_PROPERTY_1);
throw new InitializationException("Incorrect value for property: " + CustomProperties.CUSTOM_PROPERTY_1);
}
}
if ( key.equalsIgnoreCase(CustomProperties.CUSTOM_PROPERTY_2) ) {
if (value != null) {
LOG.info("Property: [{}] value: [{}] is valid", key, value);
return true;
}
}
return false;
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.05171 seconds