When creating a new document, the author is prompted for:
* Name (stored as @hippo:name property)
* URL name (JCR node name of the document) - optional; usually derived from lowercase of the Name, with dashes instead of spaces & probably URL encoding also
* document type (which type of document)
In the document bean, I would like to return the authored "Name" of the document so I don't have to repeat it as a field inside the custom document. Is there a recommended approach to re-using the property?
Example:
/content/documents/my-site/content/my-doc
@hippo:name = "My Cool Title"
\my-doc
@hippo:availability
\my-doc
@hippo:availability = "preview"
\my-doc
@hippo:availablity = "live"
@myns:str1 = "A"
@myns:str2 = "B"
@myns:long = 123
public class MyDocument extends HippoDocument {
public String getStr1() { return getProperty("myns:str1"); }
public String getStr2() { return getProperty("myns:str2"); }
public String getLong() { return getProperty("myns:long"); }
public String getMyTitle() {
return getProperty("hippo:name"); // <= null/"" because the live node doesn't have this property
return getProperty("../hippo:name"); // <= null/""; looking for shortcut relative path that worked
return getParentBean().getProperty("hippo:name"); // <= "Content", the @hippo:name property of the node ABOVE the document
try {
return getNode().getParent().getProperty("hippo:name").getString(); // <= returns desired "My Cool Title"
} catch (RepositoryException re) { return re.getMessage(); }
}
}
Obviously, dropping to JCR API is undesired because of exceptions, but it was the only way I found to obtain the property I was looking for without duplicating it inside another field of the custom document.
I _happen_ to be rendering through Freemarker templates, but believe that has nothing to do with it. Calling document.getName(), document.getDisplayName() all return the wrong thing (but I don't understand the difference in them). Calling document.getPath() returns the path to the live node (/content/documents/my-site/content/my-doc/my-doc).
Also, I am on Hippo v11.1, but I don't believe that is important to the question.