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
Unable to set values on DDM Fields like date and radio button(Liferay v7.2)
Someone please help me out to update DDM field value programmatically below is the code I am using.
import com.liferay.dynamic.data.lists.model.DDLRecord;
import com.liferay.dynamic.data.lists.model.DDLRecordConstants;
import com.liferay.dynamic.data.lists.model.DDLRecordSet;
import com.liferay.dynamic.data.lists.service.DDLRecordLocalServiceUtil;
import com.liferay.dynamic.data.lists.service.DDLRecordSetLocalServiceUtil;
import com.liferay.dynamic.data.mapping.model.DDMStructure;
import com.liferay.dynamic.data.mapping.storage.Fields;
import com.liferay.dynamic.data.mapping.util.DDMUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.service.ServiceContextFactory;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
@Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=FordFleetCare",
"com.liferay.portlet.instanceable=false",
"javax.portlet.display-name=FordFleetCareForms",
"javax.portlet.name=FordFleetCareForms",
"javax.portlet.init-param.template-path=/",
"javax.portlet.security-role-ref=power-user,user",
"javax.portlet.init-param.view-template=/fordfleetcareforms/form.jsp"
},
service = Portlet.class
)
public class FormsPortlet extends MVCPortlet {
public void addDetails(ActionRequest actionRequest, ActionResponse response)
throws IOException, PortletException, PortalException {
UploadPortletRequest uploadPortletRequest =
PortalUtil.getUploadPortletRequest(actionRequest);
ThemeDisplay themeDisplay =(ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long recordSetId =
ParamUtil.getLong(
uploadPortletRequest, "recordSetId");
String storeDataLocally = ParamUtil.getString(uploadPortletRequest, "storeData"); LOGGER.info("RECORD SET ID >>" + recordSetId);
LOGGER.info("STORE DATE LOCALLY >>" + storeDataLocally); long groupId = themeDisplay.getScopeGroupId();
ServiceContext serviceContext = ServiceContextFactory.getInstance(
DDLRecord.class.getName(), uploadPortletRequest);
try {
DDLRecordSet ddlRecordSet=DDLRecordSetLocalServiceUtil.getDDLRecordSet(recordSetId);
DDMStructure ddmStructure =ddlRecordSet.getDDMStructure();
Fields fields = DDMUtil.getFields(ddmStructure.getStructureId(), serviceContext);
List<String> rootFields = ddmStructure.getRootFieldNames();
for(String rootField : rootFields){
String type= ddmStructure.getFieldType(rootField);
String value =ParamUtil.getString(uploadPortletRequest, rootField);
LOGGER.info("FIELD NAME : "+rootField);
LOGGER.info("FIELD TYPE : "+type);
LOGGER.info("FIELD VALUE : "+value);
if(type.toLowerCase().contains("date")){
fields.get(rootField).addValue(themeDisplay.getLocale(),new java.util.Date(value));
}
else if( type.toLowerCase().contains("radio")) {
try {
fields.get(rootField).addValue(themeDisplay.getLocale(), ddmStructure.getDDMFormField(rootField).getDDMFormFieldOptions().getOptions().get(0));
}catch(Exception e) {
LOGGER.error("ERROR ** ",e);
}
LOGGER.info("FIELD RADIO VALUES : "+value);
}else{
fields.get(rootField).addValue(themeDisplay.getLocale(),value); }
}
DDLRecordLocalServiceUtil.addRecord(themeDisplay.getUserId(),groupId, recordSetId, DDLRecordConstants.DISPLAY_INDEX_DEFAULT, fields, serviceContext);
}catch(Exception e) {
LOGGER.error("ERROR ** ",e);
}
}private static final Log LOGGER=LogFactoryUtil.getLog(FormsPortlet.class.getName());
}
I am getting below errors.
1. On the date field, I am getting an unparsable date from date.ftl file.
2. On the radio button field, I am getting "com.liferay.dynamic.data.mapping.form.field.type.DDMFormFieldValueValidationException: The selected option "option2" is not a valid alternative"
@liferay team please help me out on the above issue.
import com.liferay.dynamic.data.lists.model.DDLRecord;
import com.liferay.dynamic.data.lists.model.DDLRecordConstants;
import com.liferay.dynamic.data.lists.model.DDLRecordSet;
import com.liferay.dynamic.data.lists.service.DDLRecordLocalServiceUtil;
import com.liferay.dynamic.data.lists.service.DDLRecordSetLocalServiceUtil;
import com.liferay.dynamic.data.mapping.model.DDMStructure;
import com.liferay.dynamic.data.mapping.storage.Fields;
import com.liferay.dynamic.data.mapping.util.DDMUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.service.ServiceContextFactory;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
@Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=FordFleetCare",
"com.liferay.portlet.instanceable=false",
"javax.portlet.display-name=FordFleetCareForms",
"javax.portlet.name=FordFleetCareForms",
"javax.portlet.init-param.template-path=/",
"javax.portlet.security-role-ref=power-user,user",
"javax.portlet.init-param.view-template=/fordfleetcareforms/form.jsp"
},
service = Portlet.class
)
public class FormsPortlet extends MVCPortlet {
public void addDetails(ActionRequest actionRequest, ActionResponse response)
throws IOException, PortletException, PortalException {
UploadPortletRequest uploadPortletRequest =
PortalUtil.getUploadPortletRequest(actionRequest);
ThemeDisplay themeDisplay =(ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long recordSetId =
ParamUtil.getLong(
uploadPortletRequest, "recordSetId");
String storeDataLocally = ParamUtil.getString(uploadPortletRequest, "storeData"); LOGGER.info("RECORD SET ID >>" + recordSetId);
LOGGER.info("STORE DATE LOCALLY >>" + storeDataLocally); long groupId = themeDisplay.getScopeGroupId();
ServiceContext serviceContext = ServiceContextFactory.getInstance(
DDLRecord.class.getName(), uploadPortletRequest);
try {
DDLRecordSet ddlRecordSet=DDLRecordSetLocalServiceUtil.getDDLRecordSet(recordSetId);
DDMStructure ddmStructure =ddlRecordSet.getDDMStructure();
Fields fields = DDMUtil.getFields(ddmStructure.getStructureId(), serviceContext);
List<String> rootFields = ddmStructure.getRootFieldNames();
for(String rootField : rootFields){
String type= ddmStructure.getFieldType(rootField);
String value =ParamUtil.getString(uploadPortletRequest, rootField);
LOGGER.info("FIELD NAME : "+rootField);
LOGGER.info("FIELD TYPE : "+type);
LOGGER.info("FIELD VALUE : "+value);
if(type.toLowerCase().contains("date")){
fields.get(rootField).addValue(themeDisplay.getLocale(),new java.util.Date(value));
}
else if( type.toLowerCase().contains("radio")) {
try {
fields.get(rootField).addValue(themeDisplay.getLocale(), ddmStructure.getDDMFormField(rootField).getDDMFormFieldOptions().getOptions().get(0));
}catch(Exception e) {
LOGGER.error("ERROR ** ",e);
}
LOGGER.info("FIELD RADIO VALUES : "+value);
}else{
fields.get(rootField).addValue(themeDisplay.getLocale(),value); }
}
DDLRecordLocalServiceUtil.addRecord(themeDisplay.getUserId(),groupId, recordSetId, DDLRecordConstants.DISPLAY_INDEX_DEFAULT, fields, serviceContext);
}catch(Exception e) {
LOGGER.error("ERROR ** ",e);
}
}private static final Log LOGGER=LogFactoryUtil.getLog(FormsPortlet.class.getName());
}
I am getting below errors.
1. On the date field, I am getting an unparsable date from date.ftl file.
2. On the radio button field, I am getting "com.liferay.dynamic.data.mapping.form.field.type.DDMFormFieldValueValidationException: The selected option "option2" is not a valid alternative"
@liferay team please help me out on the above issue.
No one here to provide any solution for this.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™