• 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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.
 
Marshal
Posts: 67164
169
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
Marshal
Posts: 67164
169
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!