The Documents and Media API lets you
copy or move
folders to a different location. Options for in-place folder updates, however,
are limited. You can only update a folder’s name and description. You can do
this with the
DLAppService
method updateFolder
:
updateFolder(long folderId, String name, String description, ServiceContext serviceContext)
All parameters except the description are mandatory. For a full description of this method and its parameters, see its Javadoc.
Follow these steps to use this method to update a folder:
-
Get a reference to
DLAppService
:@Reference private DLAppService _dlAppService;
For more information on this, see the section on getting a service reference in the getting started tutorial.
-
Get the data needed to populate the
updateFolder
method’s arguments. Since it’s common to update a folder with data submitted by the end user, you can extract the data from the request. This example does so viajavax.portlet.ActionRequest
andParamUtil
, but you can get the data any way you wish:long folderId = ParamUtil.getLong(actionRequest, "folderId"); String name = ParamUtil.getString(actionRequest, "name"); String description = ParamUtil.getString(actionRequest, "description"); ServiceContext serviceContext = ServiceContextFactory.getInstance( DLFolder.class.getName(), actionRequest);
For more information on getting folder IDs, see the getting started tutorial’s section on specifying folders. For more information on
ServiceContext
, see the tutorial Understanding ServiceContext. -
Call the service reference’s
updateFolder
method with the data from the previous step:_dlAppService.updateFolder(folderId, name, description, serviceContext);
You can find the full code for this example in the updateFolder
method of
Liferay DXP’s
EditFolderMVCActionCommand
class. This class uses the Documents and Media API to implement almost all the
Folder
actions that the Documents and Media app supports. Also note that
this updateFolder
method, as well as the rest of EditFolderMVCActionCommand
,
contains additional logic to suit the specific needs of the Documents and Media
app.