While implementing the solution suggested in this thread I have come across two problems:
-
The fields associated with an Object aren’t displayed until I save and then edit the document for a second time. I presume this is because the Object isn’t present until after save, or I’m calling $doc.getObject(‘Content Manager.Code.Content Manager Reduced Class’).xWikiClass before the event listener actually adds the object.
-
Server side validation redirects to preview of page instead of back to edit when validation returns False.
I would be extremely grateful if anyone can help address these two issues.
This is what I’ve done to allow display (during edit) of 3 input fields attached to the XObject inserted by an event listener on document create:
Firstly, and for testing purposes, I’ve added the following two lines to “editwysiwyg.vm”. I’ll probably move these to a better location when I get everything working.
#set($mydoc = $xwiki.getDocument("Content Manager.Code.Form and Validation"))
$mydoc.getRenderedContent()
Where “Content Manager.Code.Form and Validation” contains:
<div class="xform">
## Iterate over the properties of the Content Manager Reduced Class
#set($discard = $doc.use('Content Manager.Code.Content Manager Reduced Class'))
#set($class = $doc.getObject('Content Manager.Code.Content Manager Reduced Class').xWikiClass)
#foreach($prop in $class.properties)
<b>$prop.prettyName</b>
$doc.display($prop.getName())
#end
</div>
## Invoke validation
<input type="hidden" name="xvalidate" value="1" />
## Set the Groovy script which will be used for validation
<input type="hidden" name="xvalidation" value="Content Manager.Code.Content Manager GroovyValidation" />
#if(($xcontext.validationStatus.errors&&$xcontext.validationStatus.errors.size()>0)||($xcontext.validationStatus.exceptions&&$xcontext.validationStatus.exceptions.size()>0))
<div class="validation-errors" style="border: 1px solid grey; padding: 10px;">
This is a recap of all errors in this page (change the form to show errors only at the top or only next to the fields):
#foreach($error in $xcontext.validationStatus.errors)
<font color="red">$xwiki.parseMessage($error)</font><br />
#end
#foreach($exp in $xcontext.validationStatus.exceptions)
<font color="red">$exp</font><br />
#end
</div>
#end
Note that when placed in a sheet this code works fine, so I’m assuming my problems have something to do with the fact I’m calling it from a template file.