Results 1 to 6 of 6

Thread: Attribute invalid for tag forEach according to TLD

  1. #1
    Join Date
    Aug 2010
    Posts
    25

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Have you actually checked the tld?! There is no property named 'agents' for the forEach tag. There is an 'items' attribute...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2010
    Posts
    25

    Default

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

  4. #4
    Join Date
    Aug 2010
    Posts
    25

    Default

    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!

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Well how about writing a valid expression {$model isn't valid ${model is...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  6. #6
    Join Date
    Aug 2010
    Posts
    25

    Default

    Quote 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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •