PROBLEM: I cannot access other bean properties in a LOOP. In other words,
I can only access LOOP properties.
EXAMPLE: Say that I have a JSP aware bean called BankCustomer, and the bean
has two properties: Name and an array type property called BankAccount. (My
bean, of course, has set/get methods for Name. In addition, there is a
getBankAcountSize method that returns the size of the bank account array,
and there is a getBankAccount method that takes an integer as an index into
the array.)
The important part of my JSP page looks like this:
<USEBEAN NAME="BankCustomer" TYPE="bank.BankCustomer " LIFESPAN="page">
<SETONCREATE BEANPROPERTY="Name" VALUE="John Smith">
</USEBEAN>
<LOOP PROPERTY="BankCustomer:BankAccount" PROPERTYELEMENT="Account">
Customer Name = <DISPLAY PROPERTY=" BankCustomer:Name"><BR>
Bank Account = <DISPLAY PROPERTY="Account"><BR>
<BR>
</LOOP>
I want to produce output that lists all John's bank accounts (which are
retrieved from a database, let's say), but I what to repeat the customer
name each loop:
John Smith
CHECKING1
John Smith
SAVINGS1
John Smith
SAVINGS2
However, this does not work! It is choking on the Customer Name line in the
loop: I'm using JRun 2.3 on NT 4.0 with IIS. Is this a problem with JRun
or a problem with the JSPs, in general?
The simple work around is to use <% %>:
<LOOP PROPERTY="BankCustomer:BankAccount" PROPERTYELEMENT="Account">
Customer Name = <% BankCustomer.getName() %><BR>
Bank Account = <DISPLAY PROPERTY="Account"><BR>
<BR>
</LOOP>
What's so bad about this? Well, I'm trying to put as much functionality as
possible in the bean, so that I can avoid Java in the JSP. Why? So that I
can capitalize on the LOOP and DISPLAY tags and make the JSP appear like
HTML (to simplify the presentation elements of JSP).
GRIPE: If Sun is going to add LOOP and DISPLAY tags, then they should be
powerful enough to do something simple like this (what I've shown above).
If these new constructs are not powerful and flexible enough, then I think
they should be pulled completely. I don't like mixing these tags with <%
%>.
Your thoughts are welcome.
Vaughn Wine
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".