preselect select field with freemarker

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>

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?



See 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

Use Struts select tag.

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

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

Need Your Help

Keep Outlook 2016 Task Pane open when switching emails

javascript email outlook office-addins office-2016

I have a custom task pane for Outlook 2016 written in JavaScript and HTML. I am currently calling an API and passing the email address to get some data back. I then display this data in the Task Pane

Memory saving in multi-dimentional array

java cluster-analysis hierarchical-clustering

Hi i need a multidimentional array to store big number but i am getting heap space error. I have 4gb ram.