Hi,
I think the issue is that your component is rendering itself, which
you shouldn't do.
(or can you try null for the renderer-type node?)
It is better to provide a renderer for your component (better reuse of
the component).
After all use these nodes in the taglib.xml file
<component-type />
<renderer-type />
one cool thing with facelets is, that you don't need to write a tag,
(since that guy is only for the jsp world of jsf)
On 11/27/06, Christian Wiesing <[EMAIL PROTECTED]> wrote:
Thanks,
i created the Facelets-Taglib-File, but it still don't work. It would be
great if somebody could tell me what I do wrong. See my source code below.
Thanks.
Christian
---------------------------------------
view.xhtml ----------------------------
---------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:cf="http://test.com/customtags">
<cf:jsfhello hellomsg="Hello world." />
</html>
---------------------------------------
custom-taglib.xml ---------------------
---------------------------------------
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://test.com/customtags</namespace>
<tag>
<tag-name>jsfhello</tag-name>
<component>
<component-type>demo.JsfHello</component-type>
</component>
</tag>
</facelet-taglib>
---------------------------------------
faces-config --------------------------
---------------------------------------
<faces-config>
<component>
<component-type>demo.JsfHello</component-type>
<component-class>demo.HelloUIComp</component-class>
</component>
---------------------------------------
HelloUIComp.java -------------------
---------------------------------------
package demo;
import java.util.Date;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import java.io.IOException;
import javax.faces.context.ResponseWriter;
public class HelloUIComp extends UIComponentBase
{
public void encodeBegin(FacesContext context) throws IOException
{
ResponseWriter writer = context.getResponseWriter();
String hellomsg = (String)getAttributes().get("hellomsg");
writer.startElement("h3", this);
if(hellomsg != null)
writer.writeText(hellomsg, "hellomsg");
else
writer.writeText("Hello from a custom JSF UI Component!",
null);
writer.endElement("h3");
writer.startElement("p", this);
writer.writeText(" Today is: " + new Date(), null);
writer.endElement("p");
}
public String getFamily()
{
return "HelloFamily";
}
}
---------------------------------------
FacesHelloTag -----------------------
---------------------------------------
package demo;
import javax.faces.application.Application;
import javax.faces.webapp.UIComponentTag;
import javax.faces.component.UIComponent;
import javax.faces.el.ValueBinding;
import javax.faces.context.FacesContext;
public class FacesHelloTag extends UIComponentTag
{
// Declare a bean property for the hellomsg attribute.
public String hellomsg = null;
// Associate the renderer and component type.
public String getComponentType() { return "demo.JsfHello"; }
public String getRendererType() { return null; }
protected void setProperties(UIComponent component)
{
super.setProperties(component);
// set hellomsg
if (hellomsg != null)
{
if (isValueReference(hellomsg))
{
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();
ValueBinding vb = app.createValueBinding(hellomsg);
component.setValueBinding("hellomsg", vb);
}
else
component.getAttributes().put("hellomsg", hellomsg);
}
}
public void release()
{
super.release();
hellomsg = null;
}
public void setHellomsg(String hellomsg)
{
this.hellomsg = hellomsg;
}
}
Matthias Wessendorf schrieb:
> Hi Christian,
>
> take a look at [1]. That describes the steps for Tomahawk custom
> components; which are also true for your custom components.
>
> HTH,
> Matthias
>
> [1] http://wiki.apache.org/myfaces/Use_Facelets_with_Tomahawk
>
> On 11/27/06, Christian Wiesing <[EMAIL PROTECTED]> wrote:
>> Hello,
>>
>> how can I use custom JSF components with Facelets? I have some JSF
>> components which I wanna use in my Facelets-Web-App.
>>
>> Is there any example or something like that?
>>
>> regards,
>>
>> Christian
>>
>>
>>
>>
>>
>
>
--
Matthias Wessendorf
http://tinyurl.com/fmywh
further stuff:
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com