logic:iterate question

M

Ming

logic:iterate question
Reply to all
Forward
Reply by chat
Filter messages like this
Print
Add to Contacts list
Delete this message
Report phishing
Report not phishing
Show original
Message text garbled?
Why is this spam/nonspam?
Minghui Yu to Struts

show details 6:58 PM (19 minutes ago)



Reply


in Action:
....
Set<Book> books=bdao.findAllBooks();
request.setAttribute("books", books);
....


In JSP:

<logic:present name="books">
All Books:<br/><br/>
<logic:iterate id="book" name="books">
<bean:write name="book" property="title" /><br/>
</logic:iterate>
</logic:present>
--

The line ( <bean:write name="book" property="title" /><br/>throws an
exception:

Root Cause:
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot
find bean: "book" in any scope

(there is getTitle method for Book)

Any idea why I made mistake?

Thanks,

Thanks & Have a good day,

YU, Minghui
Reply

Forward
 
M

Ming

logic:iterate question
Reply to all
Forward
Reply by chat
Filter messages like this
Print
Add to Contacts list
Delete this message
Report phishing
Report not phishing
Show original
Message text garbled?
Why is this spam/nonspam?
Minghui Yu to Struts

show details 6:58 PM (19 minutes ago)

Reply

in Action:
...
Set<Book> books=bdao.findAllBooks();
request.setAttribute("books", books);
...

In JSP:

<logic:present name="books">
All Books:<br/><br/>
<logic:iterate id="book" name="books">
<bean:write name="book" property="title" /><br/>
</logic:iterate>
</logic:present>
--

The line ( <bean:write name="book" property="title" /><br/>throws an
exception:

Root Cause:
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot
find bean: "book" in any scope

(there is getTitle method for Book)

Any idea why I made mistake?

Thanks,

Thanks & Have a good day,

YU, Minghui
Reply

Forward


Tried code below, same error"


<logic:present name="books">
All Books:<br/><br/>

<logic:notEmpty name="books">
<logic:iterate id="book" name="books" indexId="cnt">
Next element is <bean:write name="book" property="title"/>
</logic:iterate>
</logic:notEmpty>

<logic:empty name="books">
Database search does not return any result
</logic:empty>

</logic:present>
 
S

S O H I L

hi,
pls set the variable scope to session in struts config
and set the variable in session

Set<Book> books=bdao.findAllBooks();
session.setAttribute("books", books);
 
L

Lew

S said:
hi,
pls set the variable scope to session in struts [sic] config
and set the variable in session

Set<Book> books=bdao.findAllBooks();
session.setAttribute("books", books);

Why is that necessary?

Struts tags are supposed to be able to find request attributes, too.

Personally, I'd use standard tags; even Struts dropped those tags in its
current version.

Anyhow, the problem wasn't with finding the "books" bean, it was with finding
the "book" bean.
 
M

Manish Pandit

The line ( <bean:write name="book" property="title" /><br/>throws an
exception:

Root Cause:
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot
find bean: "book" in any scope

(there is getTitle method for Book)

Any idea why I made mistake?

Thanks,

Thanks & Have a good day,

YU, Minghui
Reply

Forward

The scope should be fine, as book bean should be created under page
scope, accessible to bean:write. I agree with Lew on using standard
tags, which would make this a lot easier with EL.

Are you sure the struts-bean TLD is delcared in the JSP? How about you
try to use bean:write with some other variable outside of the
logic:iterate and see if that works?

-cheers,
Manish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top