You are looking at documentation for an older release. Not what you want? See the current release documentation.
There are 2 ways to change the category of a gadget:
Via UI as described in Adding a portlet/gadget to the Application list. However, this works only one time for a new gadget. After you have added it to a category, you could not change its category via UI.
By configuring ApplicationCategoriesPlugins
, as detailed below.
Here is the configuration example to add Hello World gadget to the My Gadgets category.
Add the following configuration to WEB-INF/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>
Deploy it to a fresh server. You will see the category is automatically added:
This method only works for a fresh (empty data) server because the categories defined in the ApplicationRegistryService configuration are created all in once when you start eXo Platform for the first time, and when the JCR repository is empty. In case the server is started already, you may write a portlet for this job, as described below.
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.