[seam-issues] [JBoss JIRA] Commented: (SEAMFACES-109) Provide a query API to retrieve components from view metadata

Dan Allen (JIRA) jira-events at lists.jboss.org
Sun Mar 20 01:10:46 EDT 2011


    [ https://issues.jboss.org/browse/SEAMFACES-109?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12589149#comment-12589149 ] 

Dan Allen commented on SEAMFACES-109:
-------------------------------------

Other names for the class might be ViewMetadataAnalyzer, ViewMetadataProcessor or ViewMetadataScanner

If you wanted to take this a step further, you could build a generic query API for retrieving components from the UIComponent tree. In that case, you might break it down into the following concerns:

UIComponentQueryProcessor
   execute(UIComponentQuery query, UIComponent searchRoot)

ViewMetadataQueryProcessor extends UIComponentQueryProcessor
   execute(UIComponentQuery query)

UIComponentQuery
   matches(UIComponent)
   descend(UIComponent)

Just an idea ;)

> Provide a query API to retrieve components from view metadata
> -------------------------------------------------------------
>
>                 Key: SEAMFACES-109
>                 URL: https://issues.jboss.org/browse/SEAMFACES-109
>             Project: Seam Faces
>          Issue Type: Feature Request
>          Components: UI Components
>    Affects Versions: 3.0.0.CR1
>            Reporter: Dan Allen
>            Priority: Minor
>
> The ViewMetadata API only provides a method for retrieving the collection of UIViewParameter components. However, this facet can be used for many other components, such as view actions, view restrictions and so forth. Seam Faces should provide a convenient query API for retrieving any type of component.
> Here is a proposal:
> {code:java}
> public class ViewMetadataQuery {
>     public <C extends UIComponent> Collection<C> findMetadataComponents(UIViewRoot viewRoot,
>             UIComponentFilter<C> componentFilter) { 
>         UIComponent metadataFacet = viewRoot.getFacet(UIViewRoot.METADATA_FACET_NAME);
>        
>         if (metadataFacet == null) {
>             return Collections.<C>emptyList();
>         }  
>         
>         Collection<C> matches = new ArrayList<C>();
>         for (UIComponent candidate : metadataFacet.getChildren()) {
>             if (componentFilter.accepts(candidate)) {
>                 matches.add((C) candidate);
>             } 
>         }  
>         
>         return matches;
>     }   
> }   
>    
> public class UIComponentFilter<C extends UIComponent> {
>     public abstract boolean accepts(UIComponent candidate);
> }
> {code}
> It would be used as follows:
> {code:java}
> @Inject
> private ViewMetadataQuery query;
> ...
> Collection<UIViewAction> viewActions = query.findMetadataComponents(viewRoot, new UIComponentFilter<UIViewAction>() {
>     public boolean accepts(UIComponent candidate) {
>         return candidate instanceof UIViewAction;
>     }
> });
> {code}
> You can simplify this further by providing a version of the method that accepts a type:
> {code:java}
> Collection<UIViewAction> viewActions = query.findMetadataComponents(viewRoot, UIViewAction.class);
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the seam-issues mailing list