Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
How to programmatically create a form
			It is possible to programmatically create a form based on a specific element set.
This is done through the "DDMFormInstanceLocalServiceUtil.addFormInstance" method.
See attached sample code for more details.
Disclaimer: Please note that this is a sample of how to extend your portlet and should only be used as a reference.
		This is done through the "DDMFormInstanceLocalServiceUtil.addFormInstance" method.
// Here goes your existing element set Id
long ddmStructureId = 33869;
// Initialize form instance
long ddmInstanceId = CounterLocalServiceUtil.increment(DDMFormInstance.class.getName());
DDMFormInstance ddmFormInstance = DDMFormInstanceLocalServiceUtil.createDDMFormInstance(ddmInstanceId);
ddmFormInstance.setStructureId(ddmStructureId);
// Retrieve the element set
DDMStructure ddmStructure = null;
try {
	ddmStructure = DDMStructureLocalServiceUtil.getDDMStructure(ddmStructureId);
} catch (PortalException e) {
	e.printStackTrace();
}
// Convert it into formValues needed for addFormInstance
DDMForm ddmForm = ddmStructure.getDDMForm();
DDMFormValues ddmFormValues = _ddmFormValuesFactory.create(actionRequest, ddmForm);
// Set name and description for the new form
Map<locale, string> name = new HashMap<locale, string>();
name.put(LocaleUtil.US, "New Form");
Map<locale, string> description = new HashMap<locale, string>();
description.put(LocaleUtil.US, "New Form Description");
// Create the form
try {
	DDMFormInstanceLocalServiceUtil.addFormInstance(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), ddmStructureId, name, description, ddmFormValues, serviceContext);
} catch (PortalException e) {
	e.printStackTrace();
}</locale,></locale,></locale,></locale,>See attached sample code for more details.
Disclaimer: Please note that this is a sample of how to extend your portlet and should only be used as a reference.
Attachments: