Example 4: Configuration

If you can't play the video, make sure that you are logged in at Wex Solutions.

The purpose of this example is to demonstrate how to add a configuration UI to a Windchill Extension. If you want to learn more about WEX configuration, be sure to check out the Configuration section of the Developer Guide.

You can find the code for this example in our GitHub repository.

Implementation

A WEX's configuration is implemented with a single Java file. In this example, you'll find it under com/wincomplm/wex/example/config/impl/config/ExampleConfiguration.java. This file implements the following fields:

    @ConfigOption(category = "Basic", description = "Simple string", required = false)
    String exampleString = "bad";

    @ConfigOption(category = "Basic", description = "Boolean",
            longdesc = "A true/false boolean", required = false)
    boolean exampleBoolean = false;

    @ConfigOption(category = "Collections", description = "String list",
            longdesc = "A string list", required = false)
    List<String> exampleList = new ArrayList();

    @ConfigOption(category = "Collections", description = "String map",
            longdesc = "A string map", required = false)
    Map<String,String> exampleMap = new HashMap();

    @ConfigOption(category = "Collections", description = "String list with handler",
            longdesc = "String list with handler", required = false, handler = LifeCycleStateHandler.class)
    List<String> exampleStateList = new ArrayList();

The @ConfigOption tab is used to define each of the fields that will appear in the configuration's UI. It takes in several paremeters:

It is good practice to implement validation checks for the fields that need it. An example of a validation would look like this.

@Override
public void validate() throws WexValidationException {
    // We ccheck the consistency of the data here
    if (exampleString.equals("bad")) {
        throw new WexValidationException("exampleString","Please change to not bad!");
    }
}

The developer might also choose to set up a test JSP to verify the data held by the config:

@WexComponent(uid = "methods", description = "Wex Diagnostic Methods")
public class ExampleMethods {

    public static ExampleConfiguration config = (ExampleConfiguration) WexConfigRegistryHelper.instance.getConfig();

    @WexMethod(name = "test", description = "Display configuration")
    public String test() throws Exception {
        // This is test code but generally rendering HTML server side is not a good practice ;-)
        final String EOL = "<br>";
        String result = "";
        result += "Example String: " + config.getExampleString() + EOL;
        result += "Example Boolean: " + config.isExampleBoolean()+ EOL;
        result += "Example List: " + config.getExampleList()+ EOL;
        result += "Example Map: " + config.getExampleMap()+ EOL;
        result += "Example State List: " + config.getExampleStateList()+ EOL;
        return result;
    }//string

}

Execution

The configuration UI can be accessed through the Extension Manager:

1618003177748

Once the icon is clicked, the following UI will appear which offers the possibility of updating the data:

image-20240205101221504

Note that if you enter "bad" in the Simple string, a warning will appear. This is triggered by the validation previously implemented in the configuration's Java file.

1618004412099

You can use the test page from the WEX's User Guide in order to test if the changes you made to the fields actually made it to the system.

1618052916274

Clicking on the link will show the current configuration values:

image-20240205101329729

Passwords

The configuration can be used to store passwords using the hidden flag

@ConfigOption(category = "Security", description = "Password", required = false, hidden=true)
String examplePassword = "";

For security the password is only show whilst being edited, from wex-config 1.36

image-20240205101618072