Custom field on DL not updating

Etienne Roy, modified 12 Years ago. Regular Member Posts: 114 Join Date: 8/8/13 Recent Posts
Hi,
I create a custom field for the Documents and Media Document
this new field add automatically on the page
When I add a new document, the new field was saved in the expendo table but I can't update this field after

Do I have to make a modification to update the field ?

thanks
thumbnail
Zsigmond Rab, modified 12 Years ago. Liferay Master Posts: 764 Join Date: 1/5/10 Recent Posts
Hi Etienne,

why cannot you update? What is the symptom either on the UI or in the log files.

Regards,
Zsigmond
thumbnail
Fabian Leonardo Lopez, modified 12 Years ago. New Member Posts: 12 Join Date: 9/18/13 Recent Posts
I'm having the same problem,

after creating some expando columns programatically they appear to be working fine even creating the DL entry but after creation if i try to update any of the custom attributes nothing happend however the normal attributes of the DL entry change as expected.

more information here
any ideas?
thumbnail
Nagendra Kumar Busam, modified 12 Years ago. Liferay Master Posts: 678 Join Date: 7/7/09 Recent Posts
Which version of liferay you are using?

Can you share code snippet for how you are adding your custom fields programmatically , so that we can look where the actual issue is
thumbnail
sushil patidar, modified 12 Years ago. Expert Posts: 467 Join Date: 10/31/11 Recent Posts
Etienne Roy:
Hi,
I create a custom field for the Documents and Media Document
this new field add automatically on the page
When I add a new document, the new field was saved in the expendo table but I can't update this field after

Do I have to make a modification to update the field ?

thanks


Hi,
I think problem is related to update permissions. Have you set update permissions for that custom field. First assign update permissions,then check.
I hope this may help you.


Thanks
thumbnail
Fabian Leonardo Lopez, modified 12 Years ago. New Member Posts: 12 Join Date: 9/18/13 Recent Posts
Hi.

In my case, I am having this problem with the portal administrator, however y put all the permissions for the field to the power user role wich is also a role on the user i'm using but the custom field remains unmodified.

I'm using version 6.1 GA3 of LP if that brings any light on the matter.

Thanks in advance.
thumbnail
Fabian Leonardo Lopez, modified 12 Years ago. New Member Posts: 12 Join Date: 9/18/13 Recent Posts
Finally made it work!!

i developed a hook in the struts action /document_library/edit_file_entry
after the entry is updated i manually set the expandos with a couple of methods that looks something like this.


private static final Pattern EXPANDO_PATTERN = Pattern.compile("ExpandoAttribute--(.*)--");

private void updateExpandosForFileEntries(PortletRequest request, FileEntry fileEntry){
		Set<string> values = new HashSet<string>();
		
		for(String param :  request.getParameterMap().keySet()){
                        // aplies the method only to the expando parameters
			Matcher matcher = EXPANDO_PATTERN.matcher(param);
			if(matcher.find()){
				String expandoParam = matcher.group(1);
				
				if(values.contains(expandoParam)){
					continue;
				}
				else{
					updateExpandosForFileEntry(request, expandoParam, fileEntry);
					values.add(expandoParam);
				}
			}
		}
		
	}



private void updateExpandosForFileEntry(PortletRequest request, String expandoName, FileEntry fileEntry){
		
		String nameParam = "ExpandoAttribute--" + expandoName + "--";
		String paramValue = request.getParameter(nameParam);
		
		if(Validator.isNotNull(paramValue)){
			int type = fileEntry.getExpandoBridge().getAttributeType(expandoName);
			if(type == ExpandoColumnConstants.BOOLEAN){
				fileEntry.getExpandoBridge().setAttribute(expandoName, paramValue.equals("1")?true:false);
				return;
			}
			fileEntry.getExpandoBridge().setAttribute(expandoName, paramValue);
		} else{
			String dateYear = nameParam + "Year";
			String dateMonth = nameParam + "Month";
			String dateName = nameParam + "Day";
			String dateAmPm = nameParam + "AmPm";
			String dateHour = nameParam + "Hour";
			String dateMinute = nameParam + "Minute";
			
			Calendar expandoCalendar = Calendar.getInstance();
			
			expandoCalendar.set(Calendar.YEAR, ParamUtil.getInteger(request, dateYear));
			expandoCalendar.set(Calendar.MONTH, ParamUtil.getInteger(request, dateMonth));
			expandoCalendar.set(Calendar.DAY_OF_MONTH, ParamUtil.getInteger(request, dateName));
			expandoCalendar.set(Calendar.AM_PM, ParamUtil.getInteger(request, dateAmPm));
			expandoCalendar.set(Calendar.HOUR, ParamUtil.getInteger(request, dateHour));
			expandoCalendar.set(Calendar.MINUTE, ParamUtil.getInteger(request, dateMinute));
			
			try {
				fileEntry.getExpandoBridge().setAttribute(expandoName, expandoCalendar.getTime());
			} catch (Exception e) {
				_log.error(e);
			}
		}
	}
</string></string>


I know it's dirty but i had to do it emoticon