Hi devs,
I'm working on a sheet management module (see
https://github.com/xwiki/xwiki-platform/compare/feature-sheets ) and I
have an issue. My component returns the list of sheets "registered"
for a document or a class. The component methods take document
references as input. The consequence is that my component always
"queries" the saved document (taken from the database/cache). I have
modified the edit.vm template to check if there is a sheet available
for the current document. It works great with one exception: when you
create a document (e.g. when you create a blog post).
The problem is this: although the information required to detect the
sheet is present on the current/context document (e.g. it has an
object of type BlogPostClass) my component fails to access this
information because the document wasn't saved, it doesn't even exist.
The reason I used document references on my component interface is
obvious: I didn't want to depend on the core (at least not the
interface, because the implementation does right now). The solution to
keep the current component interface is to explicitly specify the
sheet on the edit URL (only) for the create form. For instance,
replace:
/edit/Blog/MyNewBlogPost?template=Blog.BlogPostTemplate
with:
/edit/Blog/MyNewBlogPost?template=Blog.BlogPostTemplate&sheet=Blog.BlogPostSheet
but I think it's a bit too much to ask from the application developers.
Another solution, suggested by Thomas Mortagne, is to:
* change the component interface to use DocumentModelBridge (which is
implemented by XWikiDocument) instead of DocumentReference (=> keep
the interface independent of old core)
* change the script service to use api.Document instead of
DocumentReference, and to extract the XWikiDocument from it through
reflection, to avoid programming rights issues.
It's not a clean solution but it is better from the application
developers' point of view.
WDYT? Any alternatives?
Thanks,
Marius