aspose file tools*
The moose likes Servlets and the fly likes Best Practice for Listing Directory Names Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Best Practice for Listing Directory Names" Watch "Best Practice for Listing Directory Names" New topic
Author

Best Practice for Listing Directory Names

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
What forum would this belong in and what other info do you need?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Jun 27, 2002
Posts: 401
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 ]

comp.lang.javascript FAQ: http://jibbering.com/faq/
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
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

Joined: Jun 27, 2002
Posts: 401
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

Joined: Nov 16, 2004
Posts: 1466
    
    1
Can you elaborate on the innerHTML solution?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67



[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
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

Joined: Jan 10, 2002
Posts: 61420
    
  67

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

Joined: Nov 16, 2004
Posts: 1466
    
    1
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

Joined: Jan 10, 2002
Posts: 61420
    
  67

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

Joined: Nov 16, 2004
Posts: 1466
    
    1
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

Joined: Nov 16, 2004
Posts: 1466
    
    1
Even this causes the NullPointerException error in my servlet:

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
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

Joined: Jan 10, 2002
Posts: 61420
    
  67

The System.out is null.


I find this difficult to believe. On what do you base this assertion?
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1466
    
    1
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

Joined: Jan 10, 2002
Posts: 61420
    
  67

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.
 
 
subject: Best Practice for Listing Directory Names