java - Bean Validation What's wrong? All the time result.hasErrors () == true -
all time result.haserrors () == true
. what's wrong? if enter values in fields on page, restarts. necessary empty when entering rebooted, if enter fields moved page. validation class
public class createcoursedto { @notnull private string name; @notnull private string category; @notnull private string description; @notnull private string links; public createcoursedto() {} public string getname() { return name; } public void setname(string name) { this.name = name; } public string getdescription() { return description; } public void setdescription(string description) { this.description = description; } public string getlinks() { return links; } public void setlinks(string links) { this.links = links; } public string getcategory() { return category; } public void setcategory(string category) { this.category = category; } }
this controller:
@requestmapping(value = "/create", method = requestmethod.post, params = { "titlefield", "descriptionfield", "linksfield", "categoryfield" }) public string createcoursepost(model model, httpsession session, httpservletrequest request, @valid createcoursedto course3, bindingresult result) { model.addattribute("email", session.getattribute("email")); string title = request.getparameter("titlefield"); string description = request.getparameter("descriptionfield"); string links = request.getparameter("linksfield"); string category = request.getparameter("categoryfield"); if (result.haserrors()) { model.addattribute("email", session.getattribute("email")); user user = userservice.read(session.getattribute("name") .tostring()); model.addattribute("listcategories", categoryservice.getall()); model.addattribute("abilitycreate", "true"); return "create"; } else { model.addattribute("email", session.getattribute("email")); course course = new course(); course.setname(title); course.setdescription(description); course.setlinks(links); course.setcategory(category); course.setstate("draft"); course.setowner(session.getattribute("email").tostring()); course = courseservice.create(course); return "redirect:/courses"; } }
page freemarker
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"/> <link rel="stylesheet" type="text/css" href="./css/style.css"/> </head> <body> <div class="container"> <header> <h1> create course <div class="logout"> <span id="currentuserlogin"> ${email} </span> <a href="logout.html"> <i class="icon-off"></i> </a> </div> </h1> </header> <#if abilitycreate=="false" > <div class="alert alert-error"> <div> <strong>okay, houston, we've had problem here.</strong> </div> <ul> <li>action not allowed. again please.</li> </ul> </div> <#elseif abilitycreate=="true"> <form class="form-horizontal" commandname="course3" method=post> <fieldset> <div class="control-group"> <label class="control-label">name</label> <div class="controls"> <input id="titlefield" name="titlefield" class="span5" type="text"/> </div> </div> <div class="control-group"> <label class="control-label">category</label> <div class="controls"> <select id="categoryfield" name="categoryfield" class="span5"> <option></option> <#list listcategories category> <option>${category.category}</option> </#list> </select> </div> </div> <div class="control-group"> <label class="control-label">description</label> <div class="controls"> <textarea id="descriptionfield" name="descriptionfield" class="span5" rows="3"></textarea> </div> </div> <div class="control-group"> <label class="control-label">links</label> <div class="controls"> <textarea id="linksfield" name="linksfield" class="span5" rows="3"></textarea> </div> </div> <div class="form-actions"> <button id="createbutton" name="createbutton" class="btn btn-primary" type="submit">create</button> </div> </fieldset> </form> </#if> <a class="btn" href="courses.html">cancel</a> </div> </body> </html>
Comments
Post a Comment