Default Settings for a custom ExtensionPoint

I'm building a custom historian module for 8.3. I want to have pre-filled-in values for some of the fields when creating it on the gateway config page.
I've implemented defaultSettings() but the settings do not show up on the config page for whatever reason (I want the poll rate to default to 60000).

This is what I have:

In REDACTEDExtentionPoint.java:

	@Override
    public Optional<REDACTEDSettings> defaultSettings() {
        REDACTEDSettings.Connectivity connectivity = new REDACTEDSettings.Connectivity(null);
        REDACTEDSettings.Advanced advanced = new REDACTEDSettings.Advanced(60000);
        REDACTEDSettings settings = new REDACTEDSettings(connectivity, advanced);
        return Optional.of(settings);
    }

REDACTEDSettings.java:

public record REDACTEDSettings(Connectivity connectivity, Advanced advanced) implements HistorianSettings {
    public record Connectivity(
            @FormCategory("Connectivity")
            @FormField(FormFieldType.REFERENCE)
            @Label("Database Connection")
            @Required
            @Description("The database connection to use.")
            @FormReferenceType("ignition/database-connection")
            String databaseConnection
    ) {}
    public record Advanced(
            @FormCategory("Advanced")
            @FormField(FormFieldType.NUMBER)
            @Label("Poll Rate")
            @Required
            @Description("The rate (in milliseconds) at which the historian should query the datasource to check for updates")
            int pollRate
    ) {}

I've also tried the @DefaultValue() annotation which didn't work either. Looking at the docs, it seems to be meant for optional parameters and applied after the user fails to specify a value, which is not what I'm looking for.

I've tried @ExampleValue("60000") as well, but that doesn't seem to fill it out either...

When stepping through with the debugger, it looks like the default settings get created correctly and are stored with the list of extension points, but the Create Historian popup doesn't use them...

Am I misunderstanding the purpose of the defaultSettings() method? If so, what should I use instead?

Your config page is just an ExtensionPointResourceForm?

Returning an instance with the desired values from defaultSettings() + the @DefaultValue("60000") annotation should be enough...

1 Like

Thanks for replying so quickly!

I added the default annotation back in:

public record Advanced(
            @FormCategory("Advanced")
            @FormField(FormFieldType.NUMBER)
            @Label("Poll Rate")
            @Required
            @DefaultValue("60000")
            @Description("The rate (in milliseconds) at which the historian should query the datasource to check for updates. Set the the value to anything less than or equal to 0 to only poll the values on the historian's startup.")
            int pollRate
    ) {}

And my config page should just be an ExtensionPointResourceForm:

    @Override
    public Optional<WebUiComponent> getWebUiComponent(ComponentType type) {
        return Optional.of(new ExtensionPointResourceForm(
                RESOURCE_TYPE,
                "Historian Settings",
                "REDACTED",
                SchemaUtil.fromType(HistorianProvider.class),
                SchemaUtil.fromType(REDACTEDSettings.class)
        ));
    }

Still no default value though:

I fell like I'm missing something simple and I just can't see it...

I'm not seeing anything that stands out yet. We're using the same pattern all over with extension points to provide default values. Are you sure you've properly cleaned, rebuilt, reinstalled your module? Can you change something else (name, description, whatever) to make sure?

3 Likes

I changed stuff on it to make sure:

Could it be because I don't have defaultProfile() implemented?

I don't think so, most/all of ours don't implement that.

Maybe something to do with using null instead of empty string here?