【问题标题】:simple jsp file using wcm library使用 wcm 库的简单 jsp 文件
【发布时间】:2012-12-17 16:16:46
【问题描述】:

我是在 jsp 文件中使用 wcm 库的新手,我有点卡住了。我在我使用的创作模板中创建了一个新元素(“发布日期”)和一个自定义 jsp 组件,我从原子调用中引用该组件以生成“更新日期”字段。我要做的只是检查我添加的元素是否不为空,如果是,则使用更新的日期字段,如果不是,则使用“发布日期”元素。

我试过了:

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

但我什至没有进入第一个 if 条件。我觉得这必须是一种更简单的方法来简单地检查一个元素是否存在,任何帮助都会受到赞赏。

【问题讨论】:

    标签: jsp wcm


    【解决方案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 - 显示创建项目的用户的名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多