having trouble with useBean

I am using a session bean, and then assigning it a value by referring to it by name... but when I use <%=beanName.getMyProperty()%>

I get the value I expect, and when I use <jsp:getProperty name="beanName" property="myProperty">

I get the default/empty bean value of 0.

Here is my code snippet, can anybody see anything wrong with it?

<html>

<head>

<jsp:useBean id="defineSaleBean" scope="session" class="com.ifxonline.drm.core.beans.DefineSaleBean" />

<jsp:useBean id="saleBean" scope="session" class="com.ifxonline.drm.core.beans.SaleBean" />

<jsp:useBean id="saleClientBean" scope="session" class="com.ifxonline.drm.core.beans.ClientBean" />

<jsp:useBean id="saleProductBean" scope="session" class="com.ifxonline.drm.core.beans.ProductBean" />

<%

if (null != saleBean.getSaleClientValue()){

saleClientBean = saleBean.getSaleClientValue();

}

if (null != saleBean.getSaleProductValue()){

saleProductBean = saleBean.getSaleProductValue();

}

%>

</head>

<body>

<jsp:getProperty name="defineSaleBean" property="saleClientLabel" />:

<%=saleClientBean.getClientId()%> (<jsp:getProperty name="saleClientBean" property="clientId" />)

<b><jsp:getProperty name="defineSaleBean" property="saleProductLabel" />: </b>

<%=saleProductBean.getProductId()%> (<jsp:getProperty name="saleProductBean" property="productId" />)

The first printout of the value (the value just after the ':') prints the correct value, the value inside the parenthesis prints out 0 (default empty bean)... I think they should be the same though.

I was under the impression that referring to the bean by name (as in saleClientBean = saleBean.getSaleClientValue();

) will refer to the same instance of the bean as when using a jsp tag (as in <jsp:getProperty name="saleClientBean" property="clientId" />

) and putting the bean name into the "name" value.

Am I wrong?

[2966 byte] By [TonyaBeana] at [2007-10-3 0:36:23]
# 1

Hello,

You seem to be accessing attributes before you have set them.

For example, there are no setter method calls before you use:

<jsp:getProperty name="defineSaleBean" property="saleClientLabel" />:

So it will have the default value, you have never assigned anything else.

You must SET before you get :-)

angrycata at 2007-7-14 17:30:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I know I have to set attributes before I get them... that's not the issue I am seeing... I am setting the entire bean equal to a bean which I know has non-default values in it with the following:

saleProductBean = saleBean.getSaleProductValue();

(saleBean.getSaleProductValue returns a bean)

And in any case, no matter what the values of the attributes are, shouldn't the following code snippets print the same thing?

<%=saleClientBean.getClientId()%>

<jsp:getProperty name="saleClientBean" property="clientId" />

(where the method getClientId() returns the property clientId)

I am concerned that referring to the bean by name, and referring to it with the jsp:getProperty tag do not refer to the same instance... when I thought that it should/would. Is that the case? Or is there some other kind of bug/error? And I am also confused because I never declare the saleClientBean other than with the useBean tag, so if referring to it by name refers to a different instance, I should be getting a compile error.

TonyaBeana at 2007-7-14 17:30:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> saleProductBean =

> saleBean.getSaleProductValue();

You cannot do this, you are trying to assing the value of a method to a class.

You could do something like saleProductBean.setParameter = saleBean..getSaleProductValue()

Like I said, you need to use get and set methods properly.

angrycata at 2007-7-14 17:30:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Also, when you try to assign values from one object to another in teh way you describe, you are actually just assigning a reference in memory, not the actual values in a separate copy.
angrycata at 2007-7-14 17:30:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
http://www.oreillynet.com/pub/a/oreilly/java/news/jsptips_1100.htmlCheck out section 7 for an explaination for what is happening.
tolmanka at 2007-7-14 17:30:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

tolmank,

thanks, that explained exactly what was going on and

<%pageContext.setAttribute("saleClientBean", saleBean.getSaleClientValue());%>

in place of

<%saleClientBean = saleBean.getSaleClientValue();%>

works perfectly.

Tonya

TonyaBeana at 2007-7-14 17:30:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...