2012-12-17 32 views
0

即時通訊使用wcm庫在jsp文件中,我有點卡住了。我在創作模板im中創建了一個新元素(「發佈日期」),並使用了我從原子調用引用的自定義jsp組件來生成「更新日期」字段。我試圖做的只是檢查,看看我添加的元素是否爲空,如果它然後使用更新的日期字段,如果它不是然後使用「發佈日期」元素。簡單的jsp文件使用wcm庫

我曾嘗試:

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); 
    } 

,但林甚至沒有第一,如果條件內進入。我覺得這已經成爲一種簡單的方法來簡單地檢查一個元素是否存在,任何幫助都會被解密。

回答

1

您可以使用[Property]標籤從內容項中提取日期。

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

可能是類似於你在找什麼東西。

有很多不同的選項可用於格式和字段來獲得你想要的日期。

格式= 「DATE_SHORT」
格式= 「DATE_MEDIUM」
格式= 「DATE_LONG」
格式= 「DATE_FULL」
格式= 「DATE_TIME_SHORT」
格式= 「DATE_TIME_MEDIUM」
格式=「DATE_TIME_LONG 「
格式=」 DATE_TIME_FULL」
格式= 「TIME_SHORT」
格式= 「TIME_MEDIUM」
格式= 「TIME_LONG」
格式= 「TIME_FULL」

lastmodified - 顯示上次修改日期和上次更改消息。
lastmodifieddate - 顯示上次修改日期。
創建 - 顯示創建日期。
creationdate - 顯示創建日期。
lastmodifier - 顯示上次修改項目的用戶的名稱。
creator - 顯示創建該項目的用戶的名稱。