• Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom tags: how to get the number of "child" tags  RSS feed

 
Tiago Hillebrandt
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like to get the number of child tags into ancestor class.

Example:



I know that isn't the best example, but the idea is get the number of math:var tags (3 in the example) and their values into bhaskara tag.

So, how to i can make to get this values? I think that's possible through doAfterBody() in bhaskara tag, but i don't have idea how to implement this.

Thanks for all.

Regards,

Tiago
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66157
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The child tags can call a method in the parent tag to "register" themselves with the parent.
 
Tiago Hillebrandt
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, this was so easy!

Thanks Bear Bibeault
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66157
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Done it a few times myself!

Have you found the API that lets the children find their parent?
 
Tiago Hillebrandt
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using findAncestorWithClass() to get data from parent class.

And to pass data from children to parent, i created a Vector of objects at parent class, how in the follow example.





Is this a "correct" mode?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66157
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the way I usually do it, with the following differences:
  • List is preferred over Vector.
  • I'd not expose the List to the child classes, but have an addChild() method on the parent that adds the child to the list which is kept private to the parent.
  •  
    Tiago Hillebrandt
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for tips

    In this case, do you prefer to use List as ArrayList, LinkedList, or another?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 66157
    146
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Which do you think is most appropriate in this case?
     
    Tiago Hillebrandt
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I think that ArrayList is the most appropriate in my case, but i'm not sure.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 66157
    146
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    OK, let's look at it this way, is there any reason that ArrayList would not be a good choice? What advantages over ArrayList would any of the other implementations of List have?
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!