Setting JavaBean ids
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, July 23, 2002 03:18 AM

I have been unsuccessfully trying to set JavaBean ids for a series of objects with a for loop as follows: <% int rows = Sign.getLineNumber(); %> <% for (int y=0; y <%=y%>" scope="session" class="signs.LineBean" /> <% } %> I would like successive LineBean objects to be given ids of: LineBean0, LineBean1, LineBean2, LineBean3 etc but there are always problems with this part of the code at runtime: id="LineBean <%=y%>" I have tried as many methods of incorporating the variable y into the id as I can think of such as id="LineBean+y"    More>>

I have been unsuccessfully trying to set JavaBean ids
for a series of objects with a for loop as follows:


<% int rows = Sign.getLineNumber(); %>

<% for (int y=0; y

<%=y%>" scope="session"
class="signs.LineBean" />

<% } %>

I would like successive LineBean objects to be given ids of:

LineBean0, LineBean1, LineBean2, LineBean3 etc but there
are always problems with this part of the code at runtime:

id="LineBean <%=y%>"


I have tried as many methods of incorporating the variable
y into the id as I can think of such as

id="LineBean+y"

id="LineBean" + y

etc but am getting no further.


I would be grateful if anyone could help.

   <<Less

Re: Setting JavaBean ids

Posted By:   Horatiu_Ripa  
Posted On:   Friday, August 30, 2002 04:24 AM

That will never work.

Take a look to the way the JSP's are translated into servlets (ie. for Tomcat in work directory you can found the servlets for any .jsp of the app if you deployed it as sources).

The translation process is somehow like this:

1. The taglib tags (as jsp:useBean) are translated into java code

2. All the HTML code is translated into "out.write()"

3. All the server side code <%..%> is left as it is


But there is another simple solution to your problem:


<% for (int y=0; y
 session.setAttribute("LineBean" + String.valueOf(y),new signs.LineBean());


%>
About | Sitemap | Contact