2

How to set a selectbox value in jsp from controller.

Employee employee = new Employee();

I created new object for entity Employee and then set the value of designation with this code..

employee.setEmpDesignation(addEmployeeForm.getEmpDesignation());

Here is the jsp

<form:select path="empDesignation" id="emplDesignation" onchange="showTextBox();" cssClass="textBox">
    <c:forEach var="desig" items="${designation}">
        <option value="${desig.designationDesc}">
              <c:out value="${desig.designationDesc}"/>
        </option>
    </c:forEach>
</form:select>

Basically I am trying to set the values entered by the user,when error occurs.

But it always displays the first value in the selectbox.

1

1 Answer 1

1

Why are you not using <form:options> ?

E.g:

<form:select path="empDesignation">
    <form:options items="${designation}" itemLabel="designationDesc" itemValue="designationDesc"/>
</form:select>

if your form backing object is bound, SpringMVC should handle all this for you.

Sign up to request clarification or add additional context in comments.

1 Comment

You're welcome. I've just recently gone through the pain of learning SpringMVC myself, so I can sympathise! :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.