What I'm looking for is the ability to quickly (DRY!) generate forms for given models, but in a less-controlled way than using CRUD forms/models; for instance, by being able to use crud tags without the full crud controllers/routes, or by strongly customizing them.
Let me explain through an example.
I have a model A than links (ManyToOne) to 2 models, B and C
class public A extends Model {
public String name;
@ManyToOne
public A a;
@ManyToOne
public B b;
}
I would like to be able to write the following routes:
/A/{id}/B/ somecontroller
/A/{id}/C/ some(other?)controller
or even better:
/A/{id}/{submodel}/ somecontroller
And in the corresponding html view be able to do something like:
<div>object.name</div>
#{form action:@save(object.b._key()), enctype:'multipart/form-data'}
#{crud.form object.b /}
<p class="crudButtons">
<input type="submit" name="_save" value="&{'crud.save', type.modelName}" />
<input type="submit" name="_saveAndContinue" value="&{'crud.saveAndContinue', type.modelName}" />
</p>
#{/form}
Where 'object' is not the "b" or "c" instance, but "a", and I can tell #{crud.form /}
which model it should map (in this case, 'b')
Is there any way to achieve something similar?
The question could be solved either:
- is there any simple
#{form MODEL} #{/form}
tag?!
or, by being able to somehow customize more the CRUD eg.
- is there a way to modify the main crud module and override only desired methods (without copying it all!)?
I am afraid I can't achieve this goal by simply overriding a model CRUD controller, maybe I'm wrong but beside reading the CRUD code (which I'm doing), the official doc is a little limited on which methods can be overridden and how...
Related: how to create an html form for a model in playframework
I also just found this google mail thread that seems to go in the customize-crud direction. I was hoping for a more out-of-the-box solution for such a typical need...
See Question&Answers more detail:
os