Forums de discussion

Liferay 7: configuration scope

thumbnail
Benjamin Bini, modifié il y a 7 années.

Liferay 7: configuration scope

Junior Member Publications: 31 Date d'inscription: 24/05/13 Publications récentes
Hi,

Here is my use case : I have a portlet with a configuration class, a configuration action class and a configuration view.
The configuration for the portlet works well, but I want to have a system-wide default configuration (that can be overriden in my portlet configuration view).
In the Control Panel > Settings > System Settings, I can set this default configuration. But how do I get it in my portlet then ?
When I look in my db, when I instantiate my portlet on a page, a line is created in the portletpreferences table (with <portlet-preferences /> as preferences value), and when I save default settings in the control panel, a line is updated in the "configuration_" table with my default values in the "dictionary" field.

But when I do :
MyPortletConfiguration configuration = themeDisplay
				.getPortletDisplay().getPortletInstanceConfiguration(
					MyPortletConfiguration.class);

I do not get the default values set in the control panel.

What do I have to do to get these default values ?

Thanks.
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Liferay 7: configuration scope

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
Hmm, have you checked the values? There may be some sort of "override" mechanism in place that is returning the first available setting...

Just a thought!







Come meet me at the LSNA!
thumbnail
Benjamin Bini, modifié il y a 7 années.

RE: Liferay 7: configuration scope

Junior Member Publications: 31 Date d'inscription: 24/05/13 Publications récentes
The values I get are empty (I did not set any in my portlet configuration view). But I am not sure that "themeDisplay.getPortletDisplay().getPortletInstanceConfiguration()" is designed to look for possible default settings. It seems it just gets the instance configuration and only the instance configuration.
And I don't really see how to get the values from the system settings configuration.
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Liferay 7: configuration scope

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
right, but the instance you get is an interface, so the implementation behind the scenes may be doing anything at all, including supporting a cascading override mechanism.

perhaps this is a bug, though, but I wouldn't know how to classify it. Was the intention that when the instance was created the default values would be cloned into the new instance? Was the intention that there should be some kind of override mechanism? Not sure.






Come meet me at the LSNA!
thumbnail
Benjamin Bini, modifié il y a 7 années.

RE: Liferay 7: configuration scope

Junior Member Publications: 31 Date d'inscription: 24/05/13 Publications récentes
Well, I guess I have to use properties instead, until this gets clarified.
thumbnail
Benjamin Bini, modifié il y a 7 années.

RE: Liferay 7: configuration scope

Junior Member Publications: 31 Date d'inscription: 24/05/13 Publications récentes
I found the solution, I have to create a ConfigurationBeanDeclaration as explained in the doc and use a ConfigurationProvider in my controller :

    PortletInstance portletInstance = PortletInstance.fromPortletInstanceKey(instanceKey); 
    MyPortletConfiguration configuration = _configurationProvider.getPortletInstanceConfiguration(MyPortletConfiguration.class, themeDisplay.getLayout(), portletInstance);

...
...

ConfigurationProvider _configurationProvider;

@Reference
protected void setConfigurationProvider(ConfigurationProvider configurationProvider) {
    _configurationProvider = configurationProvider;
}