This is even more bizarre... I just did the following...
<logic:iterate id="drive" name="listDrivesForm" property="drives" type="java.io.File">
<tr><td>Drive: <%=drive.getClass().getName()%> - <nested:write name="drive" property="name" /></td></tr>
</logic:iterate>
And sure enough I'm seeing java.io.File for each before the dash, so I know they aren't null, and it seems unlikely that the taglib implementation would instantiate an object it it didn't find (although maybe it does, to avoid exceptions?). nested:write vs. bean:write doesn't seem to make any difference either.
Actually, thinking it through a little more, I think in fact the taglib code might very well be creating a File object, because that would explain why <%=drive.getName()%> in place of the bean:write tag is blank... Since I know for sure that listDrivesForm is in the request object, and I know for sure that the drives element is populated with the list of drives, then it's either (a) the :iterate tag not founding the collection (or for some reason finding it empty) and instead of throwing an exception is returning me an empty File object, which STILL doesn't make sense because it's obviously seeing the collection properly otherwise it wouldn't return an empty Field object the exact correct number of times, or (b) the :write tag is not properly getting the value from getName(), but that doesn't make sense because then doing <%=drive.getName()%> would work.
I have to conclude that the :iterate tag is somehow seeing the ArrayList correctly but is failing to get each element out of it and instead of throwing an exception is creating a new File object. That's the only thing I can think of that would explain everything I'm seeing.
Of course, that doesn't help me solve the problem! :)
From: "Geeta Ramani" <[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 15:37:53 -0400
Any joy looking at the page source maybe..?
> -----Original Message----- > From: None None [mailto:[EMAIL PROTECTED] > Sent: Thursday, May 06, 2004 3:43 PM > To: [EMAIL PROTECTED] > Subject: RE: Some further newbie woes > > > I'll stick with None None until I get this figured out :) > > That didn't seem to help either... I actually thought of that > previously, I > figured at some point there has to be some code casting an > Object to a File > object, otherwise certainly the getName() method call is > going to fail. I > tried again anyway, and it didn't help. > > >From: "Geeta Ramani" <[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 15:28:14 -0400 > > > >None None: (or Someone Someone..;)) > > > >In fact maybe just adding the "type" attribute to your > orignal iterate will > >work I think: > > > ><logic:iterate id="drive" name="listDrivesForm" property="drives" > >type="java.io.File"> > > <tr><td><bean:write name="drive" property="name" /></td></tr> > ></logic:iterate> > > > >Regards, > >Geeta > > > > > -----Original Message----- > > > From: Solley, Tim [mailto:[EMAIL PROTECTED] > > > Sent: Thursday, May 06, 2004 3:31 PM > > > To: Struts Users Mailing List > > > Subject: RE: Some further newbie woes > > > > > > > > > Hi None None... > > > > > > So in your JSP you are iterating over an ArrayList of File > > > objects, trying to get at a property inside the File objects. > > > To get at nested objects, you use the Struts nested tag library. > > > > > > Try replacing your <logic:iterate....> with the equivalent > > > from the nested library: (below off the top of my head) > > > > > > <nested:iterate id="drive" name="listDrivesForm" > > > property="drives" type="java.io.File"> > > > <nested:write name="drive" property="name"/> > > > </nested:iterate> > > > > > > See if you have luck with that. > > > > > > > > > > > > -----Original Message----- > > > From: None None [mailto:[EMAIL PROTECTED] > > > Sent: Thursday, May 06, 2004 2:16 PM > > > To: [EMAIL PROTECTED] > > > 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] > > > > > > > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: [EMAIL PROTECTED] > >For additional commands, e-mail: [EMAIL PROTECTED] > > > > _________________________________________________________________ > Stop worrying about overloading your inbox - get MSN Hotmail > Extra Storage! > http://join.msn.com/?pgmarket=en-us&page=hotmail/es2&ST=1/go/o nm00200362ave/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]
_________________________________________________________________
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]