【发布时间】: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 条件。我觉得这必须是一种更简单的方法来简单地检查一个元素是否存在,任何帮助都会受到赞赏。
【问题讨论】: