Really nice feature, Dan.

There are a lot of use cases out there (including in our domain) that will 
benefit from it.

While executing a BDD tests, I noticed that the "business rule" that requires 
to only being able to select one of the possible choices was not forced for 
"wrapped" objects, so I understand that it's only currently forced by viewers.

So it's possible to assign to a wrapped action a param value that is not on the 
choices. I only achieved to force that by means of a "validateXXX" method, 
whose implementation included to verify that the param's value was on the 
Collection returned by the "choicesXXX" method.

As the choices and auto-complete param validations can be "computationally 
expensive" (requires querying the database and validating that the value is 
included on the returned resultset), and the same can happen to other business 
rules validations, it could be considered to create a new annotation named 
similar to "@ValidationScope({DOMAIN, VIEWER, OBJECTSTORE})".

What do you think?

Thanks,

Oscar





El 23/08/2013, a las 19:40, Dan Haywood <[email protected]> 
escribió:

> Folks,
> just to let you know of a new (rather overdue) feature that I've just
> committed [1], which is the ability to set up conditional choices and also
> defaults.
> 
> Examples are:
> - category/subcategory... where the subcategory depends on the parent
> category, or
> - country/state ... where the state depends on the country.
> 
> You can see an example of the first in Isis ToDo app [2], eg:
> 
> public ToDoItem updateCategory(
>            final ToDoItem item,
>            final @Named("Category") Category category,
>            final @Named("Subcategory") Subcategory subcategory) {
>        item.setCategory(category);
>        item.setSubcategory(subcategory);
>        return item;
>    }
> 
>    public Category default1UpdateCategory(
>            final ToDoItem item) {
>        return item.getCategory();
>    }
>    public Subcategory default2UpdateCategory(
>            final ToDoItem item) {
>        return item.getSubcategory();
>    }
> 
>    public List<Subcategory> choices2UpdateCategory(
>            final ToDoItem item, final Category category) {
>        return Subcategory.listFor(category);
>    }
> 
> 
> Note how the choices method now takes parameters; it can therefore see the
> current value of the category.
> 
> Similarly, you can see an example fo the second in Estatio [3], eg:
> 
>    public CommunicationChannelOwner newPostal(
>            final @Named("Owner") CommunicationChannelOwner owner,
>            final @Named("Type") CommunicationChannelType type,
>            final Country country,
>            final State state,
>            final @Named("Address Line 1") String address1,
>            final @Named("Address Line 2") @Optional String address2,
>            final @Named("Postal Code") String postalCode,
>            final @Named("City") String city) {
>        communicationChannels.newPostal(owner, type, address1, address2,
> postalCode, city, state, country);
>        return owner;
>    }
>    ...
>    public CommunicationChannelType default1NewPostal() {
>        return choices1NewPostal().get(0);
>    }
>    public Country default2NewPostal() {
>        return countries.allCountries().get(0);
>    }
>    public List<State> choices3NewPostal(
>            final CommunicationChannelOwner owner,
>            final CommunicationChannelType type,
>            final Country country) {
>        return states.findStatesByCountry(country);
>    }
>    public State default3NewPostal() {
>        return states.findStatesByCountry(default2NewPostal()).get(0);
>    }
> 
> Here the type is an entity.
> 
> ~~~
> When I was doing the checkin, I realized that I haven't implemented
> validation checking.  So I've descoped it.  It isn't actually an issue if
> you have choices, because it isn't possible to enter any other value
> anyway.  But in the more general case I can see this might be needed.  If
> anyone discovers a need, raise a new ticket.
> 
> Cheers
> Dan
> 
> 
> [1] https://issues.apache.org/jira/browse/ISIS-478
> [2]
> https://github.com/apache/isis/blob/52bc369a0906a900fbbddf3cd7ae610d75b987a3/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItemContributions.java#L166
> [3]
> https://github.com/estatio/estatio/blob/3bb6e8d1a80b512a5fadf6a0f6268405a81cbbe8/dom/src/main/java/org/estatio/dom/communicationchannel/CommunicationChannelContributedActions.java#L71

Reply via email to