File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to add new row in response page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to add new row in response page" Watch "How to add new row in response page" New topic
Author

How to add new row in response page

surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
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
<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.

regards,
surendarprabu


SCJP 1.4
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add new row in response page
 
Similar Threads
Dynamic Form Elements - Exception
Problem Passing Parameter values to action
Problem in hiding the row of data
Nested Iterator Tags
How to catch checkbox value