473,388 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Java using loop let usebean dynamically declare id

Hi guys,

I retrieve books from a database and put each book with its data into a
bean.
this works well, the beans are called bookBeanBeg1, bookBeanBeg2,
bookBeanBeg3, bookBeanBeg4, etc.

then I retrive the first bean from an JSP page with:
Expand|Select|Wrap|Line Numbers
  1. <jsp:useBean id="bookBeanBeg1" type="p4Solution.BookBean" scope="session" />
  2. <jsp:getProperty name="bookBeanBeg1" property="shortDescription"/>
  3.  
and it works fine.

Now I try to make an automatic retrieval with a for loop.
The for cicle works well in I hardcode for example the id="bookBeanBeg1" and
the name="bookBeanBeg1"

Bu there is some problem in using an expression inside the two declarations,
it gives me an error. it doesn't accept the id the name attributes created
by the expression.

can you please help me fix this? thanks
Expand|Select|Wrap|Line Numbers
  1. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  3. "http://www.w3.org/TR/html4/loose.dtd">
  4.  
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8. <title>JSP Page</title>
  9. </head>
  10. <body>
  11. <h2>Hello HTML beginner!</h2>
  12. <%
  13. int numBooks = 
  14. Integer.parseInt(request.getParameter("numBookBeg" ));
  15. %>
  16. <%= numBooks %> books available for you.
  17. <br> <br>
  18. <UL>
  19. <%
  20. for (int i=1; i<=numBooks; i++)
  21. {
  22. String bookBeanBeg;
  23. bookBeanBeg = "bookBeanBeg" + i + "";
  24. %>
  25. <br> <br> NOTE: ERROR BELOW
  26. <jsp:useBean id="<%=bookBeanBeg%>" 
  27. type="p4Solution.BookBean" scope="session" />
  28. <LI><jsp:getProperty name="<%=bookBeanBeg%>" 
  29. property="shortDescription"/>
  30. <% } %>
  31.  
  32. </UL>
  33. </body>
  34. </html>
Apr 14 '08 #1
1 3253
Dököll
2,364 Expert 2GB
Heiya!

I have not yet used id in this fashion 'id="<%=bookBeanBeg%>' could this be your problem?
Dec 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
9
by: Stephen H. | last post by:
Hi, I have an existing web application with java beans that I wanne migrate to ASP.NET using C#. The existing web application has some jsp files that use java beans as follows: .... <%@...
28
by: liorm | last post by:
Hi everyone, I need to write a web app, that will support millions of user accounts, template-based user pages and files upload. The client is going to be written in Flash. I wondered if I coudl...
13
by: Andrew Bell | last post by:
I'm doing a uni course in the UK and one of my semesters is about programming. This is just going to be compilied and executed with no menu just using command promt (javac classfile.class) I am...
1
by: prasath03 | last post by:
I'm new to JSP, and am trying this sample code for instantiating a bean for use in a disconnected ResultSet, i placed the rowset.jar under WEB-INF/lib directory but i get the following error: ...
1
by: hostel | last post by:
HTML PAGE <html> <body> <form action="second.jsp" method="get"> YOur name <input type=text name="name"> <input type=submit > </form> </body> </html>
2
by: vijaykumardahiya | last post by:
Hello Sir, I have a simple Issue but It is not resolve by me i.e input parameter are not store in Ms-Access. I store the input parameter through Standard Action <jsp:useBean>. jsp:useBean call a...
1
by: Alien | last post by:
Hi Guys, I am learning JavaBeans and while playing around with the <jsp setProperty> and <jsp getProperty>, I wanted to try something out. Basically the the bean class has attributes, name,...
2
by: tamasu | last post by:
Hi, I am retrieving a selected item from a list/menu component on an HTML page. The said value is passed as a parameter to a method initiated through <jsp:useBean. I am aware that when...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.