I am trying to do renaming of files in a page. I have to perform a GET request on submit of dialog popup for renaming the file. The problem I am facing is, the page has lot of input fields so I cannot submit form everytime I rename a file. The HTML components for file list is generated dynamically. Here is the code snippet -
<div class="modal fade" id="renameModal" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Rename File</h4>
</div>
<div class="modal-body">
<div id="renameForm" class="form-group">
<label class="col-sm-2 control-label" for="inputFname3">FileName: </label><input id="newFilename" type = "text" name = "newFilename"/>
<br />
<input id="confirm-btn" class="btn btn-primary" type = "submit" value = "Confirm" name = "ok" style="float: right" />
<br />
</div>
</div>
</div>
</div>
</div><!-- /modal -->
<%
String str =AdministrationServlet.fileJson(request, collection).toString();
String x = request.getParameter("ok");
if(x!=null && x.equals("Confirm"))
{
AdministrationServlet.renameFile(request,collection.getUuid(),"manifest_text", collection);}
%>
<script type="text/javascript">
$(document).ready(function () {
$('button').click(function(){
var id = this.id;
var res = id.substring("rename-btn-".length,id.length);
$('#renameModal').find('#renameForm').append('<input id="myfieldname" type="hidden" name="myfieldname" value="'+res+'" />');
var oldfilename = $('#myfieldname').val(); <%--"<%=request.getParameter("myfieldname")%>"; --%>
var newfilename = $('#newFilename').val(); <%--"<%=request.getParameter("newFilename")%>";--%>
$('a[id="'+oldfilename+'"]').text(newfilename);
});
});
</script>
How can I perform renaming of files by doing API calls and not submit form. As the entire div is inside a form.
You should made Ajax Call to a Servlet for renaming file. One more thing, you should keep javascript code away from the jsp into a separate js file and include it jsp page using <script>
tag.
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.