1

I am trying to get the metadata of the component published to broker. Here is the code snippet -

Note :- in docIds[i] i have the component Ids.

ComponentPresentationFactory compfac = new ComponentPresentationFactory(pubId);
ComponentMetaFactory compmf = new ComponentMetaFactory(pubId);

for (int i =0; i < docIds.length; i++)
{
  ComponentPresentation cp = cpf.getComponentPresentation(docIds[i], "tcm:189-2786-32");    
  ComponentMeta meta = cmf.getMeta(docIds[i]);
  CustomMeta custom = meta.getCustomMeta();
  Map<String, NameValuePair> map = custom.getNameValues();
 NameValuePair pair = map.get("date");
 String value = (String) pair.getFirstValue(); }

I am not able to get the value of "date" metadata field of the components .Could somebody help me here.

Is my approach is correct or i have to go some other way around.

7
  • What do you mean by I am not able to get the metadata? What is wrong with the code you've posted?
    – Ant P
    Apr 28, 2014 at 17:10
  • Hi Ant,I am not sure what is wrong, but i am not getting anything. R u saying that the code is correct and it should work.
    – user584
    Apr 28, 2014 at 17:12
  • 2
    Where do you declare cmf, which doesn't seem to match the ComponentMetaFactory compmf.? In terms of the methods, I understand we have .getMeta() but .getCustomMeta() and .getNameValues() aren't familiar. There are properties called .CustomMeta() and .NameValues(), though. See a Bart Koopman's example in this answer: tridion.stackexchange.com/a/2783/46. Maybe you have the wrong object? Apr 28, 2014 at 18:28
  • 2
    The methods in the code are correct, the examples @AlvinReyes refers to are .NET, not Java. His point about the cmf / compmf confusion is correct, but I guess those are copy/paste errors?
    – Quirijn
    Apr 28, 2014 at 22:19
  • The first place to check is in the Broker database and to see whether the CUSTOM_META table is filled correctly. I wonder for instance whether a field name called 'date' is actually inputted in the right way and whether the date is actually set correctly. If the correct values are present, check the values of the Map<String,NameValuePair> with a debugger. Pay special attention to the actual Type for each map entry and value.
    – Raimond
    Apr 29, 2014 at 6:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.