Hello Folks,
Here I have tried to put all the possible steps which we would required to introduce custom portlet configuration.
1) Create new Liferay module using mvcportlet template
2) Define below highlighted property in your controller class:
@Component(
immediate = true,
property = {
"javax.portlet.name=SamplePortlet",
"javax.portlet.supports.mime-type=text/html",
"javax.portlet.display-name=SamplePortlet",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/html/view.jsp",
"javax.portlet.init-param.config-template=/html/config.jsp",
"javax.portlet.portlet-info.title=SamplePortlet",
"javax.portlet.portlet-info.short-title=SamplePortlet",
"javax.portlet.portlet-info.keywords=SamplePortlet",
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=administrator,guest,power-user,user",
"com.liferay.portlet.display-category=SamplePortlet",
"com.liferay.portlet.instanceable=false",
"com.liferay.portlet.header-portlet-css=/css/main.css",
"com.liferay.portlet.footer-portlet-javascript=/js/main.js"
},
service = Portlet.class
)
public class SamplePortletextends MVCPortlet {
}
3) Introduce custom interface for models with unique id as highlighted
@Meta.OCD(
id = "com.sample.action.SamplePortletConfig " )
public interface SamplePortletConfig {
}
Note :
4) Create custom config action class
@Component(
configurationPid = "com.sample.action.SamplePortletConfig",
configurationPolicy = ConfigurationPolicy.OPTIONAL, immediate = true,
property = {
"javax.portlet.name=SamplePortlet"
},
service = ConfigurationAction.class
)
public class SamplePortletConfigAction extends DefaultConfigurationAction {
// processaction,render and include methods
}
5) Add below property in module bnd file
Now check your configuration icon and see if custom configuration is available or not for that specific portlet.
Interesting right !!!!!!! Enjoy Learning Osgi :)
Here I have tried to put all the possible steps which we would required to introduce custom portlet configuration.
1) Create new Liferay module using mvcportlet template
2) Define below highlighted property in your controller class:
@Component(
immediate = true,
property = {
"javax.portlet.name=SamplePortlet",
"javax.portlet.supports.mime-type=text/html",
"javax.portlet.display-name=SamplePortlet",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/html/view.jsp",
"javax.portlet.init-param.config-template=/html/config.jsp",
"javax.portlet.portlet-info.title=SamplePortlet",
"javax.portlet.portlet-info.short-title=SamplePortlet",
"javax.portlet.portlet-info.keywords=SamplePortlet",
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=administrator,guest,power-user,user",
"com.liferay.portlet.display-category=SamplePortlet",
"com.liferay.portlet.instanceable=false",
"com.liferay.portlet.header-portlet-css=/css/main.css",
"com.liferay.portlet.footer-portlet-javascript=/js/main.js"
},
service = Portlet.class
)
public class SamplePortletextends MVCPortlet {
}
3) Introduce custom interface for models with unique id as highlighted
@Meta.OCD(
id = "com.sample.action.SamplePortletConfig " )
public interface SamplePortletConfig {
@Meta.AD(
deflt = "blue",
required = false
)
public String favoriteColor();
@Meta.AD(
deflt = "red|green|blue",
required = false
)
public String[] validLanguages();
@Meta.AD(required = false)
public int itemsPerPage();
}
Note :
- Meta.OCD: Registers this class as a configuration with a specific id. You can choose any string you want, but make sure it’s unique. A common pattern is to use the fully qualified class name.
- Meta.AD: Specifies the
default value of a configuration field as well as whether it’s required
or not. Note that if you set a field as required and don’t specify a
default value, the system administrator must specify a value in order
for your application to work properly. Use the
deflt
property to specify a default value.
4) Create custom config action class
@Component(
configurationPid = "com.sample.action.SamplePortletConfig",
configurationPolicy = ConfigurationPolicy.OPTIONAL, immediate = true,
property = {
"javax.portlet.name=SamplePortlet"
},
service = ConfigurationAction.class
)
public class SamplePortletConfigAction extends DefaultConfigurationAction {
// processaction,render and include methods
}
5) Add below property in module bnd file
-metatype: *
6) Introduce config.jsp with all possible fields which you want to configureNow check your configuration icon and see if custom configuration is available or not for that specific portlet.
Interesting right !!!!!!! Enjoy Learning Osgi :)