2

In my struts2 action that prepares the ftl page i have

private static List<Product> listOfProducts;

with getter and setters. This list is filled with products. First product in the list has type B.

In ftl page I am iterating over the list of products

<#list listOfProducts as product>
<select name = product[0].type>
  <option value="A">fistType</option>
  <option value="B">secondType</option>
  <option value="C">thirdType</option>
</select>
</#list>

Problem is that firstType is preselected each time even if in the list i have a product with type B.

Can you tell me what am i missing here? Why option B was not selected when the ftl is loaded?

Thanks

gospodin
  • 1,133
  • 4
  • 22
  • 42

2 Answers2

1

See http://www.w3schools.com/tags/tag_select.asp on the correct syntax for a select

The attribute "name" sets the name of the control - it does not influence the selection

See How can I set the default value for an HTML <select> element? on how to do that

Community
  • 1
  • 1
Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
0

Use Struts select tag.

<@s.select theme="simple" name="selectedProduct" list="listOfProducts" listKey="productId" listValue="productName" value="defaultProduct"/>

Please go through the example in below link for more understanding.

http://www.mkyong.com/struts2/struts-2-sselect-drop-down-box-example/