• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Need help with Drop Down list  RSS feed

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an ArrayList that I am creating in a java class containing unix file names. That part is working correctly.
I need to be able to load the ArrayList into a drop down list using an html select.
Any ideas? Could you give me an example? I'm not using struts, jst a jsp using html tags.
 
Author and ninkuma
Marshal
Posts: 66786
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pass the list from your page controller to the JSP as a request-scoped variable, then use the JSTL <c:forEach> tag to iterate over the list and create an <option> element for each entry.
 
Don Martino
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code that I came up with. Everything works except the document.write. Could you show me how to define the option tag where it will print out correctly?

<td>
<select name="anncFile" onChange="">
<script language="JavaScript" type="text/javascript">

<%
ArrayList tarFileList;
tarFileList = (ArrayList) mauMainForm.getTarFileList();
if (!tarFileList.isEmpty()) {
String tarFileName;
int size = tarFileList.size();
for (int i=0; i < size; i++){
tarFileName = (String) tarFileList.get(i);
%>
document.write("<option value="+<%=tarFileName%>+">"+<%=tarFileName%>+"</option>");
<%
}
}
%>

</script>
</select>
</td>
 
Don Martino
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To simplify question. Could somebody show me correct syntax for following document.write?

document.write("<option value="+<%=tarFileName%>+">"+<%=tarFileName%>+"</option>");
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66786
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the document.write at all? It's completely superfluous and just adding complexity for no reason.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!