Problem accessing elements of Collection inside logic:iterate
Hello everyone, I need your help with a tricky problem, where I do not see any explanation currently: I try to construct a table with all data items stored in a database using Hibernate. There is a Form bean for the data items themselves and a form bean with a Collection (ArrayList) with the list of all such data items. Here is the relevant JSP code logic:present name=InterfacesOverviewForm logic:notEmpty name=InterfacesOverviewForm property=interfacesItems table logic:iterate id=InterfacesOverviewData name=InterfacesOverviewForm property=interfacesItems type=de.Platinion.rr.QuestGen.P200038_26.Presentation.form.InterfacesInputFo rm tr td html:text name=InterfacesOverviewData property=mainId size=2/ // put one property of the interfaces data item into the table cell (**) . . . /logic:notEmpty logic:empty name=InterfacesOverviewForm property=interfacesItems No Interfaces data items stored yet. br / /logic:empty /logic:present logic:notPresent name=InterfacesOverviewForm No Interfaces data items available. br / /logic:notPresent In my OverviewInterfacesAction I do the following: ... Collection lDTOList = lService.readData(); // read data from the persistence layer ArrayList lFormInterfacesList = new ArrayList(); // the list of form beans lFormInterfacesList = (ArrayList) convert(lDTOList); convert DTO's to form beans lForm.setInterfacesItems(lFormInterfacesList); // set the form bean collection into the form pRequest.setAttribute(InterfacesOverviewForm,lForm); // place the form with the collection into the request return (pMapping.findForward(Constants.SUCCESS)); // done } I expect that in my JSP, The iterate gets in each iteration one form after the other out of the collection and that I have access to the properties of the collection elements as in line (**) Unfortunately there are two effects that I cannot explain: 1) With the code as above I get an Exception stating, that bean InterfacesOverviewData cannot be found in any scope 2) If I start the JSP with a bean:define id=InterfacesOverviewData name=InterfacesOverviewForm type=de.Platinion.rr.QuestGen.P200038_26.Presentation.form.InterfacesOvervie wForm/ I still get a different exception, but this time stating, that there is no getter method for property mainId in form InterfacesOverviewForm, which is correct since that form contains a Collection with elements which all have a property mainId and getter getMainId(). 3) If I try to access the Collection instead of a property in line (**), i.e. I change the line to: html:text name=InterfacesOverviewData property=interfacesItems size=150/ Then I see the the ArrayList printed (I provided a toString() method in the InterfacesInputForm (i.e. the form which represents an element of the Collection), thoug obviously the Collection is there and can be accessed. 4) A further observation which I cannot explain might indicate that the heart of my error in not caused by the logic:iterate tag itself: both branches of the surrounding logic:present and logic:empty checks, i.e., logic:present and logic:notPresent and logic:empty and logic:notEmpty are executed (with the code as described until (3)) Any help or hint is highly appreciated! Thanks in advanced Robert Dr. Robert Riemann | IT Architect Platinion GmbH A Company of The Boston Consulting group Ridlerstr. 31b 80339 Munich/Germany Tel. +49 (0) 89 54545-53 22 Mobile +49 (0) 160 532 33 22 Fax +49 (0) 89 5108 2900 mailto:[EMAIL PROTECTED] http://www.platinion.de
Problem accessing elements of Collection inside logic:iterate (II)
Hello everyone, (a second post since my mail editor just made the posting unreadable... sorry!) I need your help with a tricky problem, where I do not see any explanation currently: I try to construct a table with all data items stored in a database using Hibernate. There is a Form bean for the data items themselves and a form bean with a Collection (ArrayList) with the list of all such data items. Here is the relevant JSP code ... logic:present name=InterfacesOverviewForm logic:notEmpty name=InterfacesOverviewForm property=interfacesItems table logic:iterate id=InterfacesOverviewData name=InterfacesOverviewForm property=interfacesItems type=Presentation.form.InterfacesInputForm tr td !-- put a property of the interfaces item in table cell -- html:text name=InterfacesOverviewData property=mainId size=2/ !-- (**) -- /logic:notEmpty logic:empty name=InterfacesOverviewForm property=interfacesItems No Interfaces data items stored yet. br / /logic:empty /logic:present logic:notPresent name=InterfacesOverviewForm No Interfaces data items available. br / /logic:notPresent In my OverviewInterfacesAction I do the following: ... // read data from the persistence layer Collection lDTOList = lService.readData(); // the list of form beans ArrayList lFormInterfacesList = new ArrayList(); // convert DTO's to form beans lFormInterfacesList = (ArrayList) convert(lDTOList); // set the form bean collection into the form lForm.setInterfacesItems(lFormInterfacesList); // place the form with the collection into the request pRequest.setAttribute(InterfacesOverviewForm,lForm); // done return (pMapping.findForward(Constants.SUCCESS)); } I would expect that in my JSP, The iterate gets in each iteration one form after the other out of the collection and that I have access to the properties of the collection elements as in line (**) Unfortunately there are two effects that I cannot explain: 1) With the code as above I get an Exception stating, that bean InterfacesOverviewData cannot be found in any scope 2) If I start the JSP with a bean:define id=InterfacesOverviewData name=InterfacesOverviewForm type=Presentation.form.InterfacesOverviewForm/ I still get a different exception, but this time stating, that there is no getter method for property mainId in form InterfacesOverviewForm, which is correct since that form contains a Collection with elements which all have a property mainId and getter getMainId(). 3) If I try to access the Collection instead of a property in line (**), i.e. I change the line to: html:text name=InterfacesOverviewData property=interfacesItems size=150/ Then I see the the ArrayList printed (I provided a toString() method in the InterfacesInputForm (i.e. the form which represents an element of the Collection), thoug obviously the Collection is there and can be accessed. 4) A further observation which I cannot explain might indicate that the heart of my error in not caused by the logic:iterate tag itself: both branches of the surrounding logic:present and logic:empty checks, i.e.,logic:present and logic:notPresent and logic:empty and logic:notEmpty are executed (with the code as described until (3)) Any help or hint is highly appreciated! Thanks in advanced Robert - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem accessing elements of Collection inside logic:iterate (II)
Riemann Robert (Platinion) wrote: Hello everyone, (a second post since my mail editor just made the posting unreadable... sorry!) I need your help with a tricky problem, where I do not see any explanation currently: I try to construct a table with all data items stored in a database using Hibernate. There is a Form bean for the data items themselves and a form bean with a Collection (ArrayList) with the list of all such data items. Here is the relevant JSP code ... logic:present name=InterfacesOverviewForm logic:notEmpty name=InterfacesOverviewForm property=interfacesItems table logic:iterate id=InterfacesOverviewData name=InterfacesOverviewForm property=interfacesItems type=Presentation.form.InterfacesInputForm tr td !-- put a property of the interfaces item in table cell -- html:text name=InterfacesOverviewData property=mainId size=2/ !-- (**) -- /logic:notEmpty logic:empty name=InterfacesOverviewForm property=interfacesItems No Interfaces data items stored yet. br / /logic:empty /logic:present logic:notPresent name=InterfacesOverviewForm No Interfaces data items available. br / /logic:notPresent In my OverviewInterfacesAction I do the following: ... // read data from the persistence layer Collection lDTOList = lService.readData(); // the list of form beans ArrayList lFormInterfacesList = new ArrayList(); // convert DTO's to form beans lFormInterfacesList = (ArrayList) convert(lDTOList); // set the form bean collection into the form lForm.setInterfacesItems(lFormInterfacesList); // place the form with the collection into the request pRequest.setAttribute(InterfacesOverviewForm,lForm); // done return (pMapping.findForward(Constants.SUCCESS)); } I would expect that in my JSP, The iterate gets in each iteration one form after the other out of the collection and that I have access to the properties of the collection elements as in line (**) Unfortunately there are two effects that I cannot explain: 1) With the code as above I get an Exception stating, that bean InterfacesOverviewData cannot be found in any scope Maybe convert() is returning null? 2) If I start the JSP with a bean:define id=InterfacesOverviewData name=InterfacesOverviewForm type=Presentation.form.InterfacesOverviewForm/ I still get a different exception, but this time stating, that there is no getter method for property mainId in form InterfacesOverviewForm, which is correct since that form contains a Collection with elements which all have a property mainId and getter getMainId(). Yes, but your bean:define binds IngerfacesOverviewData to an instance of interfacesOverviewForm, not to the element type. 3) If I try to access the Collection instead of a property in line (**), i.e. I change the line to: html:text name=InterfacesOverviewData property=interfacesItems size=150/ Then I see the the ArrayList printed (I provided a toString() method in the InterfacesInputForm (i.e. the form which represents an element of the Collection), thoug obviously the Collection is there and can be accessed. With or without the bean:define? Shouldn't that be name=InterfacesOverviewForm? 4) A further observation which I cannot explain might indicate that the heart of my error in not caused by the logic:iterate tag itself: both branches of the surrounding logic:present and logic:empty checks, i.e.,logic:present and logic:notPresent and logic:empty and logic:notEmpty are executed (with the code as described until (3)) That sounds a bit odd... I'd suggest adding some debugging code to the JSP to print out everything in the various scopes to make sure everything's as you expect it. L. -- Laurie, Open Source advocate, Java geek and novice blogger: http://www.holoweb.net/~laurie/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]