2012-07-13 64 views
1

在這個論壇的很多帖子中都會調用類似的問題;但沒有人有解決方案,具體的一個,我感謝你在這幫助我:JSP form:checkbox into c:foreach

我使用spring來開發一個web應用程序, 我不知道我應該在表單的路徑:checkbox標籤其中C內:的foreach一個,這是我的代碼:

<c:forEach items="${persons}" var="person" varStatus="i"> 
    <tr> 
     <td><c:out value="${person.firstName}" /></td> 
     <td><c:out value="${person.lastName}" /></td> 
     <td><form:checkbox path="person.rights" value="Download"/>Download </td> 
     <td><form:checkbox path="person.rights" value="Delete"/>Delete </td> 
    </tr> 
</c:forEach> 

rights」是因爲它的彈簧文檔中定義的字符串列表,它具有一個吸氣和一個設置器等的其他屬性,我的複選框在c:foreach標籤之外工作,但在將它們包含到此標籤中時,會生成以下異常:

org.springframework.beans.NotReadablePropertyException: Invalid property 'person' of bean class [java.util.ArrayList]: Bean property 'person' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter? 

你有什麼問題的想法?

+0

請發佈人員權限屬性如何獲取/設置定義。 – kosa 2012-07-13 21:49:10

+0

我確定這個問題不在我的getter和setter中,它在'路徑'中; 'String [] rights = new String [] {}; \t public String [] getRights(){ \t \t return rights; \t} \t \t 公共無效setRights(字符串[]權利){ \t \t此。權利=權利; \t}' – maouven 2012-07-13 21:50:32

+0

不應該那兩個複選框是不同的屬性?爲什麼都指向人的同一個屬性? – kosa 2012-07-13 21:53:34

回答

1

這個Link可能對你有用。 謝謝

+0

謝謝你,但這裏的問題是,我不只有一個列表,而是一個列表裏面的其他列表,如果你想..人員名單,每個人有它自己的權利列表,而且這是無法訪問的列表 – maouven 2012-07-15 14:58:01

3

這個問題很奇怪在大多數地方沒有記錄。以下是我在下面發佈的鏈接摘錄。要點是我們需要一個靜態佔位符,它映射到類型而不是bean的值。因此,$ {}中的任何內容都無法解決。爲此,在使用帶有s [ring形式tld的JSTL循環運算符<c:forEach>的特定情況下,我們應該使用<c:forEach>運算符的varStatus屬性在每次迭代中引用類型信息,就像數組的索引一樣,因此請參閱集合變量上使用.的可迭代集合的內部屬性,該集合變量可通過備份表單的最外面的bean訪問。

例如:

<c:forEach items="${teamslist_session.teams}" var="team" varStatus="teamsLoop"> 
<form:input path="teams[${teamsLoop.index}].name"/> 
</c:forEach> 

其中:

  • teamList_session是bean備份形式
  • teams是豆類的收集其特性,我們需要在path設置屬性
  • var是對的每個成員的引用收集
  • teamsLoop是迭代指數,這在下面的線用於表示該說的話,i個元素的bean的屬性稱爲name

請參考以下鏈接瞭解更多信息: Forum Discussion - See the last post The link provided for reference in link 1