The following extract from the jsp1.2 specification clarifies the behaviour
witnessed by you ::

"The value of the name attribute in jsp:setProperty and jsp:getProperty will
refer to an object that is obtained from the pageContext object through its
findAttribute() method.

The object named by the name must have been "introduced" to the JSP
processor using either the jsp:useBean action or a custom action with an
associated VariableInfo entry for this name.

Note: a consequence of the previous paragraph is that objects that are
stored in, say, the session by a front component are not automatically
visible to jsp:setProperty and jsp:getProperty actions in that page unless a
jsp:useBean action, or some other action, makes them visible. "

Based on the above if you add the following line of code to your jsp
it should generate the output you are looking for :
pageContext.setAttribute("invoice",invoice);

This line of code should come inside the for loop of your jsp and after the
following line of code :
invoice = invoices[i];

Assume this helps :-).
Have a nice day.
With regards,
Sachin S. Khanna
http://www.emailanorder.com
----- Original Message -----
From: Gerry Scheetz <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, April 22, 2001 4:50 AM
Subject: <jsp:getProperty> vs <%= bean.getXxx %>


> I have a JSP file that is
>
> <%@ page import="ChildCare.InvoiceBean"
contentType="text/html;charset=ISO-8859-1" %>
> <jsp:useBean  id="invoice" class="ChildCare.InvoiceBean" />
> <% InvoiceBean[] invoices =
(InvoiceBean[])session.getAttribute("invoices"); %>
>
>     <%
>     for (int i=0; i< invoices.length; i++) {
>        invoice = invoices[i];
>     %>
>
>     <jsp:getProperty name="invoice" property="invoiceNumber" />
>     <BR>
>     <%= invoice.getInvoiceNumber() %>
>     <P>
>
>     <%
>     }
>     %>
>
> </BODY>
> </HTML>
>
> My bean code is
>
> package ChildCare;
>
> public class InvoiceBean implements Serializable{
>   int invoiceNumber;
>
>   /**
>    * Constructor
>    */
>   public InvoiceBean() {
>   }
>
>   public int getInvoiceNumber() {
>     return invoiceNumber;
>   }
>
>   public void setInvoiceNumber(int newInvoiceNumber) {
>     invoiceNumber = newInvoiceNumber;
>   }
> }
>
>   I get a 0 returned from <jsp:getProperty name="invoice"
property="invoiceNumber" />
>   and I get the invoice number from <%= invoice.getInvoiceNumber() %>
>
> I am using Tomcat as my servlet container and JSP engine, apache is my web
server.
>
> Any idea on why I do not get the invoice number using the getProperty
command?
>
> Side note, why do I have to specify my package name (ChildCare) in the
useBean command since I included it in
> my page directive.
>
> Thanks,
>
>
>
> Gerry Scheetz
> Web Application Development
> Global Information Technology Division
> TRW - S&ITG
> Helena, Montana, USA
> [EMAIL PROTECTED]
> (406) 594-1878
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to