• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does TreeNode hold multiple values?

 
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So lets say I have an xml <tag> that has 5 values - 1, 2 ,3 , 4 , 5.

If I do something like





Will that TreeNode x value now hold all 5 of those values or just the last one?
I know that code is not correct completely but you get my meaning. Will TreeNode x hold all of those values which I will then be able to bind to a recursive tree node adaptor? Or shoudl I use something other than a TreeNode value?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, first of all it won't compile because you redeclared a local variable with two different types in the same block. And if that wasn't a problem, you don't assign anything to your TreeNode variable so you'll get a NullPointerException when you try to use it in the next line. And I don't know what this TreeNode class is, but appending a TreeNode to itself is likely to end badly. If the TreeNode class allows it, which it probably shouldn't, then you're going to have a circular reference which, when processed, is likely to produce an infinite loop.

Also I'm not sure what it means for an XML <tag> element to have 5 values. Could you display the actual XML which you're asking about?
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
edit - now that I think about it, would addChild() be referring to adding a new xml <tag> or the text node within an existing tag? Like I say, this is incomplete, but one thing at a time
edit 1- maybe I should be using TreeNodeImpl Class rather than TreeNode. I thought the TreeNode class was one of the classes i would find at JBoss but I must have ogtten that somewhere else. SO I guess what this comes down to, is that I need to figure out what class to use that will allow me to append the multiple values that should result from that iterator, which I will then be able to bind to a recursive tree node adaptor

Sorry, like I said I know the code is wrong, I just threw it together to hopefully give an idea of what I meant. It will actually be more like:



Im pretty much declaring a TreeNode value, and then for every device in my device collection, Im trying to add DeviceId to TreeNode x - that is assuming it will hold more than one value. This is from the TreeNode class documentation online:

public void addChild(TreeNode child)
Add a new child node to the end of the list.

So addChild is more accurate than append. But like I said I was just trying to get it posted in time. I guess if there is an addChild method it would suggest TreeNode will hold multiple values though right?

Oh yes and the xml:



Right now when I modify that code from above to say:



It returns
printing attempted iteration thorugh devicecollection: exampleDevice1

If you want a more detailed account of that check this out:

https://coderanch.com/t/447395/Java-General-intermediate/java/If-use-println-print-out

But suffice it to say, I finally have deviceCollection being set to that xml from above like Ive been trying to get it to for days. And now Im needing to loop through deviceColelction and pull out teh text node for each instance of the <deviceId> tag, and then add all those values to a single variable (TreeNode x), which I can then use a gettter for and use tio populate my richfaces tree
reply
    Bookmark Topic Watch Topic
  • New Topic