0

im new to using wcm library in jsp files and am a little stuck. I created a new element ("Publication Date") in the authoring templates im using and a custom jsp component which i am referencing from the atom call to generate the "updated date" field. What im trying to do is simply check to see if the element i added is present is not null, if it is then use the updated date field, if its not then use the "Publication Date" element.

I have tried:

DocumentIdIterator docIdsIter = workspace.findContentByPath(request.getRequestURI());
if (docIdsIter.hasNext()) {
    Document doc = (Document)workspace.getById(docIdsIter.nextId());
                    // Cast to Content to retrieve the Publication date from the date component
    Content myContent = (Content)doc;
                    // Get the Publication date
    if (myContent.hasComponent("Publication Date")){
        out.write("I am getting here");
        DateComponent dateComponent =     (DateComponent)myContent.getComponent("Publication Date");
        if (dateComponent != null){
             out.write(dateComponent.toString());
        } else {
            //out.write(last modified date);
        } 
   } else {
        //out.write(last modified date);
   }

But im not even getting inside the first if condition. I feel that the has goto be an easier way to simply check if a element exists, any help would be appreceated.

user1103205
  • 175
  • 2
  • 13

1 Answers1

1

You can use the [Property] tag to pull a date from a content item.

[Property context="autofill" type="content" format="DATE_TIME_SHORT" field="lastmodifieddate"]

is probably something similar to what you are looking for.

There are a lot of different options to use for both format and field to get the date you want.

format="DATE_SHORT"
format="DATE_MEDIUM"
format="DATE_LONG"
format="DATE_FULL"
format="DATE_TIME_SHORT"
format="DATE_TIME_MEDIUM"
format="DATE_TIME_LONG"
format="DATE_TIME_FULL"
format="TIME_SHORT"
format="TIME_MEDIUM"
format="TIME_LONG"
format="TIME_FULL"

lastmodified - Displays the last modified date and the last change message.
lastmodifieddate - Displays the last modified date.
creation - Displays the creation date.
creationdate - Displays the creation date.
lastmodifier - Displays the name of the user who last modified the item.
creator - Displays the name of the user who created the item.

ZeekLTK
  • 233
  • 2
  • 9