2014-04-01 51 views
-1

我想迭代ArrayList元素并更新列表元素,然后保存它。Struts 1.2 - 显示和更新ArrayList项目

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

getter和setter id属性的 getter和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 

制定者在这方面,我有获取数据并保存到数据库中。对于迭代

我的jsp页面:

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

我的问题是,我成功地重复数据,但是当我得到的数据转化为动作类我没有收到数组列表数据,但我收到的id属性。

请帮忙

+0

Abhijeet,你能告诉我目标类的代码,其中bean值将被设置,还有struts-config.xml,我想你不是正确配置模型属性。 –

+0

感谢您的回复,但我得到了我的解决方案。见解决方案。 –

回答

0

我得到了解决方案,我错过了FormBean类。在我使用FormBean Class之前,有一个获取ArrayList元素的getter和一个设置ArrayList元素的setter,但是我没有为Book类创建getter和setter,为Book类创建getter和setter后,我得到了Action类中的值。现在,My Form Bean看起来像这样:

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); 
}