Solved

struts tiles / nested taglib exception

Posted on 2006-10-29
4
947 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.
0
Comment
Question by:tmonteit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 14

Expert Comment

by:boonleng
ID: 17833127
> 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).
0
 

Author Comment

by:tmonteit
ID: 17834366
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
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17835911
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
0
 
LVL 14

Accepted Solution

by:
boonleng earned 500 total points
ID: 17838856
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>  
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question