My first page id edit.jsp. Here i will present indexed text boxes as table cells.The initial text values are taken from database and provided using my ActionForm and Bean classes.
Now i need to add new rows with empty text boxes. I want these rows also to be indexed. say like <table> <logic:iterate name="bookForm" property="books">
<tr> <td><html:checkbox property="id" name="books" indexed="true"/> <html:hidden property="id" name="books" indexed="true"/></td> <td><html:text property="author" name="books" indexed="true"/></td> <td><html:text property="title" name="books" indexed="true"/></td> <td><html:text property="available" name="books" indexed="true"/></td> </tr> </logic:iterate> </table> The above code is provided by a new RowAdder.jsp which should add a new row. If my scope is set to session, then the above code is presenting all the same table data instead of a new empty row.
if the scope is set to request then my server says my ActionForm is empty and cannot use <logic:iterate>
How can i add a new row with empty text boxes which are indexed? should i specify the index myself in the action which points to RowAdder.jsp?
should i set the index my self in BookForm.setBookBean(int inde,BookBean bean) to resolve this???
if so then what is the use of unindexed getter, setter methods which are provided as well.
Joined: Feb 15, 2005
Unless I'm missing something, you're working way too hard on this. All you have to do is instantiate a blank Book bean and add it to your ActionForm's List and forward back to the same JSP. You don't have to change the JSP at all. If you're using a <logic:iterate> loop, it will automatically pick up the new row and show blank data for it.
The first time it is displayed, you go to the database and find five books to be displayed. The user clicks "Add row". The Action for "Add Row" just creates another instance of Book with all blank properties and adds it to the books List. When the JSP is redisplayed, it will show the original five books plus a new blank row allowing the user to add another book.
Note: If your ActionForm is in request scope, you need to give your List "lazy initialization" capability. This link explains more about how to do this.