Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6628707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:09:23+00:00 2026-05-25T22:09:23+00:00

I want to create my own tag, but it doesn’t work Component: package com;

  • 0

I want to create my own tag, but it doesn’t work

Component:

package com;

import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import java.io.IOException;

public class Printer extends UIOutput {
    private String label;

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    @Override
    public Object saveState(FacesContext context) {
        Object values[] = new Object[2];
        values[0] = super.saveState(context);
        values[1] = label;
        return ((Object) (values));
    }

    @Override
    public void restoreState(FacesContext context, Object state) {
        Object values[] = (Object[]) state;
        super.restoreState(context, values[0]);
        label = (String) values[1];
    }

    public void encodeBegin(FacesContext context)
            throws IOException {

        ResponseWriter writer =
                context.getResponseWriter();

        writer.startElement("label", this);
        writer.write(label);
        writer.endElement("label");
        writer.flush();
    }

    public String getFamily() {
        return "printer";
    }

    public void encodeEnd(FacesContext context)
            throws IOException {
        return;
    }

    public void decode(FacesContext context) {
        return;
    }
}

Tag

package com;

import javax.faces.component.UIComponent;
import javax.faces.webapp.UIComponentELTag;

public class PrinterTag extends UIComponentELTag {
    private String label;

    public PrinterTag() {
        int i = 10;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    @Override
    public String getComponentType() {
        return "printer";
    }

    @Override
    public String getRendererType() {
        return null;
    }

    protected void setProperties(UIComponent component) {
        super.setProperties(component);
        ((Printer) component).setLabel(label);
    }
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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-app_2_5.xsd"
         version="2.5">
    <context-param>
        <description>
        </description>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>
            /WEB-INF/faces-config.xml
        </param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    <jsp-config>
        <taglib>
            <taglib-uri>http://ff.com</taglib-uri>
            <taglib-location>/WEB-INF/ff.tld</taglib-location>
        </taglib>
    </jsp-config>
    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
</web-app>

tld

<?xml version="1.0" encoding="ISO-8859-1"?>
<taglib xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
        xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1">

    <display-name>RichFaces</display-name>
    <tlib-version>3.3.3</tlib-version>
    <short-name>ff</short-name>
    <uri>http://ff.com</uri>
    <tag>
        <name>mylabel</name>
        <tag-class>com.PrinterTag</tag-class>
        <body-content>tagdependent</body-content>
        <attribute>
            <description>The attribute takes a value-binding expression for a component property of
                a backing bean
            </description>
            <name>label</name>
            <rtexprvalue>false</rtexprvalue>
            <type>java.lang.String</type>
        </attribute>
    </tag>
</taglib>

faces-config

<?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_2_0.xsd"
              version="2.0">
    <component>
        <component-type>printer</component-type>
        <component-class>com.Printer</component-class>
    </component>
</faces-config>

test.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:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:ff="http://ff.com">

<h:head>
    <title>Simple JSF Facelets page</title>
</h:head>
<h:body>
     before-<ff:mylabel label="This is my first tag"/>-after
</h:body>
</html>

(prints before–after)

I’m using
2.0.1-FCS jsf-api/jsf.impl/jstl-1.1.0
jsp-api/servlet-api/standart

Where I’m wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:09:23+00:00Added an answer on May 25, 2026 at 10:09 pm

    You’ve definied the tag in a JSP TLD, while you’re using JSP’s successor Facelets. You need to define the tag in a Facelets TLD.

    When reading tutorials/books about creating custom JSF components, ensure that you’re reading the JSF 2.0 targeted ones, not the JSF 1.2 targeted ones.

    See also:

    • Java EE 6 Tutorial – creating Custom UI Components
      • Steps for Creating a Custom Component
      • Creating Custom Component classes
      • Delegating Rendering to a Renderer
      • Defining the Custom Component Tag in a Tag Library Descriptor <– this one.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create my own component which consists two other panels. One of
How do you create your own custom component for vb.net 2008? I want it
I want to create own filetype to save objects in my app. Basically, I
I want to create my own IM and I'm searching an open-source IM APIs.
I want to create my own event - OnPositionChange . Event implementation of course
How can you make the .xla file if you want to create your own
I want to create a separate thread that runs its own window. Frankly, the
I want to create a bunch of errors. each specific to its own class
I have create my own NSOpenGLView class, right now the data that i want
Is there a way to create your own HTML element? I want to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.