You are here

Updating metadata in a WebCenter Content Presenter template

I already made some post explaining that a content presenter template can do more than just present the content. You can add pagination or a read more link but you can also add real functionality that can be useful for the content owner or administrator.

For example in this post I will explain how we can add a link to the content presenter that will open a popup where we can update the metadata of the content.

Updating metadata of the content will be done by using RIDC which is the native API for connecting to WebCenter Content where the content is stored.

In this post I will not only show how to build this template but also how to use RIDC and reuse the connection defined in JDeveloper or Enterprise Manager.

You can download the example application here.

Because we are going to use RIDC in the application, we need to add the library to the project. This is done in the library and classpath section of the project properties. Click on Add Library and select the RIDC Library:

Creating the managed bean with functionality

Before we can use RIDC in the content presenter template we need to create a managed bean that will execute the RIDC services.

In the example project you will find the bean called RidcBean in the portal package. In the bean we have a dialog listener that will be executed when we press on the OK button of dialog which we will add to the content presenter. This is the code of the listener:

  1. public void doUpdate(DialogEvent e) throws Exception {
  2.    if(e.getOutcome().equals(DialogEvent.Outcome.ok)){
  3.         Object o = get("#{node}");
  4.         Node node = (Node)o;
  5.        String id = node.getProperty("dID").getValue().toString();
  6.        String name = node.getProperty("dDocName").getValue().toString();
  7.        binder.putLocal("IdcService", "UPDATE_DOCINFO");
  8.        binder.putLocal("dID",id);
  9.        binder.putLocal("dDocName", name);
  10.        binder.putLocal("dDocTitle", title);
  11.        binder.putLocal("xCategory", category);
  12.        try{
  13.           ServiceResponse response = client.sendRequest (context, binder);
  14.           binder = response.getResponseAsBinder ();
  15.       }
  16.      catch(Exception ex){
  17.        ex.printStackTrace();
  18.      }
  19.   }
  20. }

The code itself is not that complex. It just adds the required parameters to the binder which is connected to UCM.

In order to update metadata we have to execute the UPDATE_DOCINFO service from UCM. This service requires the dID and dDocName parameter to identify the document that we want to update. All the other parameters are the metafields that will be updated with the new value.

So as you can see from this example, we will only update dDocTitle and the xCategory. The last one is a custom field I have added to my Content Server. You can add whatever metadata you want in this binder to update.

As you also notice, we don't specify a connection to the UCM server. This is covered in the constructor of our bean with an initialization:

  1. public RidcBean() throws Exception {
  2.    super();
  3.    initBean();
  4. }
  6. private void initBean() throws Exception {
  7.   client = StellentUtils.getIdcClient("ucm");  
  8.   context = StellentUtils.getDefaultIdcContext("ucm");
  9.   binder = client.createBinder();
  10. }

The initBean just asks the WebCenter framework to pass the IdC connection with the name "ucm". This is the name of the connection we specify in JDeveloper or in the Enterprise manager. As you can see, we simply are reusing the connection. StellentUtils is part of the WebCenter framework and is not a custom class so this allows us to reuse these connections.

Now that we have our bean, we need to register it to our application in the faces-config.xml:

Now we have done the preparation, we can start building the template.

Creating the template

The template is stored in the updateMetaTemplate.jsff and has following source:

  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <jsp:root xmlns:jsp="" version="2.1"
  3.    xmlns:dt=""
  4.    xmlns:af="">
  5.   <dt:contentTemplateDef var="node">
  6.     <af:commandLink rendered="#{composerContext.subView == 'contentContribution'}"
  7.            text="Update metadata"  id="cmdUpdate" partialSubmit="true">
  8.         <af:showPopupBehavior popupId="popMetadata" triggerType="action"/>
  9.     </af:commandLink>
  10.     <af:popup id="popMetadata" contentDelivery="lazyUncached">
  11.         <af:dialog title="Metadata" id="dlgMetadata"
  12.                   dialogListener="#{ridcBean.doUpdate}">
  13.             <af:panelFormLayout id="pnlForm">
  14.                 <af:inputText value="#{ridcBean.title}"
  15.                    label="Title" id="txtTitle"/>
  16.                 <af:inputText value="#{ridcBean.category}"
  17.                   label="Category" id="txtCat"/>
  18.             </af:panelFormLayout>
  19.         </af:dialog>
  20.     </af:popup>
  21.     <dt:contentTemplate node="#{node}" id="ct1"
  22.         view="oracle.webcenter.content.templates.default.detail"/>
  23.   </dt:contentTemplateDef>
  24. </jsp:root>

Nothing really special in this template. It uses normal ADF and JSF functionality to bind values of an inputText to a String in a managed bean and the dialogListener will be executed when we click on the OK button and thus execute the RIDC service.

Something really useful here is the expression language to check if we are in contribution mode:
#{composerContext.subView == 'contentContribution'}

This way we can render the commandLink only when the user enters contribution mode. If we would not add this check, the link will be displayed all the time and we don't want this.

So as you can see, nothing really special in this template.

Let's register the template as a portal resource and we can test it:

Let's run the Portal project and add the content presenter on a page to see if it works.

So I selected a content item in the content presenter:

And specified my template:

This is a normal wiki document so it will show up in my portal:

Nothing special so far and it does not seem to change the default template. Let's see what happens when I enter contribution mode:

Now you see that the Update metadata link is showing and I can specify the new title and category:

When I press OK and I look for this content item in my content server I will see that the metadata has been updated:

This example just shows you how you can make proper use of the content presenter template to add additional functionality.

It is not just limited to updating metadata, you can do whatever you want. By using RIDC you can access almost all of the functionality from the content server. You could write complete workflow functionality inside the content presenter so it is easy for the user to approve or reject changes that are in the workflow.

The only limitations that content presenter templates have is that they cannot have a page definition which means that you cannot use the binding layer in the template. This means that you cannot use data control or anything in the templates unless you access them programatoricaly from inside a managed bean. It also means that you cannot add taskflows to a content presenter template because taskflows have their definition in the page definition and because a content presenter template does not have a page definition, taskflows cannot be added.



its a really nice example given over here for updating the metadata..
i also want to achieve something like this by taking a step further by adding a new custom attribute to a content item of webcenter content..
But i am stuck in the beginning only as i don't have any idea from where to start..
Can you please suggest from where should begin..??

What do you exactly mean? Allowing users in WebCenter Portal to create new metadata fields and assign values to it?

Not exactly the WebCenter Portal,
I just want to execute it through a normal ADF fusion application by using RIDC,
No need to go for it through UI , just simply want to alter the information associated with document.
Is it possible to create a new metadata field for the Webcenter content...
And if its not, is there a way we can add a new metadata field to a particular content item, such as a particular text file.


Yes you got it right. I want to create a new metadata field and assign value to it by using RIDC.

I don't think that is possible through RIDC.
I even think that's not a good idea because it allows users to create metadata on the fly. You have to know that each field in UCM is actually a column in the database. By adding metadata you are executing an "ALTER TABLE" command.
That's why the management of the metafields is in the admin section of UCM.

You might want to ask the question on the UCM forum:
They might be able to give you a solution, if it exists.

Can I create blog entry in webcenter content using RIDC and also post comments to blog entries

A blog is basically just an HTML document in UCM. Sure you can create it using RIDC. You just have to assign it the correct metadata and I don't know which that is for a blog to be honest.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer