[richfaces-issues] [JBoss JIRA] (RF-12195) Improve cdk:object scope

Paul Dijou (JIRA) jira-events at lists.jboss.org
Tue Apr 24 06:50:18 EDT 2012


Paul Dijou created RF-12195:
-------------------------------

             Summary: Improve cdk:object scope
                 Key: RF-12195
                 URL: https://issues.jboss.org/browse/RF-12195
             Project: RichFaces
          Issue Type: Enhancement
      Security Level: Public (Everyone can see)
          Components: cdk
    Affects Versions: 4.2.1.Final
         Environment: All
            Reporter: Paul Dijou


When using "cdk:object" tag, the cast will only occur for a part of the generated Java code, not for all of it. Here is an example :

{code:xml}
<cc:implementation>
    <cdk:object type="..." name="objectName" />
    // HTML code using "objectName"
    <cdk:body />
    // HTML code using "objectName"
</cc:implementation>
{code}

This will *not* work because the first part of the HTML code will be in "encodeBegin" method and the second part will be in "encodeEnd" method. But the cast will only happens in the "encodeBegin" method. And so there will be an error in "encodeEnd". The workaround is to copy/paste {{<cdk:object/>}} after the {{<cdk:body />}}. Ugly!

One solution would be that {{<cdk:object/>}} would generate Java code in every method that could use the variable even if they don't (methods like "encodeBegin", "encodeEnd", ...).

Another one would be that {{<cdk:object/>}} generates the following method :

{code:xml}
<cdk:object type="org.richfaces.bootstrap.component.AbstractBlockquote" name="blockquote" value="#{castComponent(component)}"/>
{code}

{code:java}
public AbstractBlockquote getCdkObjectBlockquote(FacesContext facesContext, UIComponent component) {
    // From "value" attribute :
    AbstractBlockquote blockquote = this.castComponent(component); 
    return blockquote;
}
{code}

And then replace all "blockquote" calls in HTML code with {{getCdkObjectBlockquote(facesContext, component);}}. Not sure if this last part is possible if the generation is only a copy/paste from the EL.

An alternative would be to use it like a singleton.

{code:java}
public class BlockquoteRenderer extends BlockquoteRendererBase {
    private AbstractBlockquote blockquote;

    private AbstractBlockquote getBlockquote(FacesContext facesContext, UIComponent component) {
        if(blockquote == null) {
            blockquote = getCdkObjectBlockquote(facesContext, component);
        }
        return blockquote;
    }
}
{code}

Or any other idea that allow to call {{<cdk:object/>}} only once in the template.

--
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