Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 955
  • Last Modified:

struts tiles / nested taglib exception

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
tmonteit
Asked:
tmonteit
  • 2
1 Solution
 
boonlengCommented:
> 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
 
tmonteitAuthor 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
0
 
jaggernatCommented:
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
 
boonlengCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now