Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Trouble with custom Property
Trouble with custom Property [message #1826123] Mon, 20 April 2020 00:23 Go to next message
Darth Bolek is currently offline Darth BolekFriend
Messages: 25
Registered: August 2019
Junior Member
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 #1826126 is a reply to message #1826123] Mon, 20 April 2020 04:40 Go to previous messageGo to next message
Matthias OtterbachFriend
Messages: 58
Registered: August 2015
Location: Munich
Member
Configuration properties for Scout applications are typically classes of implementing org.eclipse.scout.rt.platform.config.IConfigProperty<DATA_TYPE>. As this interface is marked @ApplicationScoped these properties are also automatically registered with the bean manager (and pass the validation).

For example a simple config propery org.eclipse.scout.rt.server.ServerConfigProperties.RemoteFilesRootDirProperty looks like https://github.com/eclipse/scout.rt/blob/10.0.12/org.eclipse.scout.rt.server/src/main/java/org/eclipse/scout/rt/server/ServerConfigProperties.java#L62 - as it subclasses AbstractStringConfigProperty it also implements the interface mentioned above.

The technical documentation also provides some examples, see https://eclipsescout.github.io/10.0/technical-guide.html#sec-config.management

For more advanced cases, of course it is also possible to customize the validation by writing a customized validator implementing IConfigurationValidator - but usually this should not be necessary.
Re: Trouble with custom Property [message #1826144 is a reply to message #1826123] Mon, 20 April 2020 08:05 Go to previous message
Darth Bolek is currently offline Darth BolekFriend
Messages: 25
Registered: August 2019
Junior Member
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;
	}

}

Previous Topic:new title Menu in GroupBox
Next Topic:how to capture content in ImageField using uploadEnabled
Goto Forum:
  


Current Time: Sat Nov 09 07:30:14 GMT 2024

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

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

Back to the top