• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

html:options throws an exception, help please!

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using html ptions to display a list of values retrieved from DB.

My JSP looks like:

<html:select property="sponsor">
<html ptions collection="sponsorList" property="value" labelProperty="label"/>
</html:select>

where sponsorList is the name of an attribute in reqeust scope, and is set by the action class; sponsorList is basically an ArrayList of LabelValueBeans.

When I run my web app, the exception says:

javax.servlet.jsp.JspException: Cannot find bean under name sponsorList
org.apache.struts.taglib.html.OptionsTag.getIterator(OptionsTag.java:374)
org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java:185)

Can someone please help? Thank you.
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Tong

in the first lines of your jsp file you must have this


why the scope is session and not a request??,
because if you use a validatitor plugin, or generally an error was thrown,
the application create a new request and losing the list that was declared
previous in your action class (yes only the "lists", not the variables values already inserted in your jsp file , because it is all referenced by the ActionForm)

best wishes
[ November 06, 2006: Message edited by: Manuel Jordan ]
 
Tong Wang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Manuel, for you help.

I found the problem and solved it. Actually, my JSP is fine, the problem is with my JDBC part, where there is a SQL error and the result collection is null. No need for the jsp:useBean tag, just set the collection as an attribute in one of the scopes and reference it by name.

However, I am not quite understanding the reqeust vs. session attribute part. To me, either reqeust or session attribute works fine. Since the attribute is set in the action class, which is executed before the JSP is rendered, that is before any validation error could happen on the JSP, does it still matter whether it's a request or a session attribute?
 
Manuel Jordan
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Tong

about this

No need for the jsp:useBean tag, just set the collection as an attribute in one of the scopes and reference it by name.



can you copy or share here the code???

does it still matter whether it's a request or a session attribute?



i had this problem, when the validation.xml find an error ,the page lose the ArrayList's,so i resolve this problem in the way mentionated (session scope), so i want to see the way in how you resolve with "attribute"

i am a little confuse

regards
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you put the list of values in request scope, you will have a problem if validation encounters an error and tries to redisplay the page. The list of options will be out of scope and you will get null values. If you really insist on putting this list in request scope, you will need to have a mechanism for rebuilding it, such as overriding the reset() method, or using lazy initialization in the getter.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...or by configuring the input attribute of your action mapping to use the action that was used to display the page so that your list will be loaded again.

- Brent
 
Manuel Jordan
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys

If you put the list of values in request scope, you will have a problem if validation encounters an error and tries to redisplay the page. The list of options will be out of scope and you will get null values. If you really insist on putting this list in request scope, you will need to have a mechanism for rebuilding it, such as overriding the reset() method, or using lazy initialization in the getter.



ok, i am agree, so i resolved this with the session scope, is good in perfomance this??, or a bad solution???

...or by configuring the input attribute of your action mapping to use the action that was used to display the page so that your list will be loaded again.


can you please, show un example of this???

regards
 
reply
    Bookmark Topic Watch Topic
  • New Topic