Play framework form validation errors

I post as I work my way through the Play material. I have not still read The reactive manifesto and relate it to Play. So I used the same classic trick popularized by Struts to debug this. As far as this type of error display mechanism is concerned I did not find anything different between Play and old versions of Struts.

Problem

I did not initialize isApproved to false.

package models;

import javax.persistence.*;
import javax.validation.Valid;

import play.data.validation.Constraints.MaxLength;
import play.data.validation.Constraints.MinLength;
import play.data.validation.Constraints.Required;
import play.db.ebean.*;

@Entity public class Proposal extends Model {

	@Id
	public String id;
	
	@Required public String title;
	
	@MinLength(value = 10)
	@MaxLength(value = 1000)
	@Column(length=1000)
	public String proposal;
	
	@Required public SessionType type = SessionType.OneHourTalk;
	
	@Required public Boolean isApproved;
	
	public String keywords;
	
	@Valid
	@OneToOne(cascade=CascadeType.ALL)
	public Speaker speaker;
}

Display errors

@(proposal: play.data.Form[Proposal])

@import helper._


@main("New Proposal"){

	@if(proposal.hasErrors) {
        <div class="alert alert-error">
            @proposal.errors
        </div>
	}

	@form(action = routes.MainController.submitProposal()){
	<h3>Proposal</h3>
    @inputText(proposal("title"))
    @textarea(proposal("proposal"))
    @inputText(proposal("keywords"))
	<h3>Speaker</h3>
    @inputText(proposal("speaker.name"))
    @inputText(proposal("speaker.email"))
    @textarea(proposal("speaker.bio"))
    @inputText(proposal("speaker.twitterId"))
    @inputText(proposal("speaker.pictureUrl"))
    
	<p class="submit">
				<button type="submit" class="button green" id="submitForm">Submit</button>
	</p>
    }
}

Error message

I can customize it but this sufficed.

Screen Shot 2014-02-23 at 5.14.17 PM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: