Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

How to add new row in response page

Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic