We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

struts tiles / nested taglib exception

tmonteit
tmonteit asked
on
Medium Priority
988 Views
Last Modified: 2013-11-24
I have a struts form with an ArrayList.  I want the elements of the array list listed in a struts tile.  To do this, I'm using the nested taglib.  When I add the reference to the taglib I get an exception.

      <%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested" %>

      <nested:iterate property="activity">
      <tr>
        <td>a: <nested:write property="name"/></td>
        <td>b: <nested:write property="title"/></td>
      </tr>
      </nested:iterate>

javax.servlet.jsp.JspException: ServletException in '/jsp/classroom/classroom.jsp':
ServletException in '/jsp/classroom/classLayout.jsp': ServletException
in '/jsp/classroom/director.jsp': Cannot find bean  in any scope
      at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:921)
      at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)
      at _jsp._jsp._layout._layout__jsp._jspService(jsp/layout/layout.jsp:23)
        .....

1.  How do I fix this exception?  
2.  If there's an easier more reliable way to put the ArrayList data into the jsp page without using nested library, I would be open to that solution.
Comment
Watch Question

Commented:
> 1.  How do I fix this exception?
If your ArrayList is not store in the form bean, then you need to store the ArrayList in request/session attribute and specify the name on the nested tag to refer to  the ArrayList.
Example:

request.setAttribute("myArrayList", activityList);

<nested:iterate property="activity" name="myArrayList">
     <tr>
       <td>a: <nested:write property="name"/></td>
       <td>b: <nested:write property="title"/></td>
     </tr>
</nested:iterate>

> 2.  If there's an easier more reliable way to put the ArrayList data into the jsp page without using nested library, I would be open to that solution.
You can either use scriplet or JSTL (preferable).

Author

Commented:
1.  the problem is I can't use "nested:Iterate" because including the following line:

   ' <%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested" %>  '

causes a major exception.   I need to either fix the exception or use another taglib.

2.  I'm trying all kinds of other ways it iterate the array list and display the data.

my latest is:
   a.  Servlet:
         ArrayList courseList = new ArrayList();
         // I add a bean that contains getters and setters for name and title
        request.setAttribute("courseList", courseList);


    b.  JSP Code
          <logic:iterate id="element" name="courseList" >
       <tr>
            <td> name: <c:out value="${element.name}"/>  </td>
            <td> title: <c:out value="${element.title}"/>  </td>
        </tr>
      </logic:iterate>  

     c.  The error:  

avax.servlet.jsp.JspException: ServletException in '/jsp/classroom/classroom.jsp':
ServletException in '/jsp/classroom/classLayout.jsp': ServletException
in '/jsp/classroom/director.jsp': Cannot find bean courseList in any scope
      at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:921)
      at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)
      at _jsp._jsp._layout._layout__jsp._jspService(jsp/layout/layout.jsp:23)
      at com.caucho.jsp.JavaPage.service(JavaPage.java:60)


How do I display this data in my JSP?   Simple example please
use this

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

and make sure you have   struts-nested.tld  in web-inf



>>>>>Cannot find bean courseList in any scope

its unable to find scope of  bean.make sure scope="request" in struts-config
<action > tags
Commented:
It will much easier to debug if you can post the error log caused by struts nested tag.

Try setting the scope in the <logic:iterate>.

     <logic:iterate id="element" name="courseList" scope="request">
      <tr>
          <td> name: <c:out value="${element.name}"/>  </td>
          <td> title: <c:out value="${element.title}"/>  </td>
       </tr>
     </logic:iterate>  


Since you are using JSTL, you can use <c:foreach> to loop the array list.

       <c:foreach var="element" items="${courseList}" >
      <tr>
          <td> name: <c:out value="${element.name}"/>  </td>
          <td> title: <c:out value="${element.title}"/>  </td>
       </tr>
     </c:foreach>  

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.