Вопрос

I want to iterate ArrayList element and Update the list element then save it.

My Form Bean:
MyTestCodeForm.java - it have two members id and ArrayList.
 String id;
 ArrayList<Book> listBook; 

getters and setters of id property getters and setters of ArrayList

 public void setListBook(ArrayList<Book> bookList)
 {
  this.listBook = bookList;
 }

 public ArrayList<Book> getListBook()
 {
   return this.listBook;
 }

Book.java have two members
 String bookId;
 String bookName;


Action class - MyTestCodeAction.java

In this, i have get the data and save into database.

my jsp page for iterating :

<nested:nest property='myTestCodeForm'>
<html:form action='/myTestCodeForm'>

<nested:write name='' property='id'/>
<html:hidden name='' property='id'/>
<nested:iterate id='foo' name='' property='bookList'>

  <html:text name='foo' property='bookName' indexd='true'/>

</nested:iterate>
<html:submit value='submit'/>

</html:form>

</nested:nest>

my question is, i iterate the data successfully but when i get the data into action class i didn't receive array list data but i received id attribute.

Please help

Это было полезно?

Решение

I got the solution, something i missed in FormBean class. Before I used in FormBean Class, one getter for getting ArrayList element and one setter for setting ArrayList element but i didn't create getter and setter for Book class, after creating getter and setter for Book class then i got the values in Action class. Now, My Form Bean look like this:

 public void setListBook(ArrayList<Book> bookList)
 {
  this.listBook = bookList;
 }

 public ArrayList<Book> getListBook()
 {
   return this.listBook;
 }
 public Book getBook(int index)
{
  if(index >= index)
  {
    this.listBook.add(new Book());
  }

  return (Book)this.listBook.get(index);
}
 public Book setBook(int index, Book book)
{
  return this.listBook.set(index, book);
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top