Thank you guys,
Actually I didn't understand any of your suggestions, I have added two
method in "*MyObject*" java class, that are:
//this to create an XClass and bind it with a sheet
crateXClass(SpaceReference spaceRefe, XWikiContext context){
try{
String className = "Instance";
String sheet = className + "Sheet";
DocumentReference docRef = new DocumentReference(className,
spaceRefe);
XWiki wiki = context.getWiki();
XWikiDocument doc = wiki.getDocument(docRef, context);
BaseClass xclass = new BaseClass();
xclass.addTextField("id", "id", 30);
xclass.addTextField("name", "name", 30);
xclass.addTextAreaField("description", "description", 40,
5);
xclass.addTextField("type", "type", 30);
xclass.addTextAreaField("incoming", "incoming", 40, 5);
xclass.addTextAreaField("outgoing", "outgoing", 40, 5);
doc.setXClass(xclass);
BaseObject obj =
wiki.getObjectFromRequest("XWiki.ClassSheetBinding", context);
obj.set("sheet", sheet, context);
doc.addXObject(obj);
docRef = new DocumentReference(sheet, spaceRefe);
doc = wiki.getDocument(docRef, context);
String content = "{{velocity}}\n";
content = content + " #set($class = $doc.getObject('";
content = content + spaceRefe.getName() + "." + className;
content = content + "').xWikiClass)\n";
content = content + " #foreach($prop in $class.properties)\n";
content = content + " === $prop.prettyName ===\n";
content = content + " $doc.display($prop.getName())\n";
content = content + " #end\n";
content = content + "{{/velocity}}\n";
doc.setContent(content);
doc.setTitle("#if($doc.fullName == '" + spaceRefe.getName() +
"." + sheet + "')" + sheet
+ "#{else}$doc.title#end");
wiki.saveDocument(doc, context);
} catch (XWikiException e) {
e.printStackTrace();
}
-----------------------------------------------------------------------
public BaseObject createXObject(String spName, XWikiContext xcontext) {
XWiki wiki = xcontext.getWiki();
BaseObject obj;
try {
obj = wiki.getObjectFromRequest(spName + ".Instance", xcontext);
obj.set("id",this.id, xcontext);
obj.set("name",this.iName, xcontext);
obj.set("description",this.description, xcontext);
obj.set("type",this.eClass, xcontext);
String in = "";
String out = "";
for (int k = 0; k < this.incoming.size(); k++) {
in = in + "* [[" + this.incoming.get(k) + "]] \n";
}
for (int k = 0; k < outgoing.size(); k++) {
out = out + "* [[" + this.outgoing.get(k) + "]] \n";
}
obj.set("incoming",in,xcontext);
obj.set("outgoing",out,xcontext);
return obj;
}catch (XWikiException e) {
e.printStackTrace();
}
return null;
}
--------------------------------------------------------------------------------
But if I update the wiki (through specified button), I get all my new pages
without any content, plus one new page with this title:"*#if($doc.fullName
== 'BSS Rome.InstanceSheet')InstanceSheet#{else}$doc.title#end" *that
should be the Sheet created through the createXClass() method, that display
a Velocity error saying that :
"
org.xwiki.rendering.macro.MacroExecutionException: The execution of
the [velocity] script macro is not allowed. Check the rights of its
last author or the parameters if it's rendered from another script.
at
org.xwiki.rendering.macro.script.AbstractScriptMacro.execute(AbstractScriptMacro.java:178)
at
org.xwiki.rendering.macro.script.AbstractScriptMacro.execute(AbstractScriptMacro.java:58)
at
org.xwiki.rendering.internal.transformation.macro.MacroTransformation.transform(MacroTransformation.java:269)
at
org.xwiki.rendering.internal.transformation.DefaultRenderingContext.transformInContext(DefaultRenderingContext.java:183)
at
org.xwiki.rendering.internal.transformation.DefaultTransformationManager.performTransformations(DefaultTransformationManager.java:95)
at
org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:253)
at
org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:126)
at
org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:56)
at
org.xwiki.display.internal.DefaultDocumentDisplayer.display(DefaultDocumentDisplayer.java:96)
at
org.xwiki.display.internal.DefaultDocumentDisplayer.display(DefaultDocumentDisplayer.java:39)
at
org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:113)
at
org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:50)
at
org.xwiki.display.internal.ConfiguredDocumentDisplayer.display(ConfiguredDocumentDisplayer.java:68)
at
org.xwiki.display.internal.ConfiguredDocumentDisplayer.display(ConfiguredDocumentDisplayer.java:42)
at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1164)
at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1127)
at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1179)
at com.xpn.xwiki.api.Document.getRenderedContent(Document.java:692)
at sun.reflect.GeneratedMethodAccessor517.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at
org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:395)
at
org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:384)
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:173)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:280)
at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:567)
at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:71)
at
org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:142)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
at
org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:106)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
at org.xwiki.velocity.introspection.TryCatchDirective.render(TryCatchDirective.java:72)
at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
at
org.xwiki.velocity.internal.DefaultVelocityEngine.evaluateInternal(DefaultVelocityEngine.java:256)
at
org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:222)
at
org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:198)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.evaluateContent(InternalTemplateManager.java:725)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.render(InternalTemplateManager.java:626)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.renderFromSkin(InternalTemplateManager.java:604)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.renderFromSkin(InternalTemplateManager.java:570)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.render(InternalTemplateManager.java:556)
at
com.xpn.xwiki.internal.template.DefaultTemplateManager.render(DefaultTemplateManager.java:65)
at com.xpn.xwiki.XWiki.evaluateTemplate(XWiki.java:1876)
at com.xpn.xwiki.XWiki.parseTemplate(XWiki.java:1854)
at com.xpn.xwiki.api.XWiki.parseTemplate(XWiki.java:820)
at sun.reflect.GeneratedMethodAccessor181.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at
org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:395)
at
org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:384)
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:173)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:280)
at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:369)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
at
org.apache.velocity.runtime.directive.VelocimacroProxy.render(VelocimacroProxy.java:216)
at org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:311)
at org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:230)
at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
at
org.xwiki.velocity.internal.DefaultVelocityEngine.evaluateInternal(DefaultVelocityEngine.java:256)
at
org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:222)
at
org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:198)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.evaluateContent(InternalTemplateManager.java:725)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.render(InternalTemplateManager.java:626)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.renderFromSkin(InternalTemplateManager.java:604)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.renderFromSkin(InternalTemplateManager.java:570)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.render(InternalTemplateManager.java:556)
at
com.xpn.xwiki.internal.template.DefaultTemplateManager.render(DefaultTemplateManager.java:65)
at com.xpn.xwiki.XWiki.evaluateTemplate(XWiki.java:1876)
at com.xpn.xwiki.XWiki.parseTemplate(XWiki.java:1854)
at com.xpn.xwiki.api.XWiki.parseTemplate(XWiki.java:820)
at sun.reflect.GeneratedMethodAccessor181.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at
org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:395)
at
org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:384)
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:173)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:280)
at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:369)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
at
org.apache.velocity.runtime.directive.VelocimacroProxy.render(VelocimacroProxy.java:216)
at org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:311)
at org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:230)
at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:87)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
at
org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:106)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
at
org.xwiki.velocity.internal.DefaultVelocityEngine.evaluateInternal(DefaultVelocityEngine.java:256)
at
org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:222)
at
org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:198)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.evaluateContent(InternalTemplateManager.java:725)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.render(InternalTemplateManager.java:626)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.renderFromSkin(InternalTemplateManager.java:604)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.renderFromSkin(InternalTemplateManager.java:570)
at
com.xpn.xwiki.internal.template.InternalTemplateManager.render(InternalTemplateManager.java:556)
at
com.xpn.xwiki.internal.template.DefaultTemplateManager.render(DefaultTemplateManager.java:65)
at com.xpn.xwiki.XWiki.evaluateTemplate(XWiki.java:1876)
at com.xpn.xwiki.web.Utils.parseTemplate(Utils.java:180)
at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:431)
at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:184)
at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)
at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
at com.xpn.xwiki.web.ActionFilter.doFilter(ActionFilter.java:115)
at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.xwiki.wysiwyg.server.filter.ConversionFilter.doFilter(ConversionFilter.java:127)
at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at
org.xwiki.container.servlet.filters.internal.SetHTTPHeaderFilter.doFilter(SetHTTPHeaderFilter.java:63)
at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at com.xpn.xwiki.plugin.webdav.XWikiDavFilter.doFilter(XWikiDavFilter.java:66)
at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at
org.xwiki.container.servlet.filters.internal.SavedRequestRestorerFilter.doFilter(SavedRequestRestorerFilter.java:208)
at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at
org.xwiki.container.servlet.filters.internal.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:111)
at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.xwiki.resource.servlet.RoutingFilter.doFilter(RoutingFilter.java:137)
at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at
org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)"
Sorry for the long post guys, but this is my Master Thesis project and
I am really tired because everytime that I think to be near to the end
something unknown arise adding complexity.
Thank you,
Giordano.
2016-01-19 11:54 GMT+01:00 Thomas Mortagne <thomas.mortagne(a)xwiki.com>om>:
On Tue, Jan 19, 2016 at 11:31 AM, vincent(a)massol.net
<vincent(a)massol.net>
wrote:
On 19 Jan 2016 at 11:24:46, Thomas Mortagne (thomas.mortagne(a)xwiki.com
(mailto:thomas.mortagne@xwiki.com)) wrote:
If this class is supposed to be available in the
wiki even if not yet
used in an object the simplest is usually to do like most standard
classes generated from java and register a component extending
com.xpn.xwiki.internal.mandatory.AbstractMandatoryDocumentInitializer.
You can find various examples in oldcore.
Yes conceptually speaking, the idea is to write an EventListener
component that
listens to the ApplicationReadyEvent event and then in the
onEvent() method, create your xclass and perform all the operations you
need.
As Thomas mentioned, you could also extend
AbstractMandatoryDocumentInitializer
although this is not a public API and
it may be removed or modified in the future. Note that
MandatoryDocumentInitializer is a public API.
Right, I actually forgot it was internal (yes I know I wrote it and I
just copy/pasted the package in the mail :)). I think we should make
it public since it's very useful for extensions and we are using it a
lot.
Thanks
-Vincent
> On Tue, Jan 19, 2016 at 11:18 AM, Giordano NinonĂ
> wrote:
> > Hi users,
> >
> > I am wondering on how to create an XClass from java, and bind it to a
> > class-sheet to be used to represent several objects as XWiki pages.
How
can
> > I achieve that in a way that allow me to
incrementaly update the
object
>
every time a modification is performed?
>
> Thanks for your help,
> Giordano.
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
--
Thomas Mortagne
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users