Thanks for the response. That was exactly the problem.  I should have
realized that the objects lived in different places (i.e. page context
VS local variable of the generated servlet).

So is there a better way to do this?  My current plan is to move all of
this type of table rendering to a taglib so that I don't need the Java
doing the iteration.

Again thanks for the help.

- Rich

-----Original Message-----
From: Greg Trasuk [mailto:[EMAIL PROTECTED]] 
Sent: Friday, February 22, 2002 11:40 AM
To: 'Tomcat Users List'
Subject: RE: Strange javabean problem


Hi folks:

        Rich, you've put your finger directly on the problem by looking
at the generated code.  Your scriptlet's way of getting the title is to
pull it out of the local variable emp, whereas the getProperties version
is using the JSP's pageContext methods, which end up pulling it out of
whatever scope it was declared in (your useBean didn't declare a scope,
so I think it defaults to 'page' scope, but don't quote me on it).  The
bean in the pageContext is the empty bean that was created by the
useBean tag, not the populated bean that you're getting from the
iterator.

        Try inserting the following into your loop:
    while(iter.hasNext()) {
     emp = (EmployeeBean)iter.next();
     pageContext.setAttribute("emp",emp);               <-- Insert this
line.
                                  
 %>

Cheers,

Greg Trasuk, President
StratusCom Manufacturing Systems Inc. - We use information technology to
solve business problems on your plant floor. http://stratuscom.ca

> -----Original Message-----
> From: Rich Sneiderman [mailto:[EMAIL PROTECTED]]
> Sent: February 22, 2002 12:15
> To: Tomcat Users List
> Subject: RE: Strange javabean problem
> 
> 
> Sorry about that.  I should have included how I declared the
> bean.  The
> <jsp:useBean> tag is the 2nd line in the page, right after the
> <jsp:Page> tag. The full tag reads:
> 
> <jsp:useBean id="emp" class="test.EmployeeBean" />
> 
> I've traced through the servlet code and the bean's getters are being 
> called even in the getProperty cases.
> 
> In the generated servlet code the scriptlet's version of getting the 
> title is:
> 
>   out.print( emp.getTitle() );
> 
> The getProperties version is:
>  
> out.print(JspRuntimeLibrary.toString((((test.EmployeeBean)page
> Context.fi
> ndAttribute("emp")).getTitle())));
> 
> - Rich
> 
> -----Original Message-----
> From: Randy Layman [mailto:[EMAIL PROTECTED]]
> Sent: Friday, February 22, 2002 7:59 AM
> To: 'Tomcat Users List'
> Subject: RE: Strange javabean problem
> 
> 
> 
>       You are not creating a bean named emp for the jsp:getProperty.
You 
> need to use jsp:useBean first (I believe) or use 
> <%=emp.getFirstName()%>.
> 
>       Randy
> 
> > -----Original Message-----
> > From: Rich Sneiderman [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, February 22, 2002 11:39 AM
> > To: Tomcat Users List
> > Subject: RE: Strange javabean problem
> > 
> > 
> > I can't believe we're the only people who have ever seen
> this problem.
> > 
> > I'm still having the problem but I got to the same place
> differently.
> > 
> > I load the data from a data base in a servlet.  The servlet
> reads from
> 
> > the database it creates a javabean for each record and adds it to a
> > ListArray.  I then add the ArrayList to the request object 
> and forward
> 
> > on to my JSP.  It's this ArrayList that I'm iterating through in my
> > JSP when I have the problem.
> > 
> > Again here is my code snippet that fails:
> > 
> > <%
> >   ArrayList la = (ArrayList) request.getAttribute("list");
> >   if ( la != null ) {
> >     Iterator iter = la.iterator();
> >     while(iter.hasNext()) {
> >       emp = (EmployeeBean)iter.next();
> > %>
> > <tr><td><%= emp.getFirstName() %></td>
> >     <td><%= emp.getLastName() %></td>
> >     <td><%= emp.getTitle() %></td>
> > </tr>
> > 
> > <tr><td><jsp:getProperty name="emp" property="firstName" /></td>
> >     <td><jsp:getProperty name="emp" property="lastName" /></td>
> >     <td><jsp:getProperty name="emp" property="title"
> /></td> </tr> <%
> >     }
> >   }
> > %>
> > 
> > Could there be something wrong with the way we're defining our
> > Javabeans?
> > 
> > Please folks.  A little help here.
> > 
> > Thanks in advance.
> > 
> > - Rich
> > 
> > -----Original Message-----
> > From: Michael J. McCormac [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, February 21, 2002 7:45 PM
> > To: [EMAIL PROTECTED]
> > Cc: Rich Sneiderman
> > Subject: RE: Strange javabean problem
> > 
> > 
> > > Hi Folks,
> > > 
> > > I'm using Tomcat 4.01 with Jbuilder 6.  I've got a
> strange problem.
> > > It seems that if I try to dump data from a Java bean using the
> > > <jsp:getProperty> tag I don't get the data.  However, if I
> > reference
> > > the value of the bean directly in a scriptlet it works fine.
> > 
> > greetings all,
> > 
> > i am having pretty much the same problem, but the
> implementation is a
> > little bit different.  i tried using an rmi process to retrieve the
> > bean directly from the JSP like so:
> > 
> > <jsp:useBean id='myBean' class='beans.MyClass' />
> > <%
> >     rmiInt rmiServer = (rmiInt)Naming.lookup( "//server/service" );
> >     myBean = (MyClass)rmiServer.getBean();
> > %>
> > <jsp:getProperty name='myBean' property='lastName' />  <- doesn't 
> > work!
> > 
> > one way i've managed to work around the problem was by creating and
> > loading the beans in a servlet first, throwing the beans in the 
> > session object, then redirecting to the JSP file where i could pull 
> > them back out of the session like this:
> > 
> > <jsp:useBean id='myBean' class='beans.MyClass' />
> > <% session.getAttribute( "mybean" ); %>
> > <jsp:getProperty name='myBean' property='lastName' /> <- works ok!!
> > 
> > but i don't like this solution...  it's inelegant ;)
> > 
> > thanks,
> > mike
> > 
> > 
> > --
> > To unsubscribe:   
> <mailto:[EMAIL PROTECTED]>
> > For additional commands:
> <mailto:[EMAIL PROTECTED]>
> > Troubles with the list:
> <mailto:[EMAIL PROTECTED]>
> > 
> > 
> > --
> > To unsubscribe:   
> <mailto:[EMAIL PROTECTED]>
> > For additional commands:
> <mailto:[EMAIL PROTECTED]>
> > Troubles with the list:
> <mailto:[EMAIL PROTECTED]>
> > 
> 
> --
> To unsubscribe:   <mailto:[EMAIL PROTECTED]>
> For additional commands: <mailto:[EMAIL PROTECTED]>
> Troubles with the list: <mailto:[EMAIL PROTECTED]>
> 
> 
> --
> To unsubscribe:   <mailto:[EMAIL PROTECTED]>
> For additional commands: <mailto:[EMAIL PROTECTED]>
> Troubles with the list: <mailto:[EMAIL PROTECTED]>
> 

--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to