On 12-10-18 01:23 PM, Mark Struberg wrote:
Hi folks!

We already discussed this as part of another thread, but it's time to find a 
final solution

What we have so far:

in CODI we have interface + annotation based view configs:

https://cwiki.apache.org/confluence/display/EXTCDI/JSF+Usage#JSFUsage-TypesafeViewConfig

You basically write your page structure as interface with sub-interfaces and 
annotate them with features you like to get.
A nice feature is that you can write JSF actions like the following

   Class<? extends ViewConfig> doSomething() {
     ....
     return Admin.EditCustomer.class;
   }

Say goodbye to any clumsy String handling...


In Seam3 there is a way to write Enums for approaching something similar. 
Someone has a link for the docs and might join in to explain the strengths and 
weak spots of this approach?

Seam Faces ViewConfig docs are here:
http://docs.jboss.org/seam/3/faces/latest/reference/en-US/html/viewconfig.html

As you pointed out, the Seam Faces approach uses enums rather than the CODI approach with interfaces (although those enums are in turn defined within an interface). The enum approach is more concise (and possibly more intuitive) than using "Interface.class" as your constant value. However interfaces are nice in their support for inheritance, and CODI makes use of this inheritence for grouping of pages.

The Seam Faces solution for grouping of pages has two approaches. First the wildcard support:

Consider this enum which can be used to consider faces-redirect, security, url-rewriting, and transaction support for all "admin" pages:

        @FacesRedirect
        @ViewPattern("/admin/*")
        ...
        ADMIN;

What we lose with the wildcard configuration is support for type-safe navigation. One would have to define an enum for each type-safe navigation result. The Seam Faces solution for grouping of pages in this scenario was to define the annotations on the top level enums. Something like:

@ViewConfig
public interface Pages {

    @FacesRedirect
    static enum Public {
        SEARCH,
        ITEM,
        ALL;
    }

    @FacesRedirect
    @Admin // Security annotation
    static enum Admin {
        ADMIN,
        ITEM,
        ALL;
    }

}

In summary, the two important aspects to take from the Seam Faces approach are the idea of wildcard support, so one can configure views without the requirement to maintain a interfaces/enum/class for each view. Secondly the concise nature of the enums would be a benefit for type-safe navigation.

Brian

Reply via email to