Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cant get Collection property from ActionForm..

Status
Not open for further replies.

jms137

Programmer
Oct 6, 2002
18
0
0
GB
Hi,

I have books.jsp with its ActionForm called BookForm, which links to an Action called BookAction.

I want the BookForm class to have a property called 'books' which returns a Collection of 'Book' objects.

When my books.jsp FIRST loads I want to have an iterator like this:
<table border=&quot;1&quot;>
<logic:iterate collection=&quot;books&quot; >
<member>
<tr>
<td>col one</td>
<td>col two</td>

</tr>
</member>
</logic:iterate>
</table>

I want the Struts engine to automatically get the property 'books' from my BookForm class and carry out the iteration. However, the problem is that the logic:iterate tag expects you to have stored a bean in a scope and wishes to use this. I DO NOT want to store a bean in a scope. What I want is when the page first loads, that Struts should use the <formbean> mapping in struts-config.xml (which i've done ok) and realise that BookForm is the form-bean for Book.jsp. Then I want it to instantiate an instance of BookForm and call getBooks() to get the collection, all automatically. getBooks() will be a static method which will contact a database and create a Collection of Books.

I know struts can do something similar, because my page also has a tag like this:

Title:<html:text property=&quot;title&quot; />

and when the page first loads the Struts framework recognizes my BookForm class is connected to books.jsp and calls getTitle() obtaining the title.

I'm hoping i'm missing something here. I will be very dissapointed with struts if it can match properties to bean properties one way but not the other....

thanks in advance,
john
 
..sorry if this post is not clear I can also post sourcecode.

also if anyone can tell me how to correctly access each 'Book' bean in the collection while iterating and extract e.g. getTitle and getAuthor instead of where I have wrote 'col one' and col two' this would be appreciated.

happy xmas.
john
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top