Follow these steps to create your own Portlet Provider:
-
Create a
PortletProvider
class in your module. Use the recommended class naming convention:[Entity] + [Action] + PortletProvider
For example, here’s a Portlet Provider class for viewing a
LanguageEntry
:LanguageEntryViewPortletProvider
-
Extend
BasePortletProvider
if you want to use itsgetPortletURL
method implementations. -
Implement one or more
PortletProvider
subinterfaces that match your action(s): -
Make the class an OSGi Component by adding an annotation like this one:
@Component( immediate = true, property = { "model.class.name=CLASS_NAME", "service.ranking:Integer=10" }, service = {INTERFACE_1.class, ...} )
The
immediate = true
element specifies that the component should be activated immediately upon installation.Assign to the
model.class.name
property the fully qualified class name of the entity the portlet operates on. Here’s an examplemodel.class.name
property for theWikiPage
entity:"model.class.name=com.liferay.wiki.model.WikiPage"
Assign the
service
element to thePortletProvider
subinterface(s) you’re implementing (e.g.,ViewPortletProvider.class
,BrowsePortletProvider.class
, etc.). This example setsservice
toEditPortletProvider.class
:service = EditPortletProvider.class
-
If you’re overriding an existing Portlet Provider, rank your Portlet Provider higher by specifying a
service.ranking:Integer
property with a higher integer value:property = { ..., "service.ranking:Integer=10" }
-
Implement the provider methods you want. Be sure to implement the
PortletProvider
methodgetPortletName
. If you didn’t extendBasePortletProvider
, implementPortletProvider
’sgetPortletURL
methods too.
Now your Portlet Provider is available to return the ID and URL of the portlet that provides the desired behaviors. For more information on this, see Retrieving Portlets.