简体   繁体   中英

how to pass jstl values in spring mvc in commandObject/modelAttribute of form

In my form I am showing all the attributes of the object for the user to edit and update. Like for example, I am passing the car object to the jsp and then using

    <td><form:input type="text" id="carType" path="carType"
                                            maxlength="15" size="20" /></td>

Now the user is able to edit it and once update button is clicked, I submit the form

    <form:form method="POST" id="formObj" action="updateCar"
                        modelAttribute="carObject">

Now, I don't want user to be able to edit some attributes, like id,make and model. So I used jstl to display those values as lable and not in text boxes. So I used

    ${carObject.carId}

The value is rendered on the page and is visible. Now the problem is when the form is submitted, the values in text box are present in the form object but the values in jstl are lost and are not a part of form object in the controller.

I don't want to use text box for uneditable values with disabled feature. I want to use jstl. Please help.

You can put a hidden input with the values that you don't want to update like:

<input type="hidden" id="id" value="${carObject.carId}" />

After that the property id will be a part of your object in the controller layer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM