Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

logic:iterate question

Thread view: 
Ming - 26 Nov 2007 03:17 GMT
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
Ming - 26 Nov 2007 03:40 GMT
> logic:iterate question
> Reply to all
[quoted text clipped - 50 lines]
>
> 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 O H I L - 26 Nov 2007 06:34 GMT
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);
Lew - 26 Nov 2007 14:13 GMT
> 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.

Signature

Lew

Manish Pandit - 26 Nov 2007 22:27 GMT
> The line ( <bean:write name="book" property="title" /><br/>throws an
> exception:
[quoted text clipped - 15 lines]
>
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.