DJ180
DJ180

Reputation: 19854

Spring MVC: Display correct value in select drop-down list

My JSP snippet is as follows:

<form:select path="rules[${counter.index}].assignedTo.assignedToName">
    <form:options items="${assignmentRulesForm.assignedToList}"
                  itemLabel="assignedToName"
                  itemValue="assignedToName"/>
</form:select>

The assignedTo property refers to this object:

public class AssignmentDTO {
    private String assignedToName;
    // No other members

assignedToList then is a List<AssignmentDTO>

Really, what I want to happen is for the drop-down to contain all entries in the assignedToList, but to select the value associated with rule[i].assignedto.assignedToName

Presently, what I am seeing is that it does not perform the selection part, and the first item in the drop-down is displayed.

Any help is appreciated.

Thanks

Upvotes: 0

Views: 2033

Answers (2)

Ramkumar
Ramkumar

Reputation: 91

<html>
    <head>
        <script>
            function show() {
                var op= window.document.getElementById('select');
                var selItem= op.options[op.selectedIndex].value;
                if(selItem=="Others") {
                    document.getElementById('text').style.visibility = 'visible';
                }
                else {
                    document.getElementById('text').style.visibility = 'hidden';
                }
            }
        </script>
    </head>
    <select id="select" onchange="show();">
        <option value="A">A</option>
        <option value="B">B</option>
        <option value="C">C</option>
        <option value="D">D</option>
        <option value="E">E</option>
        <option value="Others">Others</option>
    </select>
    <br>
    <input type="text" id="text" style="visibility:hidden">
</html>

Upvotes: 0

Biju Kunjummen
Biju Kunjummen

Reputation: 49915

This should work for you, the path is not the name but the assignedTo:

<form:select path="rules[${counter.index}].assignedTo">
    <form:options items="${assignmentRulesForm.assignedToList}"
                  itemLabel="assignedToName"
                  itemValue="assignedToName"/>
</form:select>

If you have implemented a .equals for your assignedTo, it should just work.

Upvotes: 2

Related Questions