• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, this was so easy!

Thanks Bear Bibeault
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for tips

    In this case, do you prefer to use List as ArrayList, LinkedList, or another?
     
    Bear Bibeault
    Sheriff
    Posts: 67754
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I think that ArrayList is the most appropriate in my case, but i'm not sure.
     
    Bear Bibeault
    Sheriff
    Posts: 67754
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
    reply
      Bookmark Topic Watch Topic
    • New Topic