4 Replies Latest reply on Oct 28, 2008 4:24 PM by suplizio

    CDK f:call

    suplizio

      I lead my development team down the path of using the CDK in order to render our components thinking that I could use the jspx templates as composition components. I learned otherwise when all that was rendered was the tags included in the jspx file. Are there any plans to support composition/aggregate components in the CDK anytime soon? Do you have any suggestions for rendering markup containing other component tages? Right now any insight/assistance is greatly appreciated!

      So, now I'm trying to accomplish much of the composition behavior by making calls to *RenderBase methods. However, after adding a simple method call my compilation fails:

      From my htmlDateItem.jspx file
      <?xml version="1.0" encoding="UTF-8"?>
      <f:root xmlns:f="http://ajax4jsf.org/cdk/template"
      xmlns:c=" http://java.sun.com/jsf/core"
      xmlns:ui=" http://ajax4jsf.org/cdk/ui"
      xmlns:u=" http://ajax4jsf.org/cdk/u"
      xmlns:x=" http://ajax4jsf.org/cdk/x"
      xmlns:h="http://java.sun.com/jsf/html"
      class="com.company.app.rp.renderkit.html.DateItemRenderer"
      baseclass="com.company.app.rpf.renderkit.DateItemRendererBase"
      component="com.company.app.rp.component.UIDateItem">

      <!--
      Renders a Date object and converts it according to the date format.The UIDateItem class extends HtmlOutputText, so that it may inherit both the #setStyle #setStyleClass
      methonds, one of which is referenced below (component.style)
      @author chq-jasons
      @version 1.0
      @since JSF 1.2, JDK 1.5
      -->
      <f:clientid var="clientId" />
      <!-- I am a CDK component and I can not render "h" or any other components, only HTML h:outputText value="#{component.date}" id="#{clientId}"
      x:passThruWithExclusions="value,id" style="#{component.style}}">
      <c:convertDateTime pattern="#{component.dateFormat}" />
      </h:outputText -->
      <!-- Can I write a simple string using a method call? -->
      <div x:passThruWithExclusions="value,id" >
      <f:call name="writeDateItem" />

      </f:root>

      My DateItemRendererBase.java class
      import java.io.IOException;

      import javax.faces.component.UIComponent;
      import javax.faces.context.FacesContext;
      import javax.faces.context.ResponseWriter;

      import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;

      import com.expd.app.reportingplatform.vpf.component.UIDateItem;

      /**
      * Title: The rendering base class used to display the {@link UIDateItem}
      *
      * Description: This class is apparently required by the CDK even though it
      * currently contains no special encode/decode instructions and most likely will
      * not in the future. It is referenced in the "htmlDateItem.jspx" file as the
      * value in the "baseClass" attribute.
      *
      * @author chq-jasons
      *
      */
      public class DateItemRendererBase extends HeaderResourcesRendererBase {

      /**
      * @see org.ajax4jsf.renderkit.RendererBase#getComponentClass()
      */
      @Override
      protected Class getComponentClass() {
      return UIDateItem.class;
      }

      public void writeDateItem(FacesContext context, UIComponent component)
      throws IOException {
      ResponseWriter writer = context.getResponseWriter();
      writer.writeText("Test",null);
      }
      }

      From UIDateItem.java
      public abstract class UIDateItem extends UIAbstractVpfComponent {

      public static final String COMPONENT_TYPE = "com.company.app.rp.DateItem";

      public static final String COMPONENT_FAMILY = "com.company.app.rp.DateItem";

      /**
      * Provides a {@link Date} object to be rendered on the UI according to the
      * provided date format.
      *
      * @return date
      */
      public abstract Date getDate();

      /**
      * Sets a {@link Date} object to be rendered on the UI according to the
      * provided date format.
      *
      * @param date
      */
      public abstract void setDate(Date date);

      /**
      * Provides a {@link DateFormat} object used to render a {@link Date} object
      * on the UI.
      *
      * @return dateFormat
      */
      public abstract DateFormat getDateFormat();

      /**
      * Set a {@link DateFormat} object used to render a {@link Date} object on
      * the UI.
      *
      * @param dateFormat
      */
      public abstract void setDateFormat(DateFormat dateFormat);

      /**
      * This simple component does not contain any children, unless the nested
      * converter is considered a child.
      * @see javax.faces.component.UIComponentBase#getRendersChildren()
      */
      public boolean getRendersChildren() {
      return false;
      }
      }

      The stack trace
      [DEBUG] Renderer must be compiled from template com/company/app/rp/htmlTableItem.jspx
      java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
      at org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory.getProcessor(A4JRendererElementsFactory.java:149)
      at org.ajax4jsf.templatecompiler.builder.AbstractCompilationContext.getProcessor(AbstractCompilationContext.java:500)
      at org.ajax4jsf.templatecompiler.builder.TemplateCompiler.parseElement(TemplateCompiler.java:151)
      at org.ajax4jsf.templatecompiler.builder.TemplateCompiler.parseElement(TemplateCompiler.java:163)
      at org.ajax4jsf.templatecompiler.builder.TemplateCompiler.processing(TemplateCompiler.java:102)
      at org.ajax4jsf.builder.generator.RendererGenerator.createRenderer(RendererGenerator.java:185)
      at org.ajax4jsf.builder.generator.RendererGenerator.createFiles(RendererGenerator.java:113)
      at org.ajax4jsf.builder.mojo.GenerateMojo.execute(GenerateMojo.java:115)
      at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:499)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:478)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
      at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
      at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
      at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
      Caused by: org.ajax4jsf.templatecompiler.builder.CompilationException: function name is not set[ERROR] Error on generate component
      org.ajax4jsf.builder.generator.GeneratorException: Error create Renderer Java file
      at org.ajax4jsf.builder.generator.RendererGenerator.createRenderer(RendererGenerator.java:212)
      at org.ajax4jsf.builder.generator.RendererGenerator.createFiles(RendererGenerator.java:113)
      at org.ajax4jsf.builder.mojo.GenerateMojo.execute(GenerateMojo.java:115)
      at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
      at org.ajax4jsf.templatecompiler.elements.vcp.FCallTemplateElement.(FCallTemplateElement.java:88)
      ... 30 more

      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:499)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:478)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
      at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
      at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
      at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
      Caused by: org.ajax4jsf.templatecompiler.builder.CompilationException: org.ajax4jsf.templatecompiler.builder.CompilationException: InvocationTargetException: null
      at org.ajax4jsf.templatecompiler.builder.TemplateCompiler.processing(TemplateCompiler.java:107)
      at org.ajax4jsf.builder.generator.RendererGenerator.createRenderer(RendererGenerator.java:185)
      ... 20 more
      Caused by: org.ajax4jsf.templatecompiler.builder.CompilationException: InvocationTargetException: null
      at org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory.getProcessor(A4JRendererElementsFactory.java:163)
      at org.ajax4jsf.templatecompiler.builder.AbstractCompilationContext.getProcessor(AbstractCompilationContext.java:500)
      at org.ajax4jsf.templatecompiler.builder.TemplateCompiler.parseElement(TemplateCompiler.java:151)
      at org.ajax4jsf.templatecompiler.builder.TemplateCompiler.parseElement(TemplateCompiler.java:163)
      at org.ajax4jsf.templatecompiler.builder.TemplateCompiler.processing(TemplateCompiler.java:102)
      ... 21 more
      Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
      at org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory.getProcessor(A4JRendererElementsFactory.java:149)
      ... 25 more
      Caused by: org.ajax4jsf.templatecompiler.builder.CompilationException: function name is not set
      at org.ajax4jsf.templatecompiler.elements.vcp.FCallTemplateElement.(FCallTemplateElement.java:88)
      ... 30 more
      [INFO] ------------------------------------------------------------------------
      [ERROR] BUILD ERROR
      [INFO] ------------------------------------------------------------------------
      [INFO] Error in component generation

      Embedded error: Error create Renderer Java file
      function name is not set
      [INFO] ------------------------------------------------------------------------
      [DEBUG] Trace
      org.apache.maven.lifecycle.LifecycleExecutionException: Error in component generation
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:583)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:499)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:478)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
      at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
      at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
      at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
      Caused by: org.apache.maven.plugin.MojoExecutionException: Error in component generation
      at org.ajax4jsf.builder.mojo.GenerateMojo.execute(GenerateMojo.java:233)
      at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
      ... 16 more
      Caused by: org.ajax4jsf.builder.generator.GeneratorException: Error create Renderer Java file
      at org.ajax4jsf.builder.generator.RendererGenerator.createRenderer(RendererGenerator.java:212)
      at org.ajax4jsf.builder.generator.RendererGenerator.createFiles(RendererGenerator.java:113)
      at org.ajax4jsf.builder.mojo.GenerateMojo.execute(GenerateMojo.java:115)
      ... 18 more
      Caused by: org.ajax4jsf.templatecompiler.builder.CompilationException: org.ajax4jsf.templatecompiler.builder.CompilationException: InvocationTargetException: null
      at org.ajax4jsf.templatecompiler.builder.TemplateCompiler.processing(TemplateCompiler.java:107)
      at org.ajax4jsf.builder.generator.RendererGenerator.createRenderer(RendererGenerator.java:185)
      ... 20 more
      Caused by: org.ajax4jsf.templatecompiler.builder.CompilationException: InvocationTargetException: null
      at org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory.getProcessor(A4JRendererElementsFactory.java:163)
      at org.ajax4jsf.templatecompiler.builder.AbstractCompilationContext.getProcessor(AbstractCompilationContext.java:500)
      at org.ajax4jsf.templatecompiler.builder.TemplateCompiler.parseElement(TemplateCompiler.java:151)
      at org.ajax4jsf.templatecompiler.builder.TemplateCompiler.parseElement(TemplateCompiler.java:163)
      at org.ajax4jsf.templatecompiler.builder.TemplateCompiler.processing(TemplateCompiler.java:102)
      ... 21 more
      Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
      at org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory.getProcessor(A4JRendererElementsFactory.java:149)
      ... 25 more
      Caused by: org.ajax4jsf.templatecompiler.builder.CompilationException: function name is not set
      at org.ajax4jsf.templatecompiler.elements.vcp.FCallTemplateElement.(FCallTemplateElement.java:88)
      ... 30 more
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 10 seconds
      [INFO] Finished at: Mon Oct 27 14:47:52 PDT 2008
      [INFO] Final Memory: 14M/25M
      [INFO] ------------------------------------------------------------------------


        • 1. Re: CDK f:call
          nbelaevski

          Hmm, minor corrections (closed tags) and I've build your file successfully. What CDK version do you use?

          • 2. Re: CDK f:call
            suplizio

            The one that came with the 3.2.2.GA release. What about support for composition components? Are you considering adding that kind of support? If you have any suggestions I'd appreciate it!

            • 3. Re: CDK f:call
              suplizio

              After backing out my code file by file and adding each back incrementally I discovered that my actual install problem was due to a misspelling of a method call specified on the <f:call name="myPoorlySpelledMethod"> tag.

              Looking at my jspx file, how can I interpret its output into an actual component tree?
              <?xml version="1.0" encoding="UTF-8"?>
              <f:root xmlns:f="http://ajax4jsf.org/cdk/template"
              xmlns:c=" http://java.sun.com/jsf/core"
              xmlns:ui=" http://ajax4jsf.org/cdk/ui"
              xmlns:u=" http://ajax4jsf.org/cdk/u"
              xmlns:x=" http://ajax4jsf.org/cdk/x"
              xmlns:h="http://java.sun.com/jsf/html"
              class="com.company.app.rp.renderkit.html.DateItemRenderer"
              baseclass="com.company.app.rp.renderkit.DateItemRendererBase"
              component="com.company.app.rp.component.UIDateItem">

              <!--
              Renders a Date object and converts it according to the date format.The UIDateItem
              class extends HtmlOutputText, so that it may inherit both the #setStyle #setStyleClass
              methonds, one of which is referenced below (component.style)
              @author chq-jasons
              @version 1.0
              @since JSF 1.2, JDK 1.5
              -->
              <f:clientid var="clientId" />
              <h:outputText value="#{component.date}" id="#{clientId}" x:passThruWithExclusions="value,id" style="#{component.style}}">
              <f:convertDateTime pattern="#{component.dateFormat}" />
              </h:outputText>
              <f:call name="writeClass"/>
              </f:root>

              The output rendered in the browser....
              <h:outputtext id="j_id16" style="">
              <f:convertdatetime/>
              </h:outputtext>

              Why? I need to dynamically create each component at runtime based upon a complex rendering model. Any hints (besides abandoning this path entirely), would be very helpful!

              • 4. Re: CDK f:call
                suplizio

                f:call fixed - it was a typo. I'm creating another topic to address the other questions