You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Jacek Laskowski <ja...@laskowski.net.pl> on 2008/04/03 19:26:04 UTC

Custom renderer for h:outputText - possible?

Hi,

I'm working with Geronimo 2.1 with MyFaces 1.2.2 and can't get my
custom renderer working. This is faces-config.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
  version="1.2">
  <render-kit>
    <renderer>
      <display-name><![CDATA[Mój własny JSF renderer]]></display-name>
      <component-family>javax.faces.Output</component-family>
      <renderer-type>javax.faces.Text</renderer-type>
      <renderer-class>pl.jaceklaskowski.jsf.renderers.DodajTekstRenderer</renderer-class>
    </renderer>
  </render-kit>
</faces-config>

and the code of DodajTekstRenderer:

package pl.jaceklaskowski.jsf.renderers;

import java.io.IOException;
import java.util.logging.Logger;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.render.Renderer;

public class DodajTekstRenderer extends Renderer {

    Logger logger = Logger.getLogger(DodajTekstRenderer.class.getName());

    public DodajTekstRenderer() {
        super();
        logger.info("Utworzono renderer");
        System.out.println("XYZ");
    }

    @Override
    public void decode(FacesContext facesContext, UIComponent component) {
        // super.decode(facesContext, component);
        logger.info("Wywołano decode");
        System.out.println("Wywołano decode");
    }

    @Override
    public void encodeBegin(FacesContext context, UIComponent
component) throws IOException {
        // TODO Auto-generated method stub
        // super.encodeBegin(context, component);
        logger.info("Wywołano encodeBegin");
        System.out.println("Wywołano encodeBegin");
    }

    @Override
    public void encodeEnd(FacesContext facesContext, UIComponent
component) throws IOException {
        // TODO Auto-generated method stub
        // super.encodeEnd(facesContext, component);
        logger.info("Wywołano encodeEnd");
        System.out.println("Wywołano encodeEnd");
    }

}

Not much, but meant to see whether it worked or not. It did not. The
constructor was called yet no other renderer methods. The
corresponding jsf page is as follows:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Mój własny JSF Renderer</title>
</head>
<body>
<f:view>
  <h:outputText value="Pewien tekst"></h:outputText>
</f:view>
</body>
</html>

Does anybody know what's wrong with it? Is it possible to override
default html renderer? I already read Extending Trinidad's default
renderers [1], but since it depends on Trinindad it didn't help much.

[1] http://matthiaswessendorf.wordpress.com/2008/02/20/extending-trinidads-default-renderers/

Jacek

-- 
Jacek Laskowski
http://www.JacekLaskowski.pl

RE: Custom renderer for h:outputText - possible?

Posted by "Jesse Alexander (KSFH 323)" <al...@credit-suisse.com>.
> > Could be then that somehow MyFaces does not allow to overwrite the
> >  standard renderers.
> 
> Why is so? Is there a page about it in the JSF spec so I could confirm
> it's right or not?

would have to check the spec... but usually it works also for MyFaces...

> >  Maybe you should grab the MyFaces source and analyze it or 
> debug the
> >  setup part of the applicaiton start.
> 
> I'm a mere JSF user and I'd rather avoid delving into the MyFaces
> sources. I want to understand how jsf works first before doing so. If
> it's the last resort I'll follow the advice.

Often it helps
a) to understand the workings of JSF
b) accelerate solutions for bugs
by analyzing the stuff as a user and maybe even hint at possible
solutions

regards
Alexander

Re: Custom renderer for h:outputText - possible?

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Sun, Apr 6, 2008 at 9:58 PM, Jesse Alexander (KSFH 323)
<al...@credit-suisse.com> wrote:
> Could be then that somehow MyFaces does not allow to overwrite the
>  standard renderers.

Why is so? Is there a page about it in the JSF spec so I could confirm
it's right or not?

>  Maybe you should grab the MyFaces source and analyze it or debug the
>  setup part of the applicaiton start.

I'm a mere JSF user and I'd rather avoid delving into the MyFaces
sources. I want to understand how jsf works first before doing so. If
it's the last resort I'll follow the advice.

Jacek

-- 
Jacek Laskowski
http://www.JacekLaskowski.pl

RE: Custom renderer for h:outputText - possible?

Posted by "Jesse Alexander (KSFH 323)" <al...@credit-suisse.com>.
Could be then that somehow MyFaces does not allow to overwrite the
standard renderers.

Maybe you should grab the MyFaces source and analyze it or debug the
setup part of the applicaiton start.

regards
Alexander 

> -----Original Message-----
> From: eljotpl@gmail.com [mailto:eljotpl@gmail.com] On Behalf 
> Of Jacek Laskowski
> Sent: Friday, April 04, 2008 10:50 PM
> To: users@myfaces.apache.org
> Subject: Re: Custom renderer for h:outputText - possible?
> 
> 2008/4/3 Jacek Laskowski <ja...@laskowski.net.pl>:
> 
> >  I'm working with Geronimo 2.1 with MyFaces 1.2.2 and can't get my
> >  custom renderer working. This is faces-config.xml file:
> 
> Just to let you know that the exact same custom renderer sample worked
> fine on GlassFish with JSF RI like a charm. See Custom renderer for
> h:outputText - possible? [1] on Sun Developer Forum for JSF. I wonder
> whether it's an issue with MyFaces or Geronimo-MyFaces integration.
> Hopefully it's going to be fixed soon as it prevents from deploying
> your own custom renderers without touching MyFaces-specific bits.
> 
> [1] http://forum.java.sun.com/thread.jspa?threadID=5282389
> 
> Jacek
> 
> -- 
> Jacek Laskowski
> http://www.JacekLaskowski.pl
> 

Re: Custom renderer for h:outputText - possible?

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
2008/4/3 Jacek Laskowski <ja...@laskowski.net.pl>:

>  I'm working with Geronimo 2.1 with MyFaces 1.2.2 and can't get my
>  custom renderer working. This is faces-config.xml file:

Just to let you know that the exact same custom renderer sample worked
fine on GlassFish with JSF RI like a charm. See Custom renderer for
h:outputText - possible? [1] on Sun Developer Forum for JSF. I wonder
whether it's an issue with MyFaces or Geronimo-MyFaces integration.
Hopefully it's going to be fixed soon as it prevents from deploying
your own custom renderers without touching MyFaces-specific bits.

[1] http://forum.java.sun.com/thread.jspa?threadID=5282389

Jacek

-- 
Jacek Laskowski
http://www.JacekLaskowski.pl