简体   繁体   中英

Play Framework Form Submission

I have followed the java play framework tutorial and created the todo task list that is the result of this tutorial:

http://www.playframework.org/documentation/2.0.4/JavaTodoList

I wanted to modify this project slightly so that instead of having label input the form I had two other inputs, starting location and end location.

Firstly I included the extra variables I required in the java class in Models/

    @Id
    public Long id;

    @Required
    public String starting_location;

    @Required
    public String end_location;

I also added this to the index.scala.html file:

@form(routes.Application.newJourney()) {

    @inputText(journeyForm("Starting Location"))
    @inputText(journeyForm("End Location")) 
    <input type="submit" value="Create">
}

I get the form fields "Starting Location" and "End Location" displaying as expected but when I click on submit the total number of journeys (or tasks for as described in the play example) does not increment and does not get added to the list of current journeys that can be deleted.

Any help is appreciated and I can post full source if required.

Thanks

The helper inputText is documented here .

You put there a label where the field name should be.

This should work:

@inputText(
    journeyForm("starting_location"), 
    '_label -> "Starting Location"
)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM