Announcement Announcement Module
Collapse
No announcement yet.
Attribute invalid for tag forEach according to TLD Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Attribute invalid for tag forEach according to TLD

    I am using Spring MVC + JSP and deployed the WAR file in JBoss AS 6. I have a list that the JSP file should output. These are my codes:

    In my Controller, I have:

    Code:
    Map<String, Object> model = new HashMap<String, Object>();
                        List<String> x = new ArrayList<String>();
                        x.add("sample1");
                        x.add("sample2");
                        x.add("sample3");
                        model.put("test", x);
                        return new ModelAndView("details", "model", model);

    In my JSP, I have:

    Code:
    <c:forEach agents="{$model.test}" var="agent">
    </c:forEach>
    After I deploy, when I visit my JSP, it will output an error:

    Code:
    org.apache.jasper.JasperException: /WEB-INF/jsp/details.jsp(46,0) Attribute agents invalid for tag forEach according to TLD
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:236)
    org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1248)
    org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:859)
    org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1530)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2427)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2433)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
    org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1776)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:209)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:358)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:338)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:325)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:607)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:312)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:236)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1183)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:902)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

    I do not know why this is happening. From the examples I researched, these codes should work.

    If I tried to print
    Code:
    ${model.test}
    , the output is:

    Code:
    [sample1,sample2,sample3]
    By the way, I included the following inside my WEB-INF/lib directory
    1. standard-1.1.2.jar
    2. jstl-1.2.jar
    3. spring-2.5.6.jar
    4. org.springframework.web.servlet-2.5.6.A.jar

    Thanks!

  • #2
    Have you actually checked the tld?! There is no property named 'agents' for the forEach tag. There is an 'items' attribute...

    Comment


    • #3
      Thanks! It should be 'items' instead of 'agents'. And thanks for the link!
      Last edited by racumin; Apr 13th, 2011, 01:56 AM. Reason: problem not yet solved

      Comment


      • #4
        Hi, I changed 'agents' to 'items' but it is still not working. Any ideas?

        This is my controller
        Code:
                        List<String> x = new ArrayList<String>();
        		x.add("sample1");
        		x.add("sample2");
        		x.add("sample3");
        		model.put("test", x);
        This is my JSP
        Code:
        <c:forEach var="item" items="{$model.test}">
        	<tr>
        		<td><c:out value="${item}"/></td>
        	</tr>
        	</c:forEach>
        The output is:
        Code:
        {$model.test}
        But if I changed my JSP to this:
        Code:
        <c:forEach var="item" items="{$model.test}">
        	<tr>
        		<td><c:out value="${model.test[0]}"/></td>
        	</tr>
        	</c:forEach>
        It outputs
        Code:
        sample1
        Thanks!

        Comment


        • #5
          Well how about writing a valid expression {$model isn't valid ${model is...

          Comment


          • #6
            Originally posted by Marten Deinum View Post
            Well how about writing a valid expression {$model isn't valid ${model is...
            I didn't see that

            I'm really sorry for wasting your time with these stupid mistakes of mine

            Comment

            Working...
            X