0

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.

romil gaurav
  • 1,121
  • 11
  • 23
  • 43

1 Answers1

1

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.

Gerard Ribas
  • 717
  • 1
  • 9
  • 17
  • This will work for id but what about other values that I want to show on the page. – romil gaurav Oct 21 '15 at 14:26
  • Do you need them if the value don't change? You can put it in a input type text readonly and that will be populated on the controller layer, be aware that the HTML Standard don't submit inputs that are on disabled status (see http://stackoverflow.com/a/524238/1228193). Or you can put it in a hidden values as well. – Gerard Ribas Oct 21 '15 at 14:48