Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes writing java code that will take data from certian xml <elements> and convert into tree nodes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "writing java code that will take data from certian xml <elements> and convert into tree nodes" Watch "writing java code that will take data from certian xml <elements> and convert into tree nodes" New topic
Author

writing java code that will take data from certian xml <elements> and convert into tree nodes

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Im unsure where to begin to even do this. I had hoped richfaces would have a nice feature for its tree that would do this for me, but it is looking like I will need to write the java code to do so completely on my own. Which is bad since I can MAYBE be classified as an intermediate java person. Maybe lol. So here is what the xml looks like.



I need the tree nodes to be populated using the data from <name>, <device>, and <channel>, in that order, to make a tree that does this:



I have looked at a lot of richfaces tree tutorials but havent had much luck. They mostly focus on the .xhtml pages rather than the actual java code. I did find some java code that takes data from a .properties file and converts it into a data stream, and uses that data stream to populate the tree. I was able to get that working, but it is not feasible for me to use .properties files to hold all of the data, which will be constantly changing.

So anyone know where I should begin with this? Or what I might do a search for that will help me figure it out. Ive been having a heck of a time having any luck. I wish I even knew where to begin, because I realize not many people are going to want to tackle somethign this complicated, so any tips at all will help me. I'm willing to do the work, but I have so little experience with this type of thing I am really constrained.


True wisdom is in knowing you know nothing - Socrates
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Moved to the XML forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

edited out - better handled in a PM I believe
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483


Well, hopefully someone in the java forum will see this before it falls to the edge of oblivion

I think I may have found an answer to this, but would like someone to confirm it. I beleie this site tells me what I need to do:
http://www.devx.com/getHelpOn/Article/11874/0/page/1
But I would like someone to confirm it because
1 - it seems to good to be true
and
2 - a lot of those concepts are new to me so I can easily just be misinterpreting
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Let me summarize some (alleged) facts which I have extracted from the original post:

1. You need to do this processing in the "richfaces" context. Which I googled for and found it's components for JSF. So the processing is going to be done in Java on the server side, is that correct?

2. You have some code which can run in this richfaces context and produce a tree which you're satisfied with. However it doesn't take XML as its input.

If I have that all right, then what I would suggest is to take the code which produces the tree, and modify it so that it does take XML as its input. Since I haven't seen the code, I can't suggest how you might do that. The concepts in that article you linked to might help. Just don't expect the article to provide code which you can drop into your richfaces context, instead you'll have to understand what its code does and what your code does and how to extract the useful bits from the article.
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Yes your pretty much right on. Except I do not have to use richfaces at all, I just started with it because it seemed like an easy way to create a tree for my pages. I think I can take the concepts from the linked article and apply them, but I just wanted to be absolutely sure that it is what I thought it was - takes input from an xml and parses it into a tree. It seems that is what it does so that will probably work for me, I will be trying it tomorrow.

But just in case you have a chance to look, here is the java code that takes data from a .properties file and parses it into a richfaces tree:



Unfortunately this code came from en example I found demoing richfaces trees, so I dont understand all of it. This makes it difficult for me to convert the code to take data from xml instead of .properties files. I attempt to do so in the other post I have on this forum which should be right below this one, but I am probably not on the right track with it
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Bah I dont think the example I found on that site is going to work for me. The javascript for it looks like this:



Which doesnt look like any code I am used to. So it seems it will not fit in for me unless someone knows how I would convert that to work. I thought javascript was the same across the board. I must be missing some piece of knowledge here, anyone care to tell me what it is?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The first code is Java. The second is Javascript. That is not an insignificant difference.

The problem isn't that you are missing a piece of knowledge, it's that you are missing a whole lot of knowledge. As I said elsewhere in one of your threads (I think), you shouldn't expect that you can just grab some code of the internet and have it miraculously do exactly what you want.

You don't even seem to have your requirements clear. At first I thought you had to work within RichFaces, but apparently you just seized on that as something which might get something done for you. So, if RichFaces isn't already part of your requirements then don't drag it in. Likewise if your requirement is to produce the tree from the server side, then don't drag in code which is written in Javascript.

So, first step: get your requirements cleared up. And remember, you need the requirements that originally existed, not things you identified as possibilities while you were galloping off in all directions.

Then once you have that done, you can start looking at solutions.
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Yes, I am unfamiliar with javascript, so when I first saw it I figured it was C# or some other type of language that wouldnt work for my project. But I followed the instructions and was able to create the sample page, so apparently it will work for me.
If I had a choice to learn all of these different concepts one at a time of course that is what I would do. But I won a design challenge from my college and now I am developing this for a company as part of winning. So I am not as ignorant on a lot of this as first impressions may seem, I do have experience but it is all classroom experience. Its mostly that developing for the web is something I havent really done, it has all been java code I have done within eclipse. Using swing gui components.


My requirements are that I am needing to create a page that has a content explorer on the left side, that has nodes populated from the xml I provided above. There will also be a set of tabs along the top, and a content pane for everything else to be displayed. The main content pane will change depending on what is selected from the content explorer from the left or the tabs across the top. I now have quite a few hours of experience with richfaces and jsf, but not javascript which is what threw me when I first looked at the example I provided. But now that I see how it fits in, I still think this will be the best option for what I am trying to do. That is it for my requirements, how this is done is completely up to me.
I do plan to use richfaces, because even if I dont use it for my tree, it will still make certian other things easier for me such as the row of tabs. The thing that worries me now though, is if I do use this example to create my tree, I am not going to have a clear idea of how to make what node is selected from the tree manipultae what shows up in my main content pane. But one problem at a time.

ow, i know I will nto be able to drag and drop pieces of my project into this example and make it work, but it still seems that figuring out how to integrate the two together will be the easiest way to do what I am trying to do. Or am I wrong about that. This is why I have had over 70 posts on this site and have only been a member for a little over a month. Im here trying to get some help with this.

Thanks for your comemnts, if you need any other information from me or have any other tips please feel free.

edit - the reason I "seized on richfaces" was because it was suggested to me by the contact I have at the company i am doing this for" WHen I first looked into that I did not even know how to import the richfaces library into my project. I have come quite a ways since then, but I know I have way more ground to cover
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing java code that will take data from certian xml <elements> and convert into tree nodes
 
Similar Threads
Help extracting text out of a response
need suggestions on how to deal with data iteration problems
Trying to get data stream from one class to another
java.util.ArrayList is not compatible with class java.lang.String exception (SOLVED)
Problem getting richfaces tree to display