Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to add new row in response page  RSS feed

surendar prabu
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using indexed properties in my application.

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
<logic:iterate name="bookForm" property="books">

<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>
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.

Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

For example:

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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!