Take the 2-minute tour ×

OK, So I am having some issues with getting data from a form to bind to a model class I have.

I have a class Question that basically looks like this:

public class Question extends Model {
     @Id @Required public int id;
     public String title;
     public String body;

So I want to use this as a template for a form for a user to create a question, so I create a static instance (as they do in the samples)

 final static Form<Question> question_form = form(Question.class);

So far so good, everything compiles. The problem comes when I actually submit the form:

 Form<Question> filled_form = new Form<Question>(Question.class).bindFromRequest();

Here I get the error:

 [UnexpectedTypeException: No validator could be found for type: java.lang.Integer]

My thinking on how to proceed is to use a design pattern that goes like this:

1.) Create template classes specifically for Forms, that don't include things like foreign keys, IDs, and information that isn't in a format designed for the user. (i.e. if the Question has a foreign key for Topic, the QuestionForm class would have a String topic field.

2.) Create a methods in the Question model that goes something like getFormForQuestion(Question) and getQuestionForForm(Form<Question>) and then use these methods to do CRUD functions.

So basically the User and controller interact using Forms, and then the Model knows how to take these forms and turn them into entries in the database.

Is this a reasonable way to proceed? Or is there a better way of doing this?


Seems to be fixed when using @GeneratedValue annotation rather than the @Required annotation, but I am still curious regarding my proposed Form Design pattern.

Also just removing @Required appears to fix the problems. Still looking for comments on the mentioned design pattern!

share|improve this question
You don't need id because that is inherited from the Model superclass. –  Dan W Mar 29 '12 at 14:28
Oh awesome, even better I guess. thanks –  wbarksdale Mar 29 '12 at 14:52
Did that solve your problem? Should I post that as an answer for this question? –  Dan W Mar 29 '12 at 14:58
Yeah, that seems to work as well, probably the correct solution rather than using @GeneratedValue annotation, do you think that the design pattern I mentioned there is a good design pattern? –  wbarksdale Mar 29 '12 at 15:36
add comment

1 Answer

up vote 1 down vote accepted

id field doesn't need any validation, ORM will care about it. Of course you should not place id in form (it shouldn't be edited at all - it's common AUTO_INCREMENT) And better make it Long, just:

public Long id;
share|improve this answer
any comments on the design pattern I mentioned? –  wbarksdale Mar 29 '12 at 15:36
@weezybizzle I'm not sure if I understood well, but if no declaration of this field, Ebean doesn't create any ID field... :) which in most cases is just useless. –  biesior Mar 29 '12 at 15:48
Ok, I will post about this design pattern separately. –  wbarksdale Mar 29 '12 at 15:57
add comment

Your Answer


