掲示板

Bug uploading images for repeatable fields in journal articles

thumbnail
10年前 に Daniele Tramis によって更新されました。

Bug uploading images for repeatable fields in journal articles

New Member 投稿: 4 参加年月日: 06/10/11 最新の投稿
When uploading images nested into a repeatable field like the following:

<dynamic-element datatype="string" indextype="keyword" name="txtLink" readonly="false" repeatable="true" required="false" showlabel="true" type="text" width="small">
		<dynamic-element datatype="string" indextype="keyword" name="txtLinkToView" readonly="false" repeatable="false" required="false" showlabel="true" type="text" width="small">
			<meta-data locale="en_US">
				<entry name="label">
					testo link
				</entry>
				<entry name="predefinedValue">
					
				</entry>
				<entry name="tip">
					
				</entry>
			</meta-data>
		</dynamic-element>
		<dynamic-element datatype="image" fieldnamespace="wcm" indextype="keyword" name="imgAssoc" readonly="false" repeatable="false" required="false" showlabel="true" type="wcm-image" width="">
			<meta-data locale="en_US">
				<entry name="label">
					Image
				</entry>
				<entry name="predefinedValue">
					
				</entry>
				<entry name="tip">
					
				</entry>
			</meta-data>
		</dynamic-element>
		<meta-data locale="en_US">
			<entry name="label">
				link pagina
			</entry>
			<entry name="predefinedValue">
				
			</entry>
			<entry name="tip">
				
			</entry>
		</meta-data>
	</dynamic-element>

the system store only the first image for each repeatable field.
The problem in into the class com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl into the method format(...) that store always the first image of the array of images.

A possible patch is like this:

	protected void format(
			User user, long groupId, String articleId, double version,
			boolean incrementVersion, Element root, Map<string, byte[]> images)
		throws PortalException, SystemException {

		for (Element element : root.elements()) {
			String elInstanceId = element.attributeValue(
				"instance-id", StringPool.BLANK);
			String elType = element.attributeValue("type", StringPool.BLANK);

			if (elType.equals("image")) {
				String elName = element.attributeValue(
					"name", StringPool.BLANK);
				String elIndex = root.attributeValue(
					"index", StringPool.BLANK);

				String name = elName + "_" + elIndex;

				formatImage(
					groupId, articleId, version, incrementVersion, element,
					elInstanceId, name, images);
			}
			else if (elType.equals("text_area") || elType.equals("text") ||
					 elType.equals("text_box")) {

				List<element> dynamicContentElements = element.elements(
					"dynamic-content");

				for (Element dynamicContentElement : dynamicContentElements) {
					String dynamicContent = dynamicContentElement.getText();

					if (Validator.isNotNull(dynamicContent)) {
						String contentType = ContentTypes.TEXT_PLAIN;

						if (elType.equals("text_area")) {
							contentType = ContentTypes.TEXT_HTML;
						}

						dynamicContent = SanitizerUtil.sanitize(
							user.getCompanyId(), groupId, user.getUserId(),
							JournalArticle.class.getName(), 0, contentType,
							dynamicContent);

						dynamicContentElement.clearContent();

						dynamicContentElement.addCDATA(dynamicContent);
					}
				}
			}

			format(
				user, groupId, articleId, version, incrementVersion, element,
				images);
		}
	}
</element></string,>
10年前 に Luis Higuera によって更新されました。

RE: Bug uploading images for repeatable fields in journal articles

New Member 投稿: 2 参加年月日: 14/01/12 最新の投稿
greetings,

Thanks for your post, but how I can implement this patch?.

I have exactly this problem.
thumbnail
10年前 に Daniele Tramis によって更新されました。

RE: Bug uploading images for repeatable fields in journal articles

New Member 投稿: 4 参加年月日: 06/10/11 最新の投稿
Hi Luis,
I'm happy to help you with you issue. To implement this patch you just need to compile the attached java class and put it into ROOT/WEB-INF/lib/portal-impl.jar library.
10年前 に Luis Higuera によって更新されました。

RE: Bug uploading images for repeatable fields in journal articles

New Member 投稿: 2 参加年月日: 14/01/12 最新の投稿
Thank you very much,

I'm a newbie in liferay, and though I could compile only the java class, but what is the correct way to put it into the library "portal-impl.jar"?, Or I should get the sources of "portal-impl" and make the change there and then build the new jar?, or i should create a "hook" to "portal-impl".... Or just put the new class file into the jar (package) replacing the previous one.

Thanks again

Daniele Tramis:
Hi Luis,
I'm happy to help you with you issue. To implement this patch you just need to compile the attached java class and put it into ROOT/WEB-INF/lib/portal-impl.jar library.
10年前 に RUBINO LUCA によって更新されました。

RE: Bug uploading images for repeatable fields in journal articles

New Member 投稿: 2 参加年月日: 13/11/04 最新の投稿
If I'm right the interested line is:
	String elIndex = element.attributeValue(
					"index", StringPool.BLANK);

and the correct version is:
	String elIndex = root.attributeValue(
                    "index", StringPool.BLANK);


Can somone confirm, please?


BTW: the official issue is there LPS-44308 Custom Structure - No save repeat input type image
9年前 に Darryl Kpizingui によって更新されました。

RE: Bug uploading images for repeatable fields in journal articles

Junior Member 投稿: 82 参加年月日: 13/01/10 最新の投稿
The code shipped with Liferay is

String elIndex = root.attributeValue( "index", StringPool.BLANK);


The **correct** one is

String element = element.attributeValue( "index", StringPool.BLANK);

as element is the node representing the image field.

for (Element element : root.elements()) {
			String elInstanceId = element.attributeValue(
				"instance-id", StringPool.BLANK);
			String elType = element.attributeValue("type", StringPool.BLANK);

			if (elType.equals("image")) {


But the fix works only if the image node is the repeatable element. In other case the index is always 0. So all other images are replaced by the first one. I guess this is why you have the issue, regarding the XML structure you posted in JIRA.
thumbnail
9年前 に Marco Abbuonandi によって更新されました。

RE: Bug uploading images for repeatable fields in journal articles

New Member 投稿: 4 参加年月日: 14/12/27 最新の投稿
Another possible solution and that should cover all cases (works for me), is the following:

element.addAttribute("checked", "checked");
// Find all node of type image and attribute-name of element parameter
XPath xPathSelector = SAXReaderUtil.createXPath("//dynamic-element[@name=\""+element.attributeValue("name", StringPool.BLANK)+"\"]");
List<Node> nodes = xPathSelector.selectNodes(element.getDocument());
int correctIndex = 0;
for(Node node : nodes){
if(node.asXML().contains("checked=\"checked\"")){
break;
}
correctIndex++;
}

String elIndex = String.valueOf(correctIndex); /* IMPORTANT This is correct "elIndex" associated to file */
element.remove(element.attribute("checked"));