playframework - When I uploading data, doubles fields Play framework -
i don't know why, when calling save
method, fields come me "title, title", "body, body". why happening?
here method:
public static void save(news news, file img) { if (img != null) { try { fileutils.deletedirectory(new file(news.imagepath)); string projectroot = play.configuration.getproperty("my.file.path"); string filename = string.format("%s.%s",randomstringutils.randomalphanumeric(8), "jpg"); fileutils.movefile(img, new file(projectroot, filename)); news.imagepath = projectroot + filename; } catch (ioexception e) { e.printstacktrace(); } } news.createdate = new date(); system.out.println("save" + news.id + " " + news.title); news.save(); news(); }
and in html file call method parameters mews
, img
:
#{extends 'main.html' /} <meta charset="utf-8" /> <h1 class="page-header">Редактировать новость</h1> <form action="@{newscontroller.save(news, img)}" method="post" enctype="multipart/form-data"> <input type="hidden" value="${news.id}" name="news.id"> <input type="hidden" value="${news.imagepath}" name="news.imagepath"> <div class="form-group"> <div class="row"> <div class="col-xs-6"> <label class="control-label">Заголовок</label> <input type="text" class="form-control" value="${news.title}" name="news.title" /> </div> </div> </div> <div class="form-group"> <label class="control-label">Содержимое</label> <textarea class="form-control" name="news.body" rows="8">${news.body}</textarea> </div> <a href="#" id="pop"> <img id="imageresource" src="http://androidnewspad.com/wp-content/themes/motion/images/genericlogo.png""> click enlarge </a> <div class="form-group"> <label class="control-label">Изображение</label> <div class="row"> <div class="col-xs-6"> <input id="file-0a" class="file" type="file" value="${img}" name="img"> <br> </div> </div> </div> <button type="submit" class="btn btn-default">Сохранить</button> </form>
Comments
Post a Comment