Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Gwowen Fu
How to set value for Metadata Sets Date field?
23 maggio 2012 14.46
Risposta

Gwowen Fu

Punteggio: Expert

Messaggi: 277

Data di Iscrizione: 27 dicembre 2010

Messaggi recenti

Hi,

In Documents and Media, I have created a new Document Type to include a Metadata Sets. The metadata set contains some Date fields.

When I set values for those metadata, all Text fields are set but not Date fields.
serviceContext.setAttribute("fileEntryTypeId", 26907);
serviceContext.setAttribute("26906FilePath", item.getFilePath());
serviceContext.setAttribute("26906Owner", item.getOwner());
serviceContext.setAttribute("26906Department", item.getDepartment());
serviceContext.setAttribute("26906PublishDate", item.getPublishDate());

I tried
serviceContext.setAttribute("26906PublishDate", "01/01/2012");

and the Date field is set to the wrong date "12/31/19xx", at least this confirms the field name is correct.

How should be set the value for Date metadata field?

Thanks!
Gwowen
Alexander Chow
RE: How to set value for Metadata Sets Date field?
23 maggio 2012 17.58
Risposta

Alexander Chow

LIFERAY STAFF

Punteggio: Liferay Master

Messaggi: 519

Data di Iscrizione: 19 luglio 2005

Messaggi recenti

What kind of class is returned by getPublishDate()? If I'm not mistaken, that needs to be a java.util.Date or the number of milliseconds since January 1, 1970.
Gwowen Fu
RE: How to set value for Metadata Sets Date field?
24 maggio 2012 11.29
Risposta

Gwowen Fu

Punteggio: Expert

Messaggi: 277

Data di Iscrizione: 27 dicembre 2010

Messaggi recenti

Alexander Chow:
What kind of class is returned by getPublishDate()? If I'm not mistaken, that needs to be a java.util.Date or the number of milliseconds since January 1, 1970.


Thanks for the information!
Checked the source code at LiferayRepositoryBase.getFieldsMap() and the value has to be a String.

 1
 2    protected HashMap<String, Fields> getFieldsMap(
 3            ServiceContext serviceContext, long fileEntryTypeId)
 4        throws PortalException, SystemException {
 5
 6        HashMap<String, Fields> fieldsMap = new HashMap<String, Fields>();
 7
 8        if (fileEntryTypeId <= 0) {
 9            return fieldsMap;
10        }
11
12        DLFileEntryType fileEntryType =
13            DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId);
14
15        List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures();
16
17        for (DDMStructure ddmStructure : ddmStructures) {
18            String namespace = String.valueOf(ddmStructure.getStructureId());
19
20            Set<String> fieldNames = ddmStructure.getFieldNames();
21
22            Fields fields = (Fields)serviceContext.getAttribute(
23                Fields.class.getName() + ddmStructure.getStructureId());
24
25            if (fields == null) {
26                fields = new Fields();
27
28                for (String name : fieldNames) {
29                    Field field = new Field();
30
31                    field.setName(name);
32
33                    String value = ParamUtil.getString(
34                        serviceContext, namespace + name);
35
36                    field.setValue(value);
37
38                    fields.put(field);
39                }
40            }
41
42            fieldsMap.put(ddmStructure.getStructureKey(), fields);
43        }
44
45        return fieldsMap;
46    }


This is the code that works:
1
2      serviceContext.setAttribute("26906PublishDate", String.valueOf(date.getTime()));