Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Using arrays in configuration API
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?
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?
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.
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();
Thanks again Russell. I copied your code in and made some changes and now it works. I have no idea what the problem was.
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.
That's interesting. Thanks for following up.
Powered by Liferay™