2014-04-01 6 views
-1

ArrayList 요소를 반복하고 목록 요소를 업데이트 한 다음 저장하고 싶습니다. ID 속성의Struts 1.2 - ArrayList 표시 및 업데이트

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

getter 및 setter이에서 getter와

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 

ArrayList를

의 호텔은, 내가 데이터를 얻을 데이터베이스에 저장합니다. 반복하는 대한

내 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, 당신은 나에게 빈 값을 설정하려고하는 대상 클래스에 대한 코드를 보여 주 시겠어요, 또한-config.xml에 스트럿, 난 당신이하지 생각 : 자, 내 양식 콩은 다음과 같이 모델 속성을 올바르게 구성합니다. –

+0

답장을 보내 주셔서 감사합니다.하지만 제 솔루션이 있습니다. 솔루션을 참조하십시오. –

답변

0

FormBean 클래스에서 놓친 해결책이 있습니다. FormBean 클래스에서 사용하기 전에 ArrayList 요소를 가져 오는 getter와 ArrayList 요소를 설정하는 Setter 중 하나지만 Book 클래스의 getter 및 setter를 만든 후 Book 클래스의 getter 및 setter를 만들지 못했습니다. 그러면 Action 클래스에 값이 있습니다.

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