Capabilities
Product
Education
Knowledge Base
Contact Us
Writing a Form Storage Adapter
Liferay DXP 7.3 and Liferay DXP 7.2 versions that include the fix for LPS-97208 (planned for Liferay DXP 7.2 SP3)
By default, forms are stored as JSON in Liferay DXP’s database. This example shows you how to implement a new storage adapter to inject custom logic into a form record persistence event.

The default storage adapter saves form records in the Liferay DXP database as JSON content. Next, add logic to store each Form Record on the file system.
Examine a Running DDM Storage Adapter
To see how storage adapters work, deploy an example and then add some form data using the example adapter.
Deploy the Example
Start a new Liferay instance by running
docker run -it -m 8g -p 8080:8080 liferay/portal:7.4.3.132-ga132
Sign in to Liferay at http://localhost:8080. Use the email address test@liferay.com and the password test. When prompted, change the password to learn.
Then, follow these steps:
-
Download and unzip the DDM Storage Adapter project.
curl https://resources.learn.liferay.com/examples/liferay-r2f1.zip -Ounzip liferay-r2f1.zip -
From the module root, build and deploy.
./gradlew deploy -Ddeploy.docker.container.id=$(docker ps -lq)TipThis command is the same as copying the deployed jars to
/opt/liferay/osgi/moduleson the Docker container. -
Confirm the deployment in the Liferay Docker container console.
STARTED com.acme.r2f1.impl_1.0.0 [1009]
Use the Deployed Storage Adapter
-
Open your browser to http://localhost:8080.
-
Go to the Forms application in Site Menu → Content & Data → Forms.
-
Click Add (
) to open the Form Builder. -
In the Form Builder view, click Options (
) and open the Settings window. -
Under Select a Storage Type, choose the R2F1 Dynamic Data Mapping Storage Adapter type and click Done.
-
Add a Text Field to the form, publish the form, and submit it a few times.
-
To verify the form data were persisted, go to the Form’s Records:
From Site Menu → Content → Forms, click the Form’s Actions button (
), then View Entries.
-
Additionally, logging is provided in each CRUD method to demonstrate that the sample’s methods are being invoked.
WARN [http-nio-8080-exec-5][R2F1DDMStorageAdapter:82] Acme storage adapter's save method was invoked
Understand the Extension Point
The example contains only one class: R2F1DDMStorageAdapter, a service implementing a DDMStorageAdapter to provide logic for storing Form Entries. The deployed example currently just wraps the default JSON implementation: DefaultDDMStorageAdapter. Later, add file system storage to the code that’s already here.
Register the Adapter Class with the OSGi Container
The DDMFileSystemStorageAdapter implements the DDMStorageAdapter interface, but must be registered as an OSGi service:
@Component(
property = "ddm.storage.adapter.type=r2f1-ddm-storage-adapter",
service = DDMStorageAdapter.class
)
public class R2F1DDMStorageAdapter implements DDMStorageAdapter {