Pita
Pita

Reputation: 508

Populate DropDown Menu in Java Code with XML

I am writing a Java Program that is being used Web Based with HTML and Wicket. Now, I need to create a Drop Down Menu in Java, but then populate the actual options in the Drop Down Menu with an XML File.

First of all, I have created some XML Code.

<item>
    <label>Send to SugarCRM</label>
</item>

<item>
    <label>E-Mail Data</label>
</item>

<item>
    <label>Print Data</label>
</item>

Is that correct, and if so, how do i link it to the Java Drop Down?

Upvotes: 0

Views: 2791

Answers (1)

Mohan Singh
Mohan Singh

Reputation: 359

First you need to parse the XML file, this link would help,

http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/

Now , follow the parsing example , and create a function which returns a list of value (in you case , its not nested , so it will return list of strings ) , then iterate over the list using "JSTL"

like this:

`

<%

List<String> lst = YouClass.getStringFromXML(); //function should return list of values from xml


%>

    <select name="">

      <c:forEach var="data" items="${lst}">    

        <option value="x">data</option>

      </c:forEach>

  </select> 

Upvotes: 1

Related Questions