Session Formulaire et Collection
Bonjour,
je me lance dans strust et les premiers problèmes surgissent, voici le problème:
Dans la sessions je mets un objet définit de cette façon ci:
Code:
1 2 3 4
| private Collection books;
books = new ArrayList();
books.add(new Book(random.nextLong(), "David Roos", "Struts book", true));
session.setAttribute("bookListForm", books); |
Bien, j'ai l'objet books dans la session, dans la jsp ou je prétends lire ma liste de livre j'ai quelque chose dans ce genre:
Code:
1 2 3 4 5
| <logic:empty name="bookListForm" property="books">
<tr>
<td colspan="5">No books available</td>
</tr>
</logic:empty> |
j' obtiens l'erreur suivante:
Code:
1 2
| SEVERE: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: No getter method for property books of bean bookListForm |
pourtant j'ai bien la définition de mon formulaire présent dans le fichier struts-config.xml:
Code:
1 2 3
| <form-beans >
<form-bean name="bookListForm" type="de.laliluna.tutorial.library.struts.form.BookListForm">
</form-bean> |
et aussi une méthode get dans la classe:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| private Collection books;
public Collection getBooks() {
return books;
}
public void setBooks(Collection books) {
this.books = books;
}
public void reset(ActionMapping arg0, HttpServletRequest arg1) {
books = new ArrayList();
} |
Merci d'avance.
Session Formulaire et Collection
Bonjour, :D
Alors, je serait intéressé de savoir comment faire pour pouvoir coder
<logic:empty name="bookListForm" property="books"> et référencer le form-bean bookListForm dans le mapping?
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <action-mappings >
<action path="/default" unknown="true" forward="/jsp/index.jsp"></action>
<action path="/bookList"
type="de.laliluna.tutorial.library.struts.action.BookListAction"
validate="true"
input="/jsp/BookList.jsp"
scope="request">
<forward name="showList" path="/jsp/bookList.jsp"></forward>
</action>
</action-mappings> |
Je te remercie!
Session Formulaire et Collection
Je te remercie pour les réponses :D
Code:
1 2 3 4 5 6 7 8
| <action path="/bookList"
type="de.laliluna.tutorial.library.struts.action.BookListAction"
validate="true"
input="/jsp/BookList.jsp"
scope="request"
name="bookListForm">
<forward name="showList" path="/jsp/bookList.jsp"></forward>
</action> |
a+
Session Formulaire et Collection
Ça marche presque, j'ai bien le form-bean dans la session, mas je le détecte toujours vide dans:
Code:
1 2 3 4 5 6 7
|
<logic:empty name="bookListForm" property="books">
<tr>
<td colspan="5">No books available</td>
</tr>
</logic:empty> |
alors qu'il devrait faire
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
<logic:notEmpty name="bookListForm" property="books">
<logic:iterate name="bookListForm" property="books" id="book">
<tr>
<%-- print out the book informations --%>
<td><bean:write name="book" property="author" /></td>
<td><bean:write name="book" property="title" /></td>
<td><html:checkbox disabled="true" name="book"
property="available" /></td>
<%-- print out the edit and delete link for each book --%>
<td><html:link action="bookEdit.do?do=editBook"
paramName="book" paramProperty="id" paramId="id">Edit</html:link></td>
<td><html:link action="bookEdit.do?do=deleteBook"
paramName="book" paramProperty="id" paramId="id">Delete</html:link></td>
</tr>
</logic:iterate>
</logic:notEmpty> |
Session Formulaire et Collection
j'avais cette déclaration:
BookListForm bookListForm = new BookListForm();
au lieu de:
BookListForm bookListForm = (BookListForm) form;
mais alors si c'est la première et comme rien n' a été saisi, alors j'aurais une erreur.
mais pour le reste ça marche.... :D
Merci!