3 Replies Latest reply on Nov 24, 2008 12:07 PM by Gleb Galkin

    Richfaces CDK problem

    Les McKinney Newbie

      Hello,

      I am new to the CDK. I have followed the documentation on how to create a new component. It seems very straight forward. What is happening is that I have created the template and renderer, as well as added properties in the xml file.

      When I run maven:install it runs fine and publishes no problem. When I look at the renderer created, it does not contain any of the code I wrote initially.

      Is there any more concise documentation on how to use the cdk properly (via pdf, word doc, etc) that I could obtain.

      It is a very nice tool. But I just don't have time for blind trial and error.

      I am using Eclipse Ganymede with the jboss tools module and m2eclipse maven module.

      I have connected to the jboss repository and am using the org.ajax4jsf - maven archetype. 1.1.0 to create the project initially. version 1.1.1 doesn't work well with my system.

      I apologize if this post is too long winded but I am at a loss

      Thanks in advance

      Les McKinney

        • 1. Re: Richfaces CDK problem
          Ilya Shaikovsky Master

           

          Is there any more concise documentation on how to use the cdk properly (via pdf, word doc, etc) that I could obtain.


          All the documents available for now is in the wiki and the guide you mentioned.

          About your case - please add code snippets carefully and point to the problematic generated code.

          • 2. Re: Richfaces CDK problem
            Les McKinney Newbie

            Thank you for the quick response.

            Here is my custom code

            package ca.whitewaterweb.renderkit;
            
            
            //
            // Imports
            //
            import java.util.Map;
            
            import javax.faces.component.UIComponent;
            import javax.faces.context.ExternalContext;
            import javax.faces.context.FacesContext;
            
            import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
            
            import ca.whitewaterweb.component.UIEventCalendar;
            
            public abstract class EventCalendarRenderer extends HeaderResourcesRendererBase {
            
             //This is my custom code
             public static final String CURRENT_MONTH_VALUE = "monthValue";
             public static final String CURRENT_YEAR_VALUE = "yearValue";
            
            
             @Override
             public void decode(FacesContext context, UIComponent component) {
             // TODO Auto-generated method stub
             super.decode(context, component);
            
             //custom code example
             ExternalContext ext = context.getExternalContext();
            
             Map<String,String> requestParms = ext.getRequestParameterMap();
            
             UIEventCalendar cal = (UIEventCalendar) component;
             String clientId = cal.getClientId(context);
             String currentMonth = (String) requestParms.get(clientId + CURRENT_MONTH_VALUE);
             String currentYear = (String) requestParms.get(clientId + CURRENT_YEAR_VALUE);
            
             cal.setCurrentMonth(currentMonth + currentYear);
            
             }
            
            
            }
            


            And here is what is generated:

            /**
             * License Agreement.
             *
             * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
             *
             * Copyright (C) 2007 Exadel, Inc.
             *
             * This library is free software; you can redistribute it and/or
             * modify it under the terms of the GNU Lesser General Public
             * License version 2.1 as published by the Free Software Foundation.
             *
             * This library is distributed in the hope that it will be useful,
             * but WITHOUT ANY WARRANTY; without even the implied warranty of
             * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
             * Lesser General Public License for more details.
             *
             * You should have received a copy of the GNU Lesser General Public
             * License along with this library; if not, write to the Free Software
             * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
             */
            
            package ca.whitewaterweb.renderkit.html;
            
            
            //
            // Imports
            //
            import java.util.Iterator;
            import java.util.Collection;
            import java.io.IOException;
            import javax.faces.component.UIComponent;
            import javax.faces.context.FacesContext;
            import javax.faces.context.ResponseWriter;
            import org.ajax4jsf.framework.renderer.ComponentsVariableResolver;
            import org.ajax4jsf.framework.renderer.ComponentVariables;
            //
            //
            //
            
            
            import org.ajax4jsf.framework.renderer.AjaxComponentRendererBase;
            
            
            
            /**
             * Renderer for component class ca.whitewaterweb.renderkit.html.EventCalendarRenderer
             */
            public class EventCalendarRenderer extends AjaxComponentRendererBase {
            
             public EventCalendarRenderer () {
             super();
             }
            
             //
             // Declarations
             //
             //
             //
             //
            
            
             private String convertToString(Object obj ) {
             return ( obj == null ? "" : obj.toString() );
             }
             private String convertToString(boolean b ) {
             return String.valueOf(b);
             }
             private String convertToString(int b ) {
             return b!=Integer.MIN_VALUE?String.valueOf(b):"";
             }
             private String convertToString(long b ) {
             return b!=Long.MIN_VALUE?String.valueOf(b):"";
             }
            
             /**
             * Get base component class, targetted for this renderer. Used for check arguments in decode/encode.
             * @return
             */
             protected Class getComponentClass() {
             return ca.whitewaterweb.component.UIEventCalendar.class;
             }
            
            
             public void doEncodeEnd(ResponseWriter writer, FacesContext context, ca.whitewaterweb.component.UIEventCalendar component, ComponentVariables variables) throws IOException {
             java.lang.String clientId = component.getClientId(context);
            writer.startElement("div", component);
             getUtils().writeAttribute(writer, "id", clientId );
             getUtils().writeAttribute(writer, "title", component.getAttributes().get("titleValue") );
             //
            // pass thru attributes
            //
            getUtils().encodeAttributesFromArray(context,component,new String[] {
             "class" ,
             "dir" ,
             "lang" ,
             "onclick" ,
             "ondblclick" ,
             "onkeydown" ,
             "onkeypress" ,
             "onkeyup" ,
             "onmousedown" ,
             "onmousemove" ,
             "onmouseout" ,
             "onmouseover" ,
             "onmouseup" ,
             "style" ,
             "title" ,
             "xml:lang" });
            //
            //
            //
            
            writer.startElement("table", component);
             getUtils().writeAttribute(writer, "cellpadding", "0" );
             getUtils().writeAttribute(writer, "cellspacing", "0" );
             getUtils().writeAttribute(writer, "class", "dr-table rich-table " + convertToString(component.getAttributes().get("styleClass")) );
             getUtils().writeAttribute(writer, "id", clientId );
             getUtils().writeAttribute(writer, "style", component.getAttributes().get("style") );
            
            writer.startElement("tr", component);
            
            writer.startElement("th", component);
             getUtils().writeAttribute(writer, "abbr", "Sunday" );
             getUtils().writeAttribute(writer, "scope", "col" );
            
            writer.writeText(convertToString("Sunday"),null);
            
            writer.endElement("th");
            writer.startElement("th", component);
             getUtils().writeAttribute(writer, "abbr", "Monday" );
             getUtils().writeAttribute(writer, "scope", "col" );
            
            writer.writeText(convertToString("Monday"),null);
            
            writer.endElement("th");
            writer.startElement("th", component);
             getUtils().writeAttribute(writer, "abbr", "Tuesday" );
             getUtils().writeAttribute(writer, "scope", "col" );
            
            writer.writeText(convertToString("Tuesday"),null);
            
            writer.endElement("th");
            writer.startElement("th", component);
             getUtils().writeAttribute(writer, "abbr", "Wednesday" );
             getUtils().writeAttribute(writer, "scope", "col" );
            
            writer.writeText(convertToString("Wednesday"),null);
            
            writer.endElement("th");
            writer.startElement("th", component);
             getUtils().writeAttribute(writer, "abbr", "Thursday" );
             getUtils().writeAttribute(writer, "scope", "col" );
            
            writer.writeText(convertToString("Thursday"),null);
            
            writer.endElement("th");
            writer.startElement("th", component);
             getUtils().writeAttribute(writer, "abbr", "Friday" );
             getUtils().writeAttribute(writer, "scope", "col" );
            
            writer.writeText(convertToString("Friday"),null);
            
            writer.endElement("th");
            writer.startElement("th", component);
             getUtils().writeAttribute(writer, "abbr", "Saturday" );
             getUtils().writeAttribute(writer, "scope", "col" );
            
            writer.writeText(convertToString("Saturday"),null);
            
            writer.endElement("th");
            writer.endElement("tr");
            renderChildren(context, component);
            
            writer.endElement("table");
            writer.startElement("input", component);
             getUtils().writeAttribute(writer, "name", convertToString(clientId) + "monthValue" );
             getUtils().writeAttribute(writer, "type", "hidden" );
             getUtils().writeAttribute(writer, "value", component.getAttributes().get("monthValue") );
            
            writer.endElement("input");
            writer.startElement("input", component);
             getUtils().writeAttribute(writer, "name", convertToString(clientId) + "yearValue" );
             getUtils().writeAttribute(writer, "type", "hidden" );
             getUtils().writeAttribute(writer, "value", component.getAttributes().get("yearValue") );
            
            writer.endElement("input");
            writer.endElement("div");
            
             }
            
             public void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException {
             ComponentVariables variables = ComponentsVariableResolver.getVariables(this, component);
             doEncodeEnd(writer, context, (ca.whitewaterweb.component.UIEventCalendar)component, variables );
            
             ComponentsVariableResolver.removeVariables(this, component);
             }
            
            
            }
            
            



            The generated renderer does not extend the base renderer that I created according to the documentation.

            What is happening?

            Thanks for looking into this

            Les McKinney

            • 3. Re: Richfaces CDK problem
              Gleb Galkin Novice

              Les McKinney, please, check the Renderer Baseclass in your Template. It should be your Baseclass, e.g. ca.whitewaterweb.renderkit.EventCalendarRenderer.