I truly do hate myself sometimes...

I was just about to post that I had solved the problem, when I saw your message (and someone else that caught it as well).

100% correct, it was the wrong method to be calling. getPath() was exactly right. I dawned on me that I have a FILE object, and what I really want is a list of drives, or paths, to use a different term, and I wondered if instead of the File class putting the name of the drive in the name property (like it obviously does the name of a file) it was just leaving it in the path property and not copying it over (which would be convenient!). Sure enough, it does NOT do the copy, hence the result I was seeing.

Thanks very much to all! I feel a bit dumb for not catching a now-obvious problem eariler, but I appreciate all the suggestions. It's certainly helping me to pick up Struts because I wasn't even aware of the nested taglib yet, now I am.


From: "Niall Pemberton" <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Subject: Re: Some further newbie woes
Date: Thu, 6 May 2004 21:08:54 +0100

Its all looks good to me except that File.getName() is returning an empty
String - instead of using "name" in your <bean:write> try "path" and I think
you'll see what you're expecting:


   <logic:iterate id="drive" name="listDrivesForm" property="drives">
     <tr><td><bean:write name="drive" property="path" /></td></tr>
   </logic:iterate>


Niall


----- Original Message -----
From: "None None" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 06, 2004 8:16 PM
Subject: Some further newbie woes


> Ok, I've banged my head enough in the past two hours...
>
> I'm working on a file manager Struts app to get myself acquainted with
> Struts. The first logical step is a list of drives. Here's what I've
> done...
>
> I have created an index.jsp that does a quick forward to main.jsp (just
like
> the blank struts app does). In main.jsp I have a simple link to
> listDrives.ofm (using extension mapping in this app). Here's my
> struts-config.xml file, minus comments, linebreaks and the XML & doctype
> tags (to save space here)...
>
> <struts-config>
> <form-beans>
> <form-bean name="listDrivesForm"
> type="com.omnytex.ofm.actionforms.ListDrivesForm" />
> </form-beans>
> <global-forwards>
> <forward name="main" path="/main.ofm" />
> </global-forwards>
> <action-mappings>
> <action path="/main" type="org.apache.struts.actions.ForwardAction"
> parameter="/jsp/main.jsp" />
> <action path="/listDrives"
> type="com.omnytex.ofm.actions.ListDrivesAction" name="listDrivesForm"
> scope="request" validate="false">
> <forward name="showDrivesList" path="/jsp/drivesList.jsp" />
> </action>
> </action-mappings>
> </struts-config>
>
> Simple enough. So, I click my link and the following ActionForm is
> instantiated in request scope:
>
> package com.test.ofm.actionforms;
> import org.apache.struts.action.*;
> import java.io.*;
> import java.util.*;
> public class ListDrivesForm extends ActionForm {
> private ArrayList drives = null;
> public ListDrivesForm() {
> drives = null;
> }
> public void setDrives(File[] inDrives) {
> drives = new ArrayList();
> for (int i = 0; i < inDrives.length; i++) {
> drives.add(inDrives[i]);
> }
> }
> public ArrayList getDrives() {
> return drives;
> }
> }
>
> Also simple enough. Next, the following action executes:
>
> package com.test.ofm.actions;
> import org.apache.struts.action.*;
> import java.io.*;
> import javax.servlet.http.*;
> import com.test.ofm.actionforms.*;
> public class ListDrivesAction extends Action {
> public ActionForward execute(ActionMapping mapping, ActionForm form,
> HttpServletRequest request, HttpServletResponse response) throws Exception
{
> File[] drives = File.listRoots();
> ListDrivesForm ldf = (ListDrivesForm)form;
> ldf.setDrives(drives);
> return mapping.findForward("showDrivesList");
> }
> }
>
> Now, to this point I am OK because if I do a simple println of
> ldf.getDrives(), I in fact get a list of the drives on my system as
> expected. So, I know my basic flow to this point is OK, and I know the
code
> in the action is doing what I expect. Lastly, I have the following JSP:
>
> <%@ page language="java" import="java.io.*,com.omnytex.ofm.actionforms.*"
%>
> <%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" %>
> <%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean"%>
> <html>
> <head>
> <title>File Manager</title>
> </head>
> <body>
> File Manager
> <br><hr><br>
> <table border="1" cellpadding="0" cellspacing="0" width="100%">
> <logic:iterate id="drive" name="listDrivesForm" property="drives">
> <tr><td><bean:write name="drive" property="name" /></td></tr>
> </logic:iterate>
> </table>
> </body>
> </html>
>
> This is where the problem arises... My table is being built, and the
proper
> number of rows are there, but I'm not seeing the drive letter being
> displayed. I have verified that my listDrivesForm is present and
populated
> by donig:
>
> <%
> ListDrivesForm ldf =
> (ListDrivesForm)request.getAttribute("listDrivesForm");
> System.out.println(ldf);
> %>
>
> Sure enough, I see my drive list. Now, I've been playing with various
names
> and ID combinations in the logic:iterate and bean:write tags, but nothing
> seems to make it work. I've also tried in place of bean:write:
>
> <tr><td><%=((File)drive).getName()%></td></tr>
>
> From my reading I expected that to work just as well. I've also tried
> adding the scope attribute to the bean:write tag to no avail.
>
> So, what am I doing wrong here? Do I need to do usebean here? Every
> example I've seen of this never shows that, so I assume not. Also, why
> didn't the code manually calling getName() above not work either? Even if
I
> needed useBean I would expect that to still work, which leads me to
believe
> I DON'T need useBean.
>
> Any help is very much appreciated!
>
> _________________________________________________________________
> MSN Toolbar provides one-click access to Hotmail from any Web page - FREE
> download! http://toolbar.msn.com/go/onm00200413ave/direct/01/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


_________________________________________________________________
Express yourself with the new version of MSN Messenger! Download today - it's FREE! http://messenger.msn.com/go/onm00200471ave/direct/01/



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to