[1.3.1] Using Play's Model with an external business layer

38 views
Skip to first unread message

Pierre Falentin

unread,
Oct 7, 2015, 9:49:12 AM10/7/15
to play-framework
Hi,

For our play projects we are using a business layer as model that we import as a jar. This business layer uses hibernate and we want to keep it independent from Play. We don't use the Model package at all in Play.

Is there a way to use the Play Framework Model functionalities with it ?

Let's take for example this piece of code from the Play documentation :

public static void hello(@Valid User user) {
   
if(validation.hasErrors()) {
       
params.flash();
       validation
.keep();
       index
();
   
}
   render
(name, age);
}

With User being a class mapped to the database in our external jar, could we use @Valid to achieve a similar result ?

Thank you very much.

hans

unread,
Oct 13, 2015, 12:51:08 PM10/13/15
to play-framework
Hi,

The @Valid anotation should work without problems, the framework will search for the play validation annotations in the annotated class in order to apply the validation, if you can't annotate the classes, you can create an annotated Pojo and then use for example BeanUtils,copyProperties to copy properties from one to the other.

I've been using persistence.xml to access other models and it works, i has noting to do with inheriting from Model or GenericModel.

Bye
Reply all
Reply to author
Forward
0 new messages