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: MVC Portlet reading custom configuration = Deployment failed
Hello everybody,
I made my application configurable with the help of the documentation. The values can be configured system-wide via "Control Panel> Configuration> System Settings> Third Party> My Custom App". Everything is great here!
But now I try to call my configuration from a MVCPortlet and now I can no longer deploy the portlet. Only when I remove the line "private volatile CustomConfiguration _customConfiguration;" The deployment works again.
source:
Thank you and best regards,
Dennis
I made my application configurable with the help of the documentation. The values can be configured system-wide via "Control Panel> Configuration> System Settings> Third Party> My Custom App". Everything is great here!
But now I try to call my configuration from a MVCPortlet and now I can no longer deploy the portlet. Only when I remove the line "private volatile CustomConfiguration _customConfiguration;" The deployment works again.
source:
...
import de.dsc.test.configuration.CustomConfiguration;
import com.liferay.portal.configuration.metatype.bnd.util.ConfigurableUtil;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
...
import javax.portlet.Portlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Modified;
@Component(
configurationPid = "de.dsc.test.configuration.CustomConfiguration",
immediate = true,
property = {
"com.liferay.portlet.display-category=category.hidden",
"com.liferay.portlet.scopeable=true",
"javax.portlet.expiration-cache=0",
"javax.portlet.init-param.portlet-title-based-navigation=true",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.name=testadminportlet",
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=administrator",
"javax.portlet.supports.mime-type=text/html",
"com.liferay.portlet.add-default-resource=true"
},
service = Portlet.class
)
public class TestAdminPortlet extends MVCPortlet {
private volatile CustomConfiguration _customConfiguration;
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException {
// parse configuration to JSP model
renderRequest.setAttribute(CustomConfiguration .class.getName(), _customConfiguration);
super.doView(renderRequest, renderResponse);
}
@Activate
@Modified
protected void activate(Map<string, object> properties) {
_customConfiguration= ConfigurableUtil.createConfigurable(
CustomConfiguration .class, properties);
}
}</string,>Thank you and best regards,
Dennis
What do you mean with "Deployment fails". Do you see an error in the logfile?
Could you execute diag in gogo shell? May you have a dependency problem.
Could you execute diag in gogo shell? May you have a dependency problem.
Sorry the module is "Installed" but not "Started".
The gogo diag command says "Unresolved requirement: Import-Package de.dsc.test.configuration.CustomConfiguration"
My build.gradle but adds the project to where the class is:
The gogo diag command says "Unresolved requirement: Import-Package de.dsc.test.configuration.CustomConfiguration"
My build.gradle but adds the project to where the class is:
dependencies {
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel"
compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib"
compileOnly group: "com.liferay", name: "com.liferay.application.list.api"
compileOnly group: "javax.portlet", name: "portlet-api"
compileOnly group: "javax.servlet", name: "javax.servlet-api"
compileOnly group: "jstl", name: "jstl"
compileOnly group: "org.osgi", name: "osgi.cmpn"
compileOnly group: "com.liferay", name: "com.liferay.portal.configuration.metatype", version: "2.0.0"
compile project (":modules:test: test-api")
compile project (":modules:test: test-service")
compile project (":modules:test-panel-category")
}
Please check where the class "de.dsc.test.configuration.CustomConfiguration" is. Is it in a different module? e.g. in your test-service?
Could you check/post the definition of that class? Maybe there is something wrong there with the annotations.
Could you check/post the definition of that class? Maybe there is something wrong there with the annotations.
Yes, the configuration class is inside the test-service module.
The MVCPortlet is in another module.
Additionally I tried to import the package explicitly in the bnd.bnd - then I can start the MVCPortlet, but get classNotFound-exceptions as soon he is try to initialize the CustomConfiguration.
The MVCPortlet is in another module.
package de.dsc.test.configuration;
import aQute.bnd.annotation.metatype.Meta;
/**
*
* @author DSchilakowski
*
*/
@Meta.OCD(
id = "de.dsc.test.configuration.CustomConfiguration",
localization = "content/Language", name = "configuration-name"
)
public interface CustomConfiguration{
@Meta.AD(
deflt = "http://localhost:3000/api",
required = true,
name = "configuration-url",
description = "configuration-url-desc"
)
public String url();
@Meta.AD(
deflt = "localhost",
required = true,
name = "configuration-targetsystem"
)
public String targetSystem();
@Meta.AD(
deflt = "localhost",
required = true,
name = "configuration-sourcesystem"
)
public String sourceSystem();
}Additionally I tried to import the package explicitly in the bnd.bnd - then I can start the MVCPortlet, but get classNotFound-exceptions as soon he is try to initialize the CustomConfiguration.
Import-Package:\
!de.dsc.test.*,\
\
*
In that case, you have a bit of a problem.
I think, the service is actually a bad place for that class. When you create a Liferay service, it has two parts. The API and the Implementation. You add stuff to the implementation, but the "magic" doesn't know that it should export it.
This is solvable in multiple ways, but I recommend that you simply add the configuration to the portlet project.
To remove the class from the Import-Packages won't help you because the class is actually needed. It is a helper for cases where the "magic" determines that you need class "x" and you tell it: "Believe me, I don't need it, you are wrong. I know what I am doing!".
I think, the service is actually a bad place for that class. When you create a Liferay service, it has two parts. The API and the Implementation. You add stuff to the implementation, but the "magic" doesn't know that it should export it.
This is solvable in multiple ways, but I recommend that you simply add the configuration to the portlet project.
To remove the class from the Import-Packages won't help you because the class is actually needed. It is a helper for cases where the "magic" determines that you need class "x" and you tell it: "Believe me, I don't need it, you are wrong. I know what I am doing!".
Many Thanks. I tried a bit more and found a solution, if it was the best I do not know :-).
I have packed all the additional logic that I have implemented in the service into a separate module as you have recommended.
The new module also exports only the required packages via the bnd.bnd file and the mvcportlet gets the new module as dependency - it works (!!)
I have packed all the additional logic that I have implemented in the service into a separate module as you have recommended.
The new module also exports only the required packages via the bnd.bnd file and the mvcportlet gets the new module as dependency - it works (!!)