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.

4

1 回答 1

1

您可以使用 [Property] 标签从内容项中提取日期。

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

可能与您正在寻找的东西相似。

有很多不同的选项可用于格式和字段来获取您想要的日期。

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"
格式="TIME_LONG"
格式="TIME_FULL"

lastmodified - 显示最后修改日期和最后更改消息。
lastmodifieddate - 显示最后修改日期。
创建 - 显示创建日期。
creationdate - 显示创建日期。
lastmodifier - 显示上次修改项目的用户的名称。
creator - 显示创建项目的用户的名称。

于 2013-08-28T20:30:14.073 回答