Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to create a drop down list of links from an Oracle Database column  RSS feed

 
Rob Singley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a list that drops down on the page when a link is clicked.
So the page displays:

Items

then when clicked items creates a drop down list of links that looks like:

Items
Item 1
Item 2
Item 3
Item 4

The item values are coming from a field in an Oracle database.
This is the code that I am using that isn't working. Is there something wrong with the while loop?

<%
while(choices.next())
{
if (choices.getString(1).equals("consulting"))
{
%>

<ul id="collapsibleList">

<script type="text/javascript">
document.write('<img id="emailImage1" src="down.png" width="15" height="8" alt="Open list" onKlick="togglecon(\'emailImage1\',\'consulList\');"> Consulting');

</script>



<ul type="square" id="consulList">
<%

while (choices.getString(1).equals("consulting"))
%>
{
out.print("<li><a href="emailer.jsp?viaName=<%=URLEncoder.encode(choices.getString(3))%>"> <%=choices.getString(2)%></a></li>");
}
%>
</ul>

</ul>
<script type="text/javascript">
document.getElementById('collapsibleList').style.listStyle="none"; // remove list markers
document.getElementById('consulList').style.display="none"; // collapse list
// this function toggles the status of a list
function togglecon(image,list){
var listElementStyle=document.getElementById(list).style;
if (listElementStyle.display=="none"){
listElementStyle.display="block";
document.getElementById(image).src="up.png";
document.getElementById(image).alt="Close list";
}else{
listElementStyle.display="none";
document.getElementById(image).src="down.png";
document.getElementById(image).alt="Open list";
}
}
</script>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code that I am using that isn't working.


It might be helpful if you would define "isn't working".

Is the expected HTML being sent to the browser?
 
Rob Singley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about that....

The browser never comes back when I try and load the page...just a blank page....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just a blank page....


That's a bit more than just not working. And it can't be caused by a problem wioth the loop since there is HTML outside of the loop(s) that would've been sent to the browser. Are you checking the HTML source? Is it totally blank as well? Or are you just talking about the displayed page?

Any log messages? Console messages?
 
Rob Singley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The browser itself never recovers...no error messages and the status bar stays at about half way...

If I take out the below section:

<ul type="square" id="consulList">
<%

while (choices.getString(1).equals("consulting"))
%>
{
out.print("<li><a href="emailer.jsp?viaName=<%=URLEncoder.encode(choices.getString(3))%>"> <%=choices.getString(2)%></a></li>");
}
%>
</ul>

and put in:
<ul type="square" id="consulList">
<li><a href="emailer.jsp?viaName=<%=URLEncoder.encode(choices.getString(3))%>"> <%=choices.getString(2)%></a></li>
</ul>

It does load the page correctly and bring me back one column value from my database. It just won't create a list with all of my values. This is why I tried to put the while loop in....
I'm a bit inexperienced at jsp so I may be going down the wrong track trying to get this list to display....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you have a JSP compilation error, do you get the error message? It may just be that there's a JSP syntax error.
[ September 28, 2004: Message edited by: Bear Bibeault ]
 
Rob Singley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I never see a compilation error...but it could very well be a jsp syntax error...I tried to construct my while loop from things I have read on the net....I thought it should have been fairly simple to do since I was already getting values returned....
I just wanted to have my code display all the values from the database not just one....

Thanks...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't run before you walk. If your setup has problems such that when you have a JSP syntax error, you cannot see the error messages, you have no chance of being successful.

First things first. Set up a simple dummy JSP page. Once you get it working, deliberately add a JSP syntax problem. Until you can see the error messages all you can do is stab in the dark when a problem occurs.
 
Rob Singley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that I figured out what is causing the problem...but I'm not sure of the proper way to code the fix....

Right now my jsp is displaying:

Consulitng
Item 1

Consulting
Item2

When I want it to display

Consulting
Item 1
Item 2

As I understand things the while will loop until the condition no longer exists, so right now I have two entries in my database therefore it is running through all of my code(including the Javascript) twice.

What I need it to do is to execute this line ( <li><a href="emailer.jsp?viaName=<%=URLEncoder.encode(choices.getString(3))%>"> <%=choices.getString(2)%></a></li> until all of the entries are displayed....

But I don't think I can add a while statement within another while statement.....

I am a beginner so this is a bit of a learning curve for me....

Any help is appreciated....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I don't think I can add a while statement within another while statement.....


Why not? That's just basic Java.

Let's get back to basics. Please describe the data structures that are available on your page that contains the data that you are trying to display. Then re-post the code that is on your JSP using UBB code tags to preserve the formatting. I will not read unformatted code.

Simplify your JSP code as much as possible. Why, for example, are you using document.write in script to generate static text? Why are you using out.print() rather than template text? I think you are just making things hard for yourself.
[ September 29, 2004: Message edited by: Bear Bibeault ]
 
Rob Singley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well...I tried a few ways to get a while loop to work within this section of the code and had no luck....

There are three main structures that are available on this page. They are:

choices.getString(1) - This retrieves data from a TYPE field in my database. There are many different values for TYPE within the database, the section I am working with anything with a value of consulting in this field.

choices.getString(2) - This retrieves data from a NAME field.

choices.getString(3) - This retrieves data from a QUOTE field.

The page is suppose to function in that when it is loaded Consulting appears as a heading with an arrow beside it. When the arrow is clicked the values for the NAME field are displayed below Consulting as links. When you click on one of the links the value of the QUOTE field is populated into a text box.
This is all functioning, except for how the links are actually getting displayed.


I use the document.write to display the arrow to do the drop down toggle. So when you click on it the list of links is displayed.
The out.print was used when I was trying a few different things to get the While loop to work. I have removed it and included my updated code below.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!