[xwiki-users] Fw : Re: Need doc about access object in a page (and use doc)

2015-02-09 Thread Pascal BASTIEN


--- En date de : Lun 9.2.15, Clemens Klein-Robbenhaar 
c.robbenh...@espresto.com a écrit :

 De: Clemens Klein-Robbenhaar c.robbenh...@espresto.com
 Objet: Re: [xwiki-users] Need doc about access object in a page (and use doc)
 À: users@xwiki.org
 Date: Lundi 9 février 2015, 13h29
 On 02/09/2015 10:15 AM,
 Pascal BASTIEN wrote:
  Hello,
  I read/apply this doc with succcess:
  http://platform.xwiki.org/xwiki/bin/view/DevGuide/APIGuide#HAccessobjectsinapage
  
  With this code I can
 display all objects ATTACHED to THIS page.
  ***
 
 #set($class = $obj.xWikiClass) ## access the class object
 representing SomeSpace.SomeClass
 
 #foreach($prop in $class.properties) ## go through all
 properties
  ...
 
 ***
  but if I attached some
 class to another page, how can I list properties?
 
 the $xwiki object has a method
 to access the class if you know the name
 
  #set( $someClass =
 $xwiki.getClass(SomeSpace.SomeClass))
 
 http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/com/xpn/xwiki/api/XWiki.html#getClass%28java.lang.String%29

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

 
  Another question:
  I have a page with 3 same Class, how to
 list them (like ?editor=class did)?
 
  you can get a list of of objects of a certain
 class via
 $doc.getObjects(SomeSpace.SomeClass)
 
  
 http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/com/xpn/xwiki/api/Document.html#getObjects%28java.lang.String%29

$doc.getObjects(SomeSpace.SomeClass)

I failed to :-(

The thing I don't understand is, my values are stored in a doc with attached 
class. I need theses value from another doc but all method have Class name 
parameter ... Class name contain only field (properties) name?


(Hope I will understand how find answer in javadoc to avoid disturbed nice 
people of user list)

Thxs


 
  An example:
 
 MySpaceMyClass contain this Class properties:
  - My Field ID (IdField: String)
  - My Lib Field (LibField: String)
  I create MySpace.MyNiceDoc and add my
 previous Class MySpace/MyNiceDoc?editor=object
  and contain:
  Objets
 de type MySpace.MyClass (2)
  * MyClass
 0
   - My Field ID
   - My Lib Field
 
 *MyClass 1:
   - My Field ID
   - My Lib Field
  
  With it I like to fill a select list from
 this doc (but from another doc to).
  How
 can I proceed? because on MySpace.MyNiceDoc I can only
 display one/First Lib values with this code:
  {{velocity}}
  ##
 Retrieve the first object (index [0]) among all objects
 attached to this page and of a certain class 
  #set($obj =
 $doc.getObject('MySpace.MyClass'))
  #set($class = $obj.xWikiClass) ## access
 the class object representing SomeSpace.SomeClass
  #foreach($prop in $class.properties) ## go
 through all properties
   *
 ${prop.prettyName} : $doc.display($prop.getName())
  #end
  {{/velocity}}
  I guess i need a loop but which one?
  
  And the big question
 (who I think it will interest everyone), how can I use
 documentation
  ( http://platform.xwiki.org/xwiki/bin/view/SRD/Navigation?xpage=embed
 and or 
 http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org/xwiki/platform/xwiki-platform-oldcore/6.4/xwiki-platform-oldcore-6.4-javadoc.jar/!/index.html
 )
  to guess xWikiClass (or my loop)
 by example?
  
  A
 doc/example to use documentation will be welcome. :-)
  
  thxs for any
 help.
  
  Pascal
 B
 
 ___
  users mailing list
  users@xwiki.org
  http://lists.xwiki.org/mailman/listinfo/users
  
 
 
 
 mit freundlichen Grüßen
 Clemens Klein-Robbenhaar
 
 -- 
 Clemens Klein-Robbenhaar
 Software Development
 EsPresto
 AG
 Breite Str. 30-31
 10178
 Berlin/Germany
 Tel: +49.(0)30.90 226.763
 Fax: +49.(0)30.90 226.760
 robbenh...@espresto.com
 
 HRB 77554 B -
 Berlin-Charlottenburg
 Vorstand: Maya
 Biersack, Peter Biersack
 Vorsitzender des
 Aufsichtsrats: Dipl.-Wirtsch.-Ing. Winfried Weber
 Zertifiziert nach ISO 9001:2008
 ___
 users mailing list
 users@xwiki.org
 http://lists.xwiki.org/mailman/listinfo/users
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] Fw : Re: Need doc about access object in a page (and use doc)

2015-02-09 Thread Clemens Klein-Robbenhaar
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
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users