RE: Using arrays in configuration API

thumbnail
Steve Weiss, modified 3 Years ago. Regular Member Posts: 112 Join Date: 9/20/11 Recent Posts

We are using the configuration API for our applications after moving to 7.x. We have an application that has a list of items, administrator should be able to configure the application to use one or more of the items in the list. In our configuration interface, if we do this it works:

 

    @Meta.AD(
            required = false,
            name = "Workflow States",
            optionValues = {
                    "Draft",
                    "Group",
                    "Summary",
                    "Reclaima",
                    "Board Review",
                    "Closed-Duplicated",
                    "Closed-Withdrawn",
                    "Closed-Completed",
                    "Closed-Rejected",
                    "Withdrawn",
                    "Rejected"
            })
    public String[] workflowStates();
 

Doing it this way, in the control panel the user can select from an option menu and add as many items from the list as he/she wishes. The problem is that if someone doesn't do the control panel configuration first, then configuration.workflowStates() returns an empty array. We would like to have a default list. In the tutorial (https://help.liferay.com/hc/en-us/articles/360018161391-Making-Your-Applications-Configurable-), this appears to be the way to do this:

 

    @Meta.AD(
            required = false,
            name = "Workflow States",
            deflt = "Draft|Group|Summary|Reclaima|Board Review|Closed-Duplicated|Closed-Withdrawn|Closed-Completed|Closed-Rejected|Withdrawn|Rejected"
)

public String[] workflowStates();

 

However this doesn't work. We still get an empty string and now you can't even configure the list in the control panel.

 

Is there some way to get this to work so that we can set a default list of options, without having to go to the control panel?

thumbnail
Russell Bohl, modified 3 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts

Hmm, the String array with defaults (like you're trying) works for me in 7.4--I can set the defaults in the configuration interface, deploy the module, and retrieve the configuration using ConfigurationPorivderUtil from a Groovy script. And there are plenty of examples in Liferay's 7.2 source code where the default is set as you are doing it. I guess my first thought is to make sure you're on the latest 7.2 release. And, as a shot in the dark, what if you remove the hyphens just as a test, to make sure there's not something going on with odd characters?

thumbnail
Steve Weiss, modified 3 Years ago. Regular Member Posts: 112 Join Date: 9/20/11 Recent Posts

Thanks Russell. Still doesn't work though. The other values from the configuration come through but the list from that field is empty. The configuration screen in the control panel for that field is shown in the attached screenshot. So it recognizes the field as an array and allows me to add additional items, but it's not getting the default list.


 

thumbnail
Steve Weiss, modified 3 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts

Steve, I tested on 7.2 GA2 and I was able to use a String array with defaults, and I see the defaults properly represented in System Settings:

	@Meta.AD(deflt = "serif|cursive|other-types", required = false)
	public String[] fontFamilies();


 

thumbnail
Steve Weiss, modified 3 Years ago. Regular Member Posts: 112 Join Date: 9/20/11 Recent Posts

Thanks again Russell. I copied your code in and made some changes and now it works. I have no idea what the problem was.

thumbnail
Steve Weiss, modified 3 Years ago. Regular Member Posts: 112 Join Date: 9/20/11 Recent Posts

I think I've identified what the problem was. Originally, the method in the configuration interface was "workflowStates()". When I changed it to "workFlowStates()" it worked. Change it back and it doesn't work. So I'm guessing that there must be some kind of naming conflict with the Liferay workflow.

thumbnail
Russell Bohl, modified 3 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts

That's interesting. Thanks for following up.