File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best Practice for Listing Directory Names

 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need a user list on an input form that shows the possible directory names where a file will can be located in our network system. Should I gather the directory names into an array and present them in a list or do I create a data file which holds the possibilites and pull this record set into an array? If the first is the best choice can you help me with code to pull
directory names?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This forum is for HTML and Javascript questions. That said, neither HTML or Javascript provide facilities for gathering directory names. On the other hand, if you are inquiring about gathering these directory names in server side code, and then how to display them on your page, we'll need more information. It could be that this question belongs in a different forum.
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What forum would this belong in and what other info do you need?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steve Dyke:
I need a user list on an input form that shows the possible directory names where a file will can be located in our network system.


Which part of this are you having a problem with? Generating the user list, getting the directory listing, or both? What server side technology are you using? Servlets/JSP?? You told us what you want to do but you told us nothing of your environment.
 
Garrett Smith
Ranch Hand
Posts: 401
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think he knows how to get the data on the server, but wants to know how to pass the data to the client and render it in the browser.

In that case...

I would generate the directory structure from a bean that generates HTML. Either in a jsp or a jsp tag (better).

The resulting html could be something like:


or



You can make this a tag and pass it the bean.

<lists:directories data="${dirBean}"/>
[ June 18, 2007: Message edited by: Garrett Smith ]
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using JSF to present the user a form. On the form there will be a static list control of main folders where a drawing will be stored. When the user selects an item from this static list I need another list control to be populated with a list of subfolders that is located within the main folder.
 
Garrett Smith
Ranch Hand
Posts: 401
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you're making an async request.

Are you using JSON, HTML, or XML?

if you are using HTML, you can insert some innerHTML from the success response.

If you are using JSON or XML, that requres a transformation in javascript. You will have to write javascript to create HTML based on the JSON or XML, then insert it in the document (do not do this in one function). If you are not comfortable doing this, then just use HTML and insert the success response with innerHTML.
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you elaborate on the innerHTML solution?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please give me some specifics to use for the client side:

HTML frgament

that would get the folder names located on the server side network?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your question how to obtain the server-side list, or how to display it once you get it to the client side?
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both, really. The data I have gatherd so far in my app for other purposes has been limited to data records which I put into an array then assign the array to a session atribute.

This is a new teritory for me so I need help in collecting the list and then presenting the list since by the time the list is needed the app will be in client mode. I hope I make sense.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't the right place to be discussing server-side operations. Once you get formatted HTML to the client, the innerHTML trik works just fine.

Are you using Ajax to fetch the information?

What are you using on the server? Servlets/JSP? Other?
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since your last post I have got this far. However, in my servlet the last line(just tring to check the array to see if it has any values) generates an error(NullPointerException). Note: This same line of code placed in my class will give a valid value. After I get my array to work can't I use ajax in my JSF to populate my list without reloading the page? If so I may need some help with this.

My class:


My servlet:

 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even this causes the NullPointerException error in my servlet:

 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have changed up my code a little but I still cannot get an array with any values in my servlet. Please help.

Class that gets directorys:



Class to set Array:



My Servlet Code:



The System.out is null.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The System.out is null.


I find this difficult to believe. On what do you base this assertion?
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind. My mistake. I was sending the wrong value to my class. I have it corrected and I am now getting desired array.

But my next challenge is how to get my servlet to return the array in a way that it will populate my list on my JSP.

My servlet has:


My JSP has:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But my next challenge is how to get my servlet to return the array in a way that it will populate my list on my JSP.


There's no need to do the list processing on the client. Have your servlet forward to a JSP that will take the list and format into an HTML fragment that you can use on the calliing page via innerHTML.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic