SmartLogic Logo (443) 451-3001

The SmartLogic Blog

SmartLogic is a web and mobile product development studio based in Baltimore. Contact us for help building your product or visit our website to learn more about what we do.

Struts 1.1: Problems with logic:iterate tags and “Cannot find bean XXX under any scope”

June 12th, 2007 by

While trying to use the in my application i ran into the error:

javax.servlet.jsp.JspException: Cannot find bean providerListData in any scope

trying to use a . This is a generic error message that the compiler throws to let you know something is wrong with either your data or your setup.
First make sure you have included the taglib necessary to interpret the logic:iterate tag ie adding the line:

‘<'%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %'>‘

to you JSP (Assuming you do have the struts.jar jar in your WEB-INF/lib folder and the TLD files in your WEB-INF folder ). If that still does not solve your problem, check the spelling of your bean name, believe it or not it might be as simple as a capitalization error. In my application i wrote my tag this way:

'<'logic:iterate id="providerListData" name="ProviderView" type="com.sls.beans.Physician" '>'

and i set the ProviderView collection in my Action class this way:

request.setAttribute(“ProviderView”, ps);

with ps being an array of Physician objects. If you have gone through all these steps and you still are getting the “cannot find bean” error, then your data must be the error, as it must contain null values. If your collection might contain null elements, make sure to use a tag. I added the line

‘<'logic:present name="ProviderView"'>‘
‘<'logic:iterate id="providerListData" name="ProviderView" type="com.sls.beans.Physician" '>‘

…Rest of my display logic

‘<'/logic:present'>‘
‘<'/logic:iterate'>‘
‘<'/logic:present'>‘

The line checking for the existence of the collection element got rid of the error message. So always make sure you return data (in your collection) does not contain null elements and if it does, use the or tags to handle those cases and you should be fine. On a related not, i kept running into a

javax.servlet.jsp.JspException: No getter method available for property physicianId for bean under name org.apache.struts.taglib.html.BEAN

while trying to set up a radio input this way:

Even though my bean had the getPhysicianId() set up properly and spelled correctly because again spelling could be the issue. If you have a property called “myId”, your getter method should be getMyId(). Since a spelling error was not the issue here, i looked closely at the attribute description on the Jakarta homepage and this line got my attention:

The attribute name of the bean whose properties are consulted when rendering the current value of this input field. If not specified, the bean associated with the form tag we are nested within is utilized. (RT EXPR)

So the problem was that since i did not specify the name of the bean to use, it was using the default one (ActionForm) which of course did not have a getPhysicianId() method. By rewriting the code like this:

Specifying the name attribute was what it took to fix the problem for me!

HIH (Hope It Helps)!

  • http://www.sangmane.com Mozes

    thanks for your info .. it really helps … :)

  • http://www.thewebtechreviews.com webtechreviews

    Thank you, this helped me solved my problem at work!

  • Saji T Sathian

    Thank you very much . It really helped

  • David from Spain

    Thank you very much! Very useful!

  • http://quitsmokingpillstq.blogspot.com Pirsey

    If you want to see a reader’s feedback :) , I rate this article for 4/5. Decent info, but I have to go to that damn yahoo to find the missed pieces. Thank you, anyway!

  • Zana

    Excellent explanation, fixed my problem by the suggestion to add <logic:present…

Abou Kone was a developer at SmartLogic from 2006 to 2007.

AK One's posts