Step 1: Create a structure in portal.
To know how to create structure :
http://liferayplanet.blogspot.in/2015/01/structure-and-template-in-liferay-62.html
Step 2: Then in your jsp page
long structureId= 12345;
ServiceContext serviceContext = ServiceContextFactory.getInstance(request);
DDMStructure ddm = null;
ddm = DDMStructureLocalServiceUtil.getDDMStructure(structureId);
Fields newFields = DDMUtil.getFields(
ddm.getStructureId(), serviceContext);
Here we get ddmstructure and we will use DDMUtil.getFields to get all the form fields.
Step 3:Then use the below tag
<%@ taglib uri="http://liferay.com/tld/ddm" prefix="liferay-ddm"%>
<liferay-ddm:html
classNameId="<%= PortalUtil.getClassNameId(DDMStructure.class)%>"
classPK="<%= ddm.getStructureId() %>"
fields="<%= newFields %>"
/>
Step 4:Then to get in controller use
ServiceContext serviceContext;
DDMStructure ddmStructure = null;
serviceContext = ServiceContextFactory.getInstance(
JournalArticle.class.getName(), actionRequest);
Object[] contentAndImages = null;
ddmStructure = DDMStructureLocalServiceUtil
.getDDMStructure(structureId);
Locale locale = LocaleUtil.getDefault();
contentAndImages = getContentAndImages(
ddmStructure, locale, serviceContext);
content = (String) contentAndImages[0];
public static Object[] getContentAndImages(
DDMStructure ddmStructure, Locale locale,
ServiceContext serviceContext)
throws Exception {
Fields fields = DDMUtil.getFields(
ddmStructure.getStructureId(), serviceContext);
Map<String, byte[]> images = getImages(fields, locale);
return new Object[] {
JournalConverterUtil.getContent(ddmStructure, fields), images
};
}
protected static Map<String, byte[]> getImages(Fields fields, Locale locale)
throws Exception {
Map<String, byte[]> images = new HashMap<String, byte[]>();
for (Field field : fields) {
String dataType = field.getDataType();
if (!dataType.equals(FieldConstants.IMAGE)) {
continue;
}
List<Serializable> values = field.getValues(locale);
for (int i = 0; i < values.size(); i++) {
String content = (String)values.get(i);
if (content.equals("update")) {
continue;
}
StringBundler sb = new StringBundler(6);
sb.append(StringPool.UNDERLINE);
sb.append(field.getName());
sb.append(StringPool.UNDERLINE);
sb.append(i);
sb.append(StringPool.UNDERLINE);
sb.append(LanguageUtil.getLanguageId(locale));
images.put(sb.toString(), UnicodeFormatter.hexToBytes(content));
}
}
return images;
}
Tuesday, 21 November 2017
03:30
MR: EDITOR
TEST
I am Java Developer. I have 6 year Experiance in this field and like to post in blogging. So keep sharing and like my post
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment