java - Why is bindFromRequest using the wrong form? -


i have 2 pages, 1 entering questions , 1 entering answers. therefore 2 forms used, send content (question or answer) index page. put newly created question / answer database.

but strangely enter goes question table. due typo somewhere or bindfromrequest not working intended?

controller class application.java:

static list<question> questionlistall = new arraylist<question>(); static list<answer> answerlistall = new arraylist<answer>();  private static final form<question> newquestionform = form.form(question.class); private static final form<answer> newanswerform = form.form(answer.class);  // go ask question page public static result askquestion(){     list<question> questionhelper = new arraylist<question>();     (question questionitem : question.find.all()) {         questionhelper.add(questionitem);     }     return ok(views.html.frageantwort.render(newquestionform, questionhelper)); }  // send question indexpage public static result sendquestion(){     // create new question-form , fill values other page     form<question> boundquestion = newquestionform.bindfromrequest();     question newquestion = boundquestion.get();     question.create(newquestion);     questionlistall.add(newquestion);     return ok(views.html.index.render(questionlistall, answerlistall)); }  // write answer, goto answerpage public static result writeanswer(){     list<answer> answerhelper = new arraylist<answer>();      (answer answeritem : answer.find.all()) {         answerhelper.add(answeritem);     }     return ok(views.html.antwortgeben.render(newanswerform, answerhelper)); }  // send answer indexpage public static result sendanswer(){     form<answer> boundanswer = newanswerform.bindfromrequest();     answer newanswer = boundanswer.get();     answer.create(newanswer);     answerlistall.add(newanswer);     return ok(views.html.index.render(questionlistall, answerlistall)); } 

my antwortgeben.scala.html view class, can enter new answer:

@import models.question @import models.answer @import helper._ @import helper.twitterbootstrap._  @(answerform: form[answer], answerlist: list[answer])  @main("antwort geben"){  @helper.form(action = routes.application.sendanswer()){     <fieldset>         @helper.inputtext(answerform("answerid"))         @helper.inputtext(answerform("questionid"))         @helper.inputtext(answerform("answertext"))         @helper.inputtext(answerform("votescore"))         @helper.inputtext(answerform("userid"))     </fieldset>     <input type="submit" class="btn btn-default">     } } 

my frageantwort.scala.html view class, can enter new questions:

@import models.question @import models.answer @import helper._ @import helper.twitterbootstrap._  @(questionform: form[question], questionlist: list[question])  @main("frage stellen"){  @helper.form(action = routes.application.sendquestion()){     <fieldset>         @helper.inputtext(questionform("questionid"))         @helper.inputtext(questionform("questiontext"))         @helper.inputtext(questionform("votescore"))         @helper.inputtext(questionform("userid"))     </fieldset>     <input type="submit" class="btn btn-default">     } } 

my routes.conf:

# home page     /                           controllers.application.index()  #questions     /fragestellen               controllers.application.askquestion() post    /                           controllers.application.sendquestion()  #answers     /antwortgeben               controllers.application.writeanswer() post    /                           controllers.application.sendanswer() 

so when go page can enter new answer, type form answerid, ... , when click button, every input goes question-table in db.

i have googled solution. did activator clean ... activator compile ... activator run , cleaned in scala ide (eclipse).

using play framework 2.3.8 , scala ide 4.0.0.

why every input go question table in db?

try mapping sendanswer new url test. change

post    /         controllers.application.sendanswer() 

to like:

post    /antwort  controllers.application.sendanswer() 

in routes file requests have priority. looks first post / route takes precedence , why never sendanswer() method


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -