To update a folder with the Documents and Media API, you must use the
updateFolder
method discussed in
Updating Entities.
The steps here show you how. For general information on using the API, see
Documents and Media API.
Follow these steps to update a folder:
-
Get a reference to
DLAppService
:@Reference private DLAppService _dlAppService;
-
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);
-
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.