Re: Struts - Getter method
- From: Rudi <diaz_ruben2003@xxxxxxxxx>
- Date: Wed, 2 Jul 2008 14:43:29 -0700 (PDT)
On Jun 28, 3:50 pm, "Joe Blow" <nob...@xxxxxxxxxxx> wrote:
"Rudi28" <rd282...@xxxxxxxxx> wrote in message
news:24ef7d68-1afc-4783-b142-a1161cc781ec@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jun 25, 11:54 pm, Lew <l...@xxxxxxxxxxxxx> wrote:
Joe Blow wrote:
Sorry to post the code,First of all. . .never aplogize for posting the source code when you
are
asking for help with a programming problem.
To the OP: We love that you posted source code. It is a good thing.
This
group loves source code, as a rule.
<logic:iterate name="bookListForm" property="books" id="book"
type="com.mycompany.Book">
The JSP Standard Tag Library (JSTL) has largely supplanted the logic:
taglib
from Struts.
<c:forEach>, etc.
<http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/index.html>
You don't have to get into that right away. Learn logic:iterate and
c:forEach
will make sense, in a different but similar way.
Sun's JSTL tutorial is a good starting place, when you're ready.
<http://java.sun.com/javaee/5/docs/tutorial/doc/bnakc.html>
--
Lew
Hi guys,
Thanks Joe and Lew for your replies. I'm glad I did the right thing
posting the code then.
I implemented the change that Joe suggested, I replaced:
<logic:iterate name="bookListForm" property="books" id="book">
with
<logic:iterate name="bookListForm" property="books" id="book"
type="com.mycompany.Book">
but I get the following error:
Jun 27, 2008 2:01:21 PM org.apache.catalina.core.ApplicationDispatcher
invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.ClassCastException: [Ljava.lang.Object;
at org.apache.jsp.jsp.bookList_jsp._jspService(bookList_jsp.java:133)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:
393)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:
320)
I'm now reading about JSTL to see what I can do in terms of getting
this to work.
Thanks for your help and any other ideas are welcome. Hope that I
can get this
going soon since I need it for a project at work.
Sorry I should have caught this the first time through but I am not as
familiar with hibernate. Now that I'm looking again, I don't see anyplace
where you are actually constructing any Book objects. In your
BookListAction code you have this:
books = session.createQuery("select id, title, author, available from Book
t").list();
bookListForm.setBooks(books);
Now if you look at the javadoc api's for the org.hibernate.Query class
you'll find the following explanation for the list() method:
"Return the query results as a List. If the query contains multiple results
pre row, the results are returned in an instance of Object[]."
So in my best estimate, unless there is some hibernate magic at work behind
the scenes here I can't see, you never actually create any
com.mycompany.Book objects.
Hi Joe,
Thanks again for the reply. I'm new at this so it's taking me some
time to get things
going. I appreciate your help.
I think I understand what you're telling me. I'm putting the result
set of the query
(objects) in a Collection, but it's not a collection of type Book.
There's no connection
between the Collection that I defined called books and the actual Book
Class.
So maybe I shouldn't have even defined that Collection in the Book
Class.
I guess what I need to do is iterate through the result set from the
Query, while creating
instances of type Book and setting the attributes of each instance
accordingly with the
corresponding value from the result set (List). As each instance of
the Book object is created,
I need to load those instances in a Collection. Then I would have a
Collection of type Book to
go through and write to the jsp page.
Have a nice day and holiday. Hope that you're doing well. I'll try
to figure out how to do
this and will post again.
Take care,
Ruben
.
- Follow-Ups:
- Re: Struts - Getter method
- From: Joe Blow
- Re: Struts - Getter method
- Prev by Date: Re: SCJP Help needed.
- Next by Date: Re: Efficiently concatenating contents of multiple files
- Previous by thread: Tile Map Editor
- Next by thread: Re: Struts - Getter method
- Index(es):
Relevant Pages
|