Fw : Re: Fw : Re: Need doc about access object in a page (and use doc)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Fw : Re: Fw : Re: Need doc about access object in a page (and use doc)

PascalB
Thxs god! xwiki is a wonderfull world ... when we manage to do what we want (or we can understand javadoc) ... hum!

More seriously, thxs a lot for your help (I pulled my hair during all this week-end).
I wil probably add your nice code on this page: http://platform.xwiki.org/xwiki/bin/view/DevGuide/APIGuide#HAccessobjectsinapage

## get the document which has the object (only one here) - this is the page where I can see things in the object editor
#set( $MyDoc = $xwiki.getDocument("MySpace.MyNiceDoc"))
## get the document wich contains the class definition: this page has entries in the class editor
#set( $class = $xwiki.getClass("MySpace.MyClass"))
#foreach($prop in $class.properties) ## go through all properties
* ${prop.prettyName} : $MyDoc.display($prop.getName())
#end

and

#set($MyDoc = $xwiki.getDocument("MySpace.MyNiceDoc"))
#set($class = $xwiki.getClass("MySpace.MyClass"))
## loop over all objects
#foreach($obj in $MyDoc.getObjects("MySpace.MyClass"))
  ## empty line is intentionally to create a new paragraph

  Object number $velocityCount
  #set($discard = $MyDoc.use($obj))
  #foreach($prop in $class.properties) ## go through all properties
    * ${prop.prettyName} : $MyDoc.display($prop.getName())
  #end
#end

Pascal B.


--- En date de : Lun 9.2.15, Clemens Klein-Robbenhaar <[hidden email]> a écrit :

> De: Clemens Klein-Robbenhaar <[hidden email]>
> Objet: Re: [xwiki-users] Fw : Re: Need doc about access object in a page (and use doc)
> À: [hidden email]
> Date: Lundi 9 février 2015, 14h53
> On 02/09/2015 02:12 PM,
> Pascal BASTIEN wrote:
> > This code
> (probably false) doesn't work.
> >
> #set( $Class =
> $xwiki.getClass("MySpace.MyClass"))
> > #foreach($prop in $class.properties) ## go
> through all properties
> >  *
> ${prop.prettyName} : $doc.display($prop.getName())
> > #end
>
> It
> works for me if I do something like:
>
> {{velocity}}
> ## get the
> document which has the object (only one here) - this is the
> page where I can see things in the object editor
> #set( $adminDoc =
> $xwiki.getDocument("XWiki.Admin"))
> ## get the document wich contains the class
> definition: this page has entries in the class editor
> #set( $class =
> $xwiki.getClass("XWiki.XWikiUsers"))
> #foreach($prop in $class.properties) ## go
> through all properties
>  * ${prop.prettyName}
> : $adminDoc.display($prop.getName())
> #end
> {{/velocity}}
>
> This code should work for you 1:1 unless you
> have deleted you "Admin" user. toapply for your
> ise case you will have to adapt the name of the class and of
> the document containing the objects
>
> Note that there is a difference between:
>
>  - the document _defining_ the
> class - for users this is XWiki.XWikiUsers and you can see
> it at
>       http://localhost:8080/xwiki/bin/view/XWiki/XWikiUsers
>    and you can cnage it  in the
> class editor:
>       http://localhost:8080/xwiki/bin/edit/XWiki/XWikiUsers?editor=class
>    but this document is in itself a
> user: the object eduitor is emprty:
>      
> http://localhost:8080/xwiki/bin/edit/XWiki/XWikiUsers?editor=object
>    (not completely empty, but does
> not contain XWiki.XWikiUsers objects)
>
>  - the "admin" User document is not a
> class:
>      http://localhost:8080/xwiki/bin/edit/XWiki/Admin?editor=class
>    but has a Users oject
> attached:
>      http://localhost:8080/xwiki/bin/edit/XWiki/Admin?editor=object
>
>
> Anyway, if
> you have more than one object on a page, you will have to
> loop over them and use "$doc.use".
>
> the following works for me
> (even though it is useless in this case, as is loops over
> all users on a page, while there should be only one ...)
>
> {{velocity}}
> #set($adminDoc =
> $xwiki.getDocument("XWiki.Admin"))
> #set($class =
> $xwiki.getClass("XWiki.XWikiUsers"))
> ## loop over all objects
> #foreach($obj in
> $adminDoc.getObjects("XWiki.XWikiUsers"))
>   ## empty line is intentionally to create a
> new paragraph
>
>   Object
> number $velocityCount
>   #set($discard =
> $adminDoc.use($obj))
>   #foreach($prop in
> $class.properties) ## go through all properties
>     * ${prop.prettyName} :
> $adminDoc.display($prop.getName())
>  
> #end
> #end
>
> {{/velocity}}
>
>
> hth,
>
> clemens
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Fw : Re: Fw : Re: Need doc about access object in a page (and use doc)

jerem
Hi,

2015-02-09 15:37 GMT+01:00 Pascal BASTIEN <[hidden email]>:

> Thxs god! xwiki is a wonderfull world ... when we manage to do what we
> want (or we can understand javadoc) ... hum!
>

Note that javadoc may not be the better entry point to understand the xwiki
model, but you may find this page interesting ;)
http://platform.xwiki.org/xwiki/bin/view/DevGuide/DataModel



>
> More seriously, thxs a lot for your help (I pulled my hair during all this
> week-end).
> I wil probably add your nice code on this page:
> http://platform.xwiki.org/xwiki/bin/view/DevGuide/APIGuide#HAccessobjectsinapage
>
> ## get the document which has the object (only one here) - this is the
> page where I can see things in the object editor
> #set( $MyDoc = $xwiki.getDocument("MySpace.MyNiceDoc"))
> ## get the document wich contains the class definition: this page has
> entries in the class editor
> #set( $class = $xwiki.getClass("MySpace.MyClass"))
> #foreach($prop in $class.properties) ## go through all properties
> * ${prop.prettyName} : $MyDoc.display($prop.getName())
> #end
>
> and
>
> #set($MyDoc = $xwiki.getDocument("MySpace.MyNiceDoc"))
> #set($class = $xwiki.getClass("MySpace.MyClass"))
> ## loop over all objects
> #foreach($obj in $MyDoc.getObjects("MySpace.MyClass"))
>   ## empty line is intentionally to create a new paragraph
>
>   Object number $velocityCount
>   #set($discard = $MyDoc.use($obj))
>   #foreach($prop in $class.properties) ## go through all properties
>     * ${prop.prettyName} : $MyDoc.display($prop.getName())
>   #end
> #end
>
> Pascal B.
>
>
> --- En date de : Lun 9.2.15, Clemens Klein-Robbenhaar <
> [hidden email]> a écrit :
>
> > De: Clemens Klein-Robbenhaar <[hidden email]>
> > Objet: Re: [xwiki-users] Fw : Re: Need doc about access object in a page
> (and use doc)
> > À: [hidden email]
> > Date: Lundi 9 février 2015, 14h53
> > On 02/09/2015 02:12 PM,
> > Pascal BASTIEN wrote:
> > > This code
> > (probably false) doesn't work.
> > >
> > #set( $Class =
> > $xwiki.getClass("MySpace.MyClass"))
> > > #foreach($prop in $class.properties) ## go
> > through all properties
> > >  *
> > ${prop.prettyName} : $doc.display($prop.getName())
> > > #end
> >
> > It
> > works for me if I do something like:
> >
> > {{velocity}}
> > ## get the
> > document which has the object (only one here) - this is the
> > page where I can see things in the object editor
> > #set( $adminDoc =
> > $xwiki.getDocument("XWiki.Admin"))
> > ## get the document wich contains the class
> > definition: this page has entries in the class editor
> > #set( $class =
> > $xwiki.getClass("XWiki.XWikiUsers"))
> > #foreach($prop in $class.properties) ## go
> > through all properties
> >  * ${prop.prettyName}
> > : $adminDoc.display($prop.getName())
> > #end
> > {{/velocity}}
> >
> > This code should work for you 1:1 unless you
> > have deleted you "Admin" user. toapply for your
> > ise case you will have to adapt the name of the class and of
> > the document containing the objects
> >
> > Note that there is a difference between:
> >
> >  - the document _defining_ the
> > class - for users this is XWiki.XWikiUsers and you can see
> > it at
> >       http://localhost:8080/xwiki/bin/view/XWiki/XWikiUsers
> >    and you can cnage it  in the
> > class editor:
> >       http://localhost:8080/xwiki/bin/edit/XWiki/XWikiUsers?editor=class
> >    but this document is in itself a
> > user: the object eduitor is emprty:
> >
> > http://localhost:8080/xwiki/bin/edit/XWiki/XWikiUsers?editor=object
> >    (not completely empty, but does
> > not contain XWiki.XWikiUsers objects)
> >
> >  - the "admin" User document is not a
> > class:
> >      http://localhost:8080/xwiki/bin/edit/XWiki/Admin?editor=class
> >    but has a Users oject
> > attached:
> >      http://localhost:8080/xwiki/bin/edit/XWiki/Admin?editor=object
> >
> >
> > Anyway, if
> > you have more than one object on a page, you will have to
> > loop over them and use "$doc.use".
> >
> > the following works for me
> > (even though it is useless in this case, as is loops over
> > all users on a page, while there should be only one ...)
> >
> > {{velocity}}
> > #set($adminDoc =
> > $xwiki.getDocument("XWiki.Admin"))
> > #set($class =
> > $xwiki.getClass("XWiki.XWikiUsers"))
> > ## loop over all objects
> > #foreach($obj in
> > $adminDoc.getObjects("XWiki.XWikiUsers"))
> >   ## empty line is intentionally to create a
> > new paragraph
> >
> >   Object
> > number $velocityCount
> >   #set($discard =
> > $adminDoc.use($obj))
> >   #foreach($prop in
> > $class.properties) ## go through all properties
> >     * ${prop.prettyName} :
> > $adminDoc.display($prop.getName())
> >
> > #end
> > #end
> >
> > {{/velocity}}
> >
> >
> > hth,
> >
> > clemens
> > _______________________________________________
> > users mailing list
> > [hidden email]
> > http://lists.xwiki.org/mailman/listinfo/users
> >
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users