get prop from a class...

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

get prop from a class...

Bubulina
Hello

1. i create a class and add n properties. besides the properties added i have this code:
#set( $class = $doc.name.substring(0,$doc.name.indexOf("Class")))
#set($defaultparent = "XWiki.${class}Class")
#set($defaultweb = "Test")
#includeForm("XWiki.ClassSheet")

2. i create doc where i include the class: #includeForm("$space.TestClass") because I wanna get those prop:

#includeForm("$space.TestClass")
#set($object = $doc.getObject("$space.TestCkass").xWikiClass)
object - $object
 #foreach($prop in $object.properties)
 -- ${prop.prettyName} </dt>
   : $doc.display($prop.getName())</dd>
#end

and my $object shows nothing. probably my favourite question....what am i missing here?
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: get prop from a class...

Sergiu Dumitriu-2
On 12/16/2009 02:08 PM, Bubulina wrote:

>
> Hello
>
> 1. i create a class and add n properties. besides the properties added i
> have this code:
> #set( $class = $doc.name.substring(0,$doc.name.indexOf("Class")))
> #set($defaultparent = "XWiki.${class}Class")
> #set($defaultweb = "Test")
> #includeForm("XWiki.ClassSheet")
>
> 2. i create doc where i include the class: #includeForm("$space.TestClass")
> because I wanna get those prop:
>
> #includeForm("$space.TestClass")
> #set($object = $doc.getObject("$space.TestCkass").xWikiClass)

$space.TestCkass is wrong, not just because it's Ckass instead of Class,
but because the dot is part of the Velocity syntax. So $space.TestClass
is not expanded as ($space).TestClass, but as $space.get("TestClass"),
which is the value of the "TestClass" property of that object. Try
${space}.TestClass. Even better, you know where the class is, you could
just use 'Test.TestClass'.

> object - $object
>   #foreach($prop in $object.properties)
>   -- ${prop.prettyName}</dt>
>     : $doc.display($prop.getName())</dd>
> #end
>
> and my $object shows nothing. probably my favourite question....what am i
> missing here?
> Thanks

--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: get prop from a class...

Bubulina
Hello Sergiu,

it was a typo when i wrote by hand the code here.
I include the TestClass, that has the properties, but the line that should give me the object from it:
#set($object = $document.getObject("spaceName.TestClass").xWikiClass)
returns nothing...

Sergiu Dumitriu-2 wrote
On 12/16/2009 02:08 PM, Bubulina wrote:
>
> Hello
>
> 1. i create a class and add n properties. besides the properties added i
> have this code:
> #set( $class = $doc.name.substring(0,$doc.name.indexOf("Class")))
> #set($defaultparent = "XWiki.${class}Class")
> #set($defaultweb = "Test")
> #includeForm("XWiki.ClassSheet")
>
> 2. i create doc where i include the class: #includeForm("$space.TestClass")
> because I wanna get those prop:
>
> #includeForm("$space.TestClass")
> #set($object = $doc.getObject("$space.TestCkass").xWikiClass)

$space.TestCkass is wrong, not just because it's Ckass instead of Class,
but because the dot is part of the Velocity syntax. So $space.TestClass
is not expanded as ($space).TestClass, but as $space.get("TestClass"),
which is the value of the "TestClass" property of that object. Try
${space}.TestClass. Even better, you know where the class is, you could
just use 'Test.TestClass'.

> object - $object
>   #foreach($prop in $object.properties)
>   -- ${prop.prettyName}</dt>
>     : $doc.display($prop.getName())</dd>
> #end
>
> and my $object shows nothing. probably my favourite question....what am i
> missing here?
> Thanks

--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: get prop from a class...

Josh-13
Hello,

Bubulina wrote:
> Hello Sergiu,
>
> it was a typo when i wrote by hand the code here.
> I include the TestClass, that has the properties, but the line that should
> give me the object from it:
> #set($object = $document.getObject("spaceName.TestClass").xWikiClass)
> returns nothing...
>

You don't need the .xWikiClass. Try just:
#set($object = $document.getObject("spaceName.TestClass")

-Joshua

>
> Sergiu Dumitriu-2 wrote:
>> On 12/16/2009 02:08 PM, Bubulina wrote:
>>> Hello
>>>
>>> 1. i create a class and add n properties. besides the properties added i
>>> have this code:
>>> #set( $class = $doc.name.substring(0,$doc.name.indexOf("Class")))
>>> #set($defaultparent = "XWiki.${class}Class")
>>> #set($defaultweb = "Test")
>>> #includeForm("XWiki.ClassSheet")
>>>
>>> 2. i create doc where i include the class:
>>> #includeForm("$space.TestClass")
>>> because I wanna get those prop:
>>>
>>> #includeForm("$space.TestClass")
>>> #set($object = $doc.getObject("$space.TestCkass").xWikiClass)
>> $space.TestCkass is wrong, not just because it's Ckass instead of Class,
>> but because the dot is part of the Velocity syntax. So $space.TestClass
>> is not expanded as ($space).TestClass, but as $space.get("TestClass"),
>> which is the value of the "TestClass" property of that object. Try
>> ${space}.TestClass. Even better, you know where the class is, you could
>> just use 'Test.TestClass'.
>>
>>> object - $object
>>>   #foreach($prop in $object.properties)
>>>   -- ${prop.prettyName}</dt>
>>>     : $doc.display($prop.getName())</dd>
>>> #end
>>>
>>> and my $object shows nothing. probably my favourite question....what am i
>>> missing here?
>>> Thanks
>> --
>> Sergiu Dumitriu
>> http://purl.org/net/sergiu/
>> _______________________________________________
>> 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: get prop from a class...

lucaa


On 12/16/2009 03:58 PM, Josh wrote:

> Hello,
>
> Bubulina wrote:
>> Hello Sergiu,
>>
>> it was a typo when i wrote by hand the code here.
>> I include the TestClass, that has the properties, but the line that should
>> give me the object from it:
>> #set($object = $document.getObject("spaceName.TestClass").xWikiClass)
>> returns nothing...
>>
>
> You don't need the .xWikiClass. Try just:
> #set($object = $document.getObject("spaceName.TestClass")


Unless you set the $document variable yourself (which you don't do in the
initial snippet I see), you should use $doc for that which is the name of the
variable holding the current document by default in the velocity context:

#set($object = $doc.getObject("spaceName.TestClass")

if it _still_ does not work, check if there is an object in there indeed by doing
Edit -> Objects in the menu and looking for an object of class spaceName.TestClass .

Have fun!
Anca

>
> -Joshua
>
>>
>> Sergiu Dumitriu-2 wrote:
>>> On 12/16/2009 02:08 PM, Bubulina wrote:
>>>> Hello
>>>>
>>>> 1. i create a class and add n properties. besides the properties added i
>>>> have this code:
>>>> #set( $class = $doc.name.substring(0,$doc.name.indexOf("Class")))
>>>> #set($defaultparent = "XWiki.${class}Class")
>>>> #set($defaultweb = "Test")
>>>> #includeForm("XWiki.ClassSheet")
>>>>
>>>> 2. i create doc where i include the class:
>>>> #includeForm("$space.TestClass")
>>>> because I wanna get those prop:
>>>>
>>>> #includeForm("$space.TestClass")
>>>> #set($object = $doc.getObject("$space.TestCkass").xWikiClass)
>>> $space.TestCkass is wrong, not just because it's Ckass instead of Class,
>>> but because the dot is part of the Velocity syntax. So $space.TestClass
>>> is not expanded as ($space).TestClass, but as $space.get("TestClass"),
>>> which is the value of the "TestClass" property of that object. Try
>>> ${space}.TestClass. Even better, you know where the class is, you could
>>> just use 'Test.TestClass'.
>>>
>>>> object - $object
>>>>    #foreach($prop in $object.properties)
>>>>    -- ${prop.prettyName}</dt>
>>>>      : $doc.display($prop.getName())</dd>
>>>> #end
>>>>
>>>> and my $object shows nothing. probably my favourite question....what am i
>>>> missing here?
>>>> Thanks
>>> --
>>> Sergiu Dumitriu
>>> http://purl.org/net/sergiu/
>>> _______________________________________________
>>> 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
Reply | Threaded
Open this post in threaded view
|

Re: get prop from a class...

Bubulina
...ah! you were right Anca, i forgot to add the object from that class. Danke

lucaa wrote

On 12/16/2009 03:58 PM, Josh wrote:
> Hello,
>
> Bubulina wrote:
>> Hello Sergiu,
>>
>> it was a typo when i wrote by hand the code here.
>> I include the TestClass, that has the properties, but the line that should
>> give me the object from it:
>> #set($object = $document.getObject("spaceName.TestClass").xWikiClass)
>> returns nothing...
>>
>
> You don't need the .xWikiClass. Try just:
> #set($object = $document.getObject("spaceName.TestClass")


Unless you set the $document variable yourself (which you don't do in the
initial snippet I see), you should use $doc for that which is the name of the
variable holding the current document by default in the velocity context:

#set($object = $doc.getObject("spaceName.TestClass")

if it _still_ does not work, check if there is an object in there indeed by doing
Edit -> Objects in the menu and looking for an object of class spaceName.TestClass .

Have fun!
Anca

>
> -Joshua
>
>>
>> Sergiu Dumitriu-2 wrote:
>>> On 12/16/2009 02:08 PM, Bubulina wrote:
>>>> Hello
>>>>
>>>> 1. i create a class and add n properties. besides the properties added i
>>>> have this code:
>>>> #set( $class = $doc.name.substring(0,$doc.name.indexOf("Class")))
>>>> #set($defaultparent = "XWiki.${class}Class")
>>>> #set($defaultweb = "Test")
>>>> #includeForm("XWiki.ClassSheet")
>>>>
>>>> 2. i create doc where i include the class:
>>>> #includeForm("$space.TestClass")
>>>> because I wanna get those prop:
>>>>
>>>> #includeForm("$space.TestClass")
>>>> #set($object = $doc.getObject("$space.TestCkass").xWikiClass)
>>> $space.TestCkass is wrong, not just because it's Ckass instead of Class,
>>> but because the dot is part of the Velocity syntax. So $space.TestClass
>>> is not expanded as ($space).TestClass, but as $space.get("TestClass"),
>>> which is the value of the "TestClass" property of that object. Try
>>> ${space}.TestClass. Even better, you know where the class is, you could
>>> just use 'Test.TestClass'.
>>>
>>>> object - $object
>>>>    #foreach($prop in $object.properties)
>>>>    -- ${prop.prettyName}</dt>
>>>>      : $doc.display($prop.getName())</dd>
>>>> #end
>>>>
>>>> and my $object shows nothing. probably my favourite question....what am i
>>>> missing here?
>>>> Thanks
>>> --
>>> Sergiu Dumitriu
>>> http://purl.org/net/sergiu/
>>> _______________________________________________
>>> 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
_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users