"Bail . Jeff" wrote:
>
> If I instantiate a bean:
>
> <jsp:useBean id="beanId" scope="session" class="BeanClass" />
>
> Shouldn't I be able to do something like:
>
> <%
> BeanClass newBean = new BeanClass();
> newBean.setName("New Name");
> beanId = newBean;
> %>
>
> At this point, on all subsequent pages I would expect that if I were to use
> the same jsp:useBean tag the object I would get back would be newBean. But
> this doesn't seem to be the case -- it always returns the original bean
> (which does not have the Name propery set). Are you actually allowed to
> change the object reference in this way?
I would suggest using something like
<jsp:useBean id="beanId" scope="session" class="BeanClass" />
<jsp:setProperty name="beanId" property="name" value="New Name" />
instead. This will work.
The reason that what you do doesn't work is that you are not changing the
properties of the bean instance in the session scope; you only change it in
an instance local to the page. If you absolutely want to create a new instance
to replace the current version in the session scope using a scriptlet, use:
<%
BeanClass newBean = new BeanClass();
newBean.setName("New Name");
session.setAttribute("beanId", newBean);
%>
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html