preeth
preeth

Reputation: 365

why form filed (type = file) value missing in field after validation failure in Spring mvc

i have a browse button and a text box.when we browse a file and give some value in the text box then its alright. but when we left either browsing a file or filling up the text box then it will ask validation as saying that a file must be uploaded or text box must be filled respectively. but here my problem is when i upload a file and left the text box then if i go for validation then it will as for text box to be filled up with some values but as well file path which uploaded in browse button also missing after validation fails like this. here is my code:

<form:form id="command" method="POST" enctype="multipart/form-data"
                commandName="project" modelAttribute="project"
                action="onsubmit.htm">
<c:forEach var="ivrsFile" items="${project.ivrsFiles}"
                            varStatus="status">
                            <tr class="filerowclass">

                                <c:if test="${fn:length(ivrsFile.fileName) > 0}">
                                    <td width='265px' class="browsebutton1"><span
                                        class="browse-text">File <c:out
                                                value="${status.index+1}"></c:out>:
                                    </span> <form:hidden path="ivrsFiles[${status.index}].fileID" /> <span
                                        class="browselist-item" style="display: none"> <input
                                            style="display: none" type="file"
                                            name="ivrsFiles[${status.index}].file" /> <span
                                            class="description"> <form:input
                                                    path="ivrsFiles[${status.index}].fileName" readonly="true" /></span></span>
                                    </td>
                                    <td>Description: <form:input
                                            path="ivrsFiles[${status.index}].fileDescription" />
                                    </td>
                                    <td valign='middle'><a href="#" class='delete-file'>Delete
                                            file</a></td>

                                </c:if>

can any one tell me how to retain my value in the browse text box even when the validation fails for the text box beside that. thanks in advance

Upvotes: 0

Views: 1034

Answers (1)

Markus Malkusch
Markus Malkusch

Reputation: 7868

You can't set a value for an upload (i.e. <input type="file" />). This is a (security) feature by design of HTML. If you want to keep that uploaded file you have to store it in the session and redesign your controller to use a previously stored file from the session.

Upvotes: 1

Related Questions