You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Henry Eduardo Iguaro <he...@gmail.com> on 2008/02/20 00:26:11 UTC

Custom Renderer for tr:message doesn't work?...

hi, i'm creating a custom renderer for a
org.apache.myfaces.trinidad.component.core.output.CoreMessage component
(aka, a <tr:message /> component), the custom renderer uses javascript
to simulate a small balloon message box. After searching in the source
code, i've found that the default renderer for the CoreMessage is the
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.MessageRenderer, so
i created a copy of it and renamed to my renderer class name, this way i
could test the tag handling before plugin mine own renderer

This is the code that registers the renderer in my faces-config.xml
file.

<render-kit>
        <render-kit-class>
org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit
        </render-kit-class>
        <renderer>
                <component-family>
                        org.apache.myfaces.trinidad.Message
                </component-family>
                <renderer-type>
                        org.apache.myfaces.trinidad.CoreMessage
                </renderer-type>
                <renderer-class>
gob.sudeban.util.jsf.custom.renderers.MessageBalloonRenderer
                </renderer-class>
        </renderer>
</render-kit>

This is the component tag from my tld file:
        <tag>
            <name>balloon-message</name>
<tag-class>gob.sudeban.util.jsf.custom.tags.BalloonMessageTag</tag-class>
                ...

The same atributes for the message tag from the tr.tld file in
trinidad-impl-1.0.6.jar
                ...
        </tag>


The class gob.sudeban.util.jsf.custom.tags.BalloonMessageTag is also a
renamed copy of
org.apache.myfaces.trinidadinternal.taglib.core.output.CoreMessageTag

This is the jsp file i use to test the component:

<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/trinidad" prefix="tr" %>
<%@ taglib uri="http://myfaces.apache.org/trinidad/html" prefix="trh" %>
<%@ taglib uri="http://sudeban.gob.ve/jsf/component/tags"
prefix="sudeban" %>

<f:view>

<trh:head>
</trh:head>

<trh:body>
        <tr:form>
                <tr:panelFormLayout >
                        <sudeban:balloon-message message="This is a message"
/>
                </tr:panelFormLayout>
        </tr:form>
</trh:body>

When i test the component i get the following:

(HtmlRenderKitImpl.java:79) Unsupported component-family/renderer-type:
org.apache.myfaces.trinidad.Message
/gob.sudeban.util.jsf.custom.renderers.MessageBalloonRenderer
19-feb-2008 16:30:22
org.apache.myfaces.trinidadinternal.renderkit.RenderKitBase getRenderer
WARNING: Renderer
'gob.sudeban.util.jsf.custom.renderers.MessageBalloonRenderer' not found
for component family 'org.apache.myfaces.trinidad.Message'
19-feb-2008 16:30:22
org.apache.myfaces.trinidad.component.UIXComponentBase _getRendererImpl
WARNING: Could not find renderer for CoreMessage[UIXFacesBeanImpl,
id=_idJsp4] rendererType =
gob.sudeban.util.jsf.custom.renderers.MessageBalloonRenderer
(UIComponentTag.java:500) Exited encodeEnd for client-Id: _idJsp1
19-feb-2008 16:30:22
org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit
encodeFinally
WARNING: No RenderingContext available
19-feb-2008 16:30:22
org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit
encodeFinally
WARNING: No RenderingContext available

And anything get rendered...

What am i doing wrong? It's possible to register another render for a
core component like this?

Any help would be appreciated

(PS: Please excuse my english)

Henry Iguaro

Re: Custom Renderer for tr:message doesn't work?...

Posted by Matthias Wessendorf <ma...@apache.org>.
Hi Henry,

I think you have a mistake in the config (like renderer-type).
here is a *simple* extended version of MessageRenderer.

Java class:
package net.wessendorf.trinidad;

import java.io.IOException;

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

import org.apache.myfaces.trinidad.bean.FacesBean;
import org.apache.myfaces.trinidad.component.core.output.CoreMessage;
import org.apache.myfaces.trinidad.context.RenderingContext;
import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.MessageRenderer;

public class CustomMessageRenderer extends MessageRenderer
{
  public CustomMessageRenderer()
  {
    this(CoreMessage.TYPE);
  }

  protected CustomMessageRenderer(FacesBean.Type type)
  {
    super(type);
  }
  @Override
  protected void encodeAll(
    FacesContext        context,
    RenderingContext    rc,
    UIComponent         component,
    FacesBean           bean) throws IOException
  {
    ResponseWriter writer = context.getResponseWriter();
    writer.startElement("div", null);
    writer.write("BLAH");
    writer.endElement("div");

    super.encodeAll(context, rc, component, bean);
  }
}


required xml:
  <render-kit>
    <render-kit-id>org.apache.myfaces.trinidadinternal.core</render-kit-id>
    <renderer>
      <component-family>
        org.apache.myfaces.trinidad.Message
      </component-family>
      <renderer-type>
        org.apache.myfaces.trinidad.Message
      </renderer-type>
      <renderer-class>
        net.wessendorf.trinidad.CustomMessageRenderer
      </renderer-class>
    </renderer>
  </render-kit>

(note that now <tr:message /> is using this custom renderer.

-Matthias

On Feb 20, 2008 12:26 AM, Henry Eduardo Iguaro <he...@gmail.com> wrote:
> hi, i'm creating a custom renderer for a
> org.apache.myfaces.trinidad.component.core.output.CoreMessage component
> (aka, a <tr:message /> component), the custom renderer uses javascript
>  to simulate a small balloon message box. After searching in the source
> code, i've found that the default renderer for the CoreMessage is the
> org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.MessageRenderer, so
> i created a copy of it and renamed to my renderer class name, this way i
> could test the tag handling before plugin mine own renderer
>
> This is the code that registers the renderer in my faces-config.xml
> file.
>
> <render-kit>
>         <render-kit-class>
> org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit
>          </render-kit-class>
>         <renderer>
>                 <component-family>
>                         org.apache.myfaces.trinidad.Message
>                 </component-family>
>                  <renderer-type>
>                         org.apache.myfaces.trinidad.CoreMessage
>                 </renderer-type>
>                 <renderer-class>
>  gob.sudeban.util.jsf.custom.renderers.MessageBalloonRenderer
>                 </renderer-class>
>         </renderer>
> </render-kit>
>
> This is the component tag from my tld file:
>          <tag>
>             <name>balloon-message</name>
> <tag-class>gob.sudeban.util.jsf.custom.tags.BalloonMessageTag</tag-class>
>                 ...
>
> The same atributes for the message tag from the tr.tld file in
> trinidad-impl-1.0.6.jar
>                 ...
>         </tag>
>
>
> The class gob.sudeban.util.jsf.custom.tags.BalloonMessageTag is also a
>  renamed copy of
> org.apache.myfaces.trinidadinternal.taglib.core.output.CoreMessageTag
>
> This is the jsp file i use to test the component:
>
> <?xml version="1.0" encoding="UTF-8" ?>
>  <%@ page language="java" contentType="text/html; charset=UTF-8"
> pageEncoding="UTF-8"%>
> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
>  <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
> <%@ taglib uri="http://myfaces.apache.org/trinidad" prefix="tr" %>
>  <%@ taglib uri="http://myfaces.apache.org/trinidad/html" prefix="trh" %>
> <%@ taglib uri="http://sudeban.gob.ve/jsf/component/tags"
>  prefix="sudeban" %>
>
> <f:view>
>
> <trh:head>
> </trh:head>
>
> <trh:body>
>         <tr:form>
>                 <tr:panelFormLayout >
>                          <sudeban:balloon-message message="This is a
> message" />
>                 </tr:panelFormLayout>
>         </tr:form>
> </trh:body>
>
> When i test the component i get the following:
>
> (HtmlRenderKitImpl.java:79) Unsupported component-family/renderer-type:
> org.apache.myfaces.trinidad.Message/gob.sudeban.util.jsf.custom.renderers.MessageBalloonRenderer
>  19-feb-2008 16:30:22
> org.apache.myfaces.trinidadinternal.renderkit.RenderKitBase getRenderer
> WARNING: Renderer
> 'gob.sudeban.util.jsf.custom.renderers.MessageBalloonRenderer' not found
>  for component family 'org.apache.myfaces.trinidad.Message'
> 19-feb-2008 16:30:22
> org.apache.myfaces.trinidad.component.UIXComponentBase _getRendererImpl
> WARNING: Could not find renderer for CoreMessage[UIXFacesBeanImpl,
>  id=_idJsp4] rendererType =
> gob.sudeban.util.jsf.custom.renderers.MessageBalloonRenderer
> (UIComponentTag.java:500) Exited encodeEnd for client-Id: _idJsp1
> 19-feb-2008 16:30:22
>  org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit
> encodeFinally
> WARNING: No RenderingContext available
> 19-feb-2008 16:30:22
> org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit
>  encodeFinally
> WARNING: No RenderingContext available
>
> And anything get rendered...
>
> What am i doing wrong? It's possible to register another render for a
> core component like this?
>
> Any help would be appreciated
>
> (PS: Please excuse my english)
>
> Henry Iguaro
>



-- 
Matthias Wessendorf

further stuff:
blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
mail: matzew-at-apache-dot-org

Re: Custom Renderer for tr:message doesn't work?...

Posted by Leonardo Uribe <lu...@gmail.com>.
Working with trinidad-sanbox, I experienced the same problem that you have.
One workaroud is create a renderer like this:

package org.apache.myfaces.trinidadinternal.sandbox.renderkit.core;

import org.apache.myfaces.trinidadinternal.renderkit.RenderKitDecorator;
import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit;

public class CoreSandboxRenderKit extends RenderKitDecorator
{

    public CoreSandboxRenderKit(){

    }

    @Override
    protected String getDecoratedRenderKitId()
    {
      return CoreRenderKit.BASE_RENDER_KIT_ID;
    }
}

And register your component on this renderer like this:

  <render-kit>
    <render-kit-id>org.apache.myfaces.trinidadinternal.sandbox.core</render-kit-id>
    <render-kit-class>org.apache.myfaces.trinidadinternal.sandbox.renderkit.core.CoreSandboxRenderKit</render-kit-class>
    <render-kit-extension>
    </render-kit-extension>
    <!-- PUT YOUR RENDERER HERE -->
  </render-kit>

Don't forget correct the <default-render-kit> on faces-config.xml of your
web app to your renderer. This should work.

regards

Leonardo Uribe