Search code examples
isis

Is there a way to generate CRUD actions dynamically for my domain objects?


By following the Apache Isis tutorial I had generate the "myApp" application that I'm using to studies purposes.

One thing that I noticed as a surprise is that any action over the domain object need to be predetermined with static inner classes.

I found this very verbose for simple CRUD operations and I looked all over the Apache isis documentation site section and found no way for generating dynamic actions for CRUD operations.

Is there a way to do that? Do I really need to write inner classes for every action that I want for my domain object?


Solution

  • Um, no. Those nested static classes are for if you want to generate type-safe domain events that can then be subscribed to by other objects via the internal event bus. Sorry if that's not clear.

    To write an action, just write a public method, eg:

    public Order placeOrder(Product p, int quantity) { ... }
    

    If all you want is CRUD, then there's no need to write any actions; objects have an edit mode and the user can just change any field.

    For more sophisticated apps we usually suggest that is disabled using @DomainObject(editing=Editing.DISABLED) - or it can be disabled globally for all objects using a setting in the isis.properties configuration file - and write an action to better capture the intent of the user's change to the data.

    Going back to those nested static classes, if you do want an event to be generated, then you can annotate it, eg:

    public static class PlaceOrderEvent extends ActionDomainEvent {}
    @Action(domainEvent=PlaceOrderEvent.class)
    public Order placeOrder(Product p, int quantity) { ... }
    

    this then lets other code subscribe using, eg:

    @Subscribe public void on(Customer.PlaceOrderEvent ev) { ... }
    

    These can be used to veto actions (eg referential integrity at the domain layer) or to perform triggers (eg cascade updates or denormalized data). But those are advanced use cases; generally speaking that sort of stuff gets added later on.

    Hope that helps. For other questions, I recommend you subscribe to the users mailing list, we tend to pick up on questions there faster than here on SO.

    Thx