jspファイルでwcmライブラリを使用するのは初めてで、少し行き詰まっています。使用しているオーサリング テンプレートに新しい要素 (「公開日」) を作成し、「更新日」フィールドを生成するためにアトム呼び出しから参照しているカスタム jsp コンポーネントを作成しました。私がやろうとしているのは、追加した要素が存在するかどうかを確認することです.nullの場合は更新された日付フィールドを使用し、そうでない場合は「公開日」要素を使用します。
私が試してみました:
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条件に入ることさえありません。要素が存在するかどうかを簡単に確認するための簡単な方法が必要だと思います。助けがあれば幸いです。