use collection of javaBean in forEach

Discussion in 'Java' started by quickcur@yahoo.com, Jan 14, 2005.

  1. Guest

    I am writing a jsp tag which stores a collection of javabean in page
    context. I was trying to use this tag in my jsp, but with no success. I
    am using tomcat 5.4

    Here is my code:

    public class man{
    String name;

    public void setName(String name){
    this.name = name;
    }

    public String getName(){
    return name;
    }
    }

    public class ManTag extends TagSupport {

    private String var;

    public int doStartTag(){
    try{
    ArrayList men = new ArrayList();
    for (int i = 0; i < 10; i++){
    Man man = ...
    men.add(man);
    }

    pageContext.setAttribute(var, men);

    }catch(Exception e){
    ....
    }
    return SKIP_BODY;
    }

    public setVar(String var){
    this.var = var;
    }
    }

    Here is my jsp:

    .....//import lab
    <mytaglib:man var="goodman"/>
    <c:forEach items="${goodman}" var="x">

    <c:eek:ut value="${x.name}"/>

    </c:forEach>


    But the server complains that

    javax.servlet.ServletException: Unable to find a value for "name" in
    object of class "XXXXXXX" using operator "."
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:845)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:778)
    org.apache.jsp.test_jsp._jspService(org.apache.jsp.test_jsp:93)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     
    , Jan 14, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. A Bag Of Memes

    Re: Use one javabean for each table?

    A Bag Of Memes, Jul 24, 2003, in forum: Java
    Replies:
    0
    Views:
    457
    A Bag Of Memes
    Jul 24, 2003
  2. tom
    Replies:
    0
    Views:
    381
  3. Tom Dyess
    Replies:
    2
    Views:
    491
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=
    Jan 20, 2005
  4. Øyvind Isaksen
    Replies:
    1
    Views:
    1,028
    Øyvind Isaksen
    May 18, 2007
  5. Replies:
    1
    Views:
    409
    Diez B. Roggisch
    Mar 20, 2009
Loading...

Share This Page