There are 2 ways to change the category of a gadget:
Through UI as stated in Adding a portlet/gadget to the Application list. However, to follow in this way, the added gadget must not belong to any category and it can only be added to one of existing categories.
Through the configuration below.
The following procedure instructs you how to add Hello World gadget to the My Gadgets category. The source code is available here for downloading.
Add the following content to the custom-extension.war/conf/configuration.xml
file.
<external-component-plugins>
<target-component>org.exoplatform.application.registry.ApplicationRegistryService</target-component>
<component-plugin>
<name>new.portal.portlets.registry</name>
<set-method>initListener</set-method>
<type>org.exoplatform.application.registry.ApplicationCategoriesPlugins</type>
<description>this listener init the portlets are registered in PortletRegister</description>
<init-params>
<object-param>
<name>MyGadgets</name>
<description>description</description>
<object type="org.exoplatform.application.registry.ApplicationCategory">
<field name="name"><string>MyGadgets</string></field>
<field name="displayName"><string>My Gadgets</string></field>
<field name="description"><string>List of personal gadgets for development.</string></field>
<field name="accessPermissions">
<collection type="java.util.ArrayList" item-type="java.lang.String">
<value><string>*:/developers</string></value>
</collection>
</field>
<field name="applications">
<collection type="java.util.ArrayList">
<value>
<object type="org.exoplatform.application.registry.Application">
<field name="applicationName"><string>HelloGadget</string></field>
<field name="categoryName"><string>MyGadgets</string></field>
<field name="displayName"><string>Hello Gadget</string></field>
<field name="description"><string>The simplest gadget</string></field>
<field name="type"><string>gadget</string></field>
<field name="contentId"><string>HelloGadget</string></field>
<field name="accessPermissions">
<collection type="java.util.ArrayList" item-type="java.lang.String">
<value><string>*:/developers</string></value>
</collection>
</field>
</object>
</value>
</collection>
</field>
</object>
</object-param>
</init-params>
</component-plugin>
</external-component-plugins>
Stop the server and clean up database, then restart. You will now see the Hello World gadget added to the My Gadgets category:
You have to clean up the database because the categories defined in the Application Registry Service configuration are created only when you start eXo Platform for the first time, and when the JCR repository is empty. However, you could avoid cleaning up database and restarting the server by using the API as below.
Avoid cleaning up database and restarting the server
Create the category by using the following code:
PortalContainer container = PortalContainer.getInstance();
ApplicationRegistryService appService = (ApplicationRegistryService)container.getComponentInstanceOfType(ApplicationRegistryService.class);
try {
if (appService.getApplication("MyGadgets/HelloGadget") == null) {
ApplicationCategory cat = new ApplicationCategory();
cat.setName("MyGadgets");
cat.setDisplayName("My Gadgets");
cat.setDescription("List of personal gadgets for development");
cat.setAccessPermissions(Arrays.asList("*:/developers"));
Application app = appService.getApplication("Gadgets/HelloGadget");
appService.save(cat, app);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
Add the above code block to one portlet action, for example:
@Override
public void processAction(ActionRequest actionRquest, ActionResponse actionResponse) {
PortalContainer container = PortalContainer.getInstance();
ApplicationRegistryService appService = (ApplicationRegistryService)container.getComponentInstanceOfType(ApplicationRegistryService.class);
try {
if (appService.getApplication("MyGadgets/HelloGadget") == null) {
ApplicationCategory cat = new ApplicationCategory();
cat.setName("MyGadgets");
cat.setDisplayName("My Gadgets");
cat.setDescription("List of personal gadgets for development");
cat.setAccessPermissions(Arrays.asList("*:/developers"));
Application app = appService.getApplication("Gadgets/HelloGadget");
appService.save(cat, app);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@RenderMode(name = "view")
public void hello(RenderRequest request, RenderResponse response) throws IOException, PortletException {
PrintWriter writer = response.getWriter();
PortletURL actionURL = response.createActionURL();
writer.append("<p>Click <a href='" + actionURL.toString() + "'>here</a> to create MyGadgets category</p>");
}
Deploy the portlet to which you have added the above code block, then do the portlet action.