Thank you very much Mattias, the change you suggested seems to have
rectified my problem. As I mentioned in my original message the purpose
of this exercise is to learn more about JSPs. Can you suggest a
webstie/tutorial/book that would mention things such as this? Or are
these the sort of things one learns only by trying something, getting
stuck and asking someone more eperienced?
For the record I am attempting to implement a variation od the example
project discussed by Duane K.Fields in his book 'Web Development with
Java Server Pages'. I'd better go through the book again, maybe there's
somehting in here that I missed.
Thank you once more.
Abhijit.
-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]] On Behalf Of Mattias Jiderhamn
Sent: Thursday, July 05, 2001 4:45 PM
To: [EMAIL PROTECTED]
Subject: Re: Newbie Question - jsp:useBean help needed.
> <%@ page import='sample.invoice.*' %>
> <html>
> <head>
> <jsp:useBean id='invoice' class='InvoiceBean'/> <jsp:setProperty
> name='invoice' property='status' value='pending'/> <jsp:scriptlet>
> invoice =
InvoiceRepository.getInstance().getInvoice(1);
> </jsp:scriptlet> <!-- Here, I am attemtpting to initialise 'invoice'
to
> A new InvoiceBean object is retreived from the repository -->
I'll try to explain this and hopefully somebody corrects me if I get
some details wrong. You might need some knowledge about objects and
references/pointers to understand this.
One could say that the beans and the scriplet variables are in different
contexts. When you create a bean you automatically get a scriplet
variable with the same name. Lets call them invoice[bean] and
invoice[scriptlet]
<jsp:useBean id='invoice' class='InvoiceBean'/>
<jsp:setProperty name='invoice' property='status' value='pending'/>
After these two tags both the bean and the scriptlet variable references
the same object. You could say invoice[bean] = invoice[scriptlet] -> an
invoice which is pending.
<% invoice = InvoiceRepository.getInstance().getInvoice(1); %>
This affects ONLY the SCRIPTLET variable. So, the scriptlet variable now
point at a different invoice!
invoice[bean] -> an invoice which is pending.
invoice[scriptlet] -> an invoice from the repository.
I believe that you can make the bean point at the same new object by
using:
pageContext.setAttribute("invoice",invoice); // ("beanName", object)
(Anyone please correct me if I'm wrong).
Good luck.
Mattias Jiderhamn
Expert Systems
[EMAIL PROTECTED]
========================================================================
===
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