[richfaces-issues] [JBoss JIRA] (RF-12226) Support for CDK fragments to allow recursion and abstraction of code

Lukáš Fryč (JIRA) jira-events at lists.jboss.org
Thu May 31 09:31:18 EDT 2012


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

Lukáš Fryč commented on RF-12226:
---------------------------------

Highlights:

* automatic propagation of implicit objects ({{facesContext, responseWriter, component}})
* type-safe definition of attributes
* rendering using {{cdk:renderFragment}} with attribute names equal to attribute names in fragment interface

{code:xml|title=testComponent.template.xml}
<cdk:root xmlns="http://jboss.org/schema/richfaces/cdk/xhtml-el"
          xmlns:cdk="http://jboss.org/schema/richfaces/cdk/core"
          xmlns:c="http://jboss.org/schema/richfaces/cdk/jstl/core"
          xmlns:cc="http://jboss.org/schema/richfaces/cdk/jsf/composite">

    <cc:interface>
        <cdk:class>org.richfaces.renderkit.TestComponentRenderer</cdk:class>
        <cdk:superclass>org.richfaces.renderkit.TestComponentRendererBase</cdk:superclass>
        <cdk:component-family>org.richfaces.TestComponentFamily</cdk:component-family>
        <cdk:renderer-type>org.richfaces.TestComponentRenderer</cdk:renderer-type>
        <cdk:component-base-class>org.richfaces.component.TestComponent</cdk:component-base-class>
    </cc:interface>

    <cc:implementation>
        <cdk:renderFragment name="methodName" attribute2="#{0}" attribute1="#{this.list}"  />
        <cdk:body />
        <cdk:renderFragment name="anotherMethod" condition="true"  />
    </cc:implementation>

    <cdk:fragment name="methodName">
        <cc:interface>
            <cc:attribute name="attribute1" type="List &lt; String &gt;" />
            <cc:attribute name="attribute2" type="int" />
        </cc:interface>
        
        <cc:implementation>
            <cdk:renderFragment name="methodName" attribute1="#{this.list}" attribute2="#{cc.attrs.attribute1.size()}" />
        </cc:implementation>
        
    </cdk:fragment>
    
    <cdk:fragment name="anotherMethod">
        <cc:interface>
            <cc:attribute name="condition" type="boolean" />
        </cc:interface>
        
        <cc:implementation>
            <c:if test="#{cc.attrs.condition}">
                Yes!
            </c:if>
        </cc:implementation>
        
    </cdk:fragment>
    
</cdk:root>
{code}

generates

{code:java|title=org.richfaces.renderkit.TestComponentRenderer}
public void methodName(ResponseWriter responseWriter, FacesContext facesContext, UIComponent uiComponent,
            List<String> attribute1, int attribute2) throws IOException {
        TestComponent component = (TestComponent) uiComponent;
        String clientId = component.getClientId(facesContext);
        methodName(responseWriter, facesContext, component, this.getList(), attribute1.size());

    }

    public void anotherMethod(ResponseWriter responseWriter, FacesContext facesContext, UIComponent uiComponent,
            boolean condition) throws IOException {
        TestComponent component = (TestComponent) uiComponent;
        String clientId = component.getClientId(facesContext);
        if (condition) {
            responseWriter.writeText("Yes!", null);

        }

    }

    @Override
    public void doEncodeBegin(ResponseWriter responseWriter, FacesContext facesContext, UIComponent uiComponent)
            throws IOException {
        TestComponent component = (TestComponent) uiComponent;
        String clientId = component.getClientId(facesContext);
        methodName(responseWriter, facesContext, component, this.getList(), 0);

    }

    private static Boolean convertToBoolean(Object object) {
        if (object instanceof Boolean) {
            return (Boolean) object;
        }

        return Boolean.valueOf(object.toString());
    }

    @Override
    public void doEncodeEnd(ResponseWriter responseWriter, FacesContext facesContext, UIComponent uiComponent)
            throws IOException {
        TestComponent component = (TestComponent) uiComponent;
        String clientId = component.getClientId(facesContext);
        anotherMethod(responseWriter, facesContext, component, convertToBoolean("true"));

    }
{code}
                
> Support for CDK fragments to allow recursion and abstraction of code
> --------------------------------------------------------------------
>
>                 Key: RF-12226
>                 URL: https://issues.jboss.org/browse/RF-12226
>             Project: RichFaces
>          Issue Type: Feature Request
>      Security Level: Public(Everyone can see) 
>          Components: cdk
>    Affects Versions: 4.2.1.Final
>            Reporter: Lukáš Fryč
>            Assignee: Lukáš Fryč
>              Labels: xp
>             Fix For: 4.3.0.Milestone1
>
>
> https://gist.github.com/2576862
> {code:xml}
> <cdk:root>
>   <cc:interface />
>   <cc:implementation>
>   
>     <cdk:render name="my" value="#{attr_value}" />  
>   </cc:implementation>
>   <cdk:fragment name="my">
>     <cc:interface>
>       <cc:attribute name="value" type="java.lang.String" />
>     </cc:interface>
>     <cc:implementation>
>       <cdk:render name="my" value="#{cc.value.recursiveParameter}" />
>     </cc:implementation>
>   </cdk:fragment>
> </cdk:root>
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the richfaces-issues mailing list