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

  • SEARCH
  • Home
  • 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 9078091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:32:02+00:00 2026-06-16T19:32:02+00:00

I wrote a simple custom component with JSF1 and it works fine. But when

  • 0

I wrote a simple custom component with JSF1 and it works fine.
But when I use it in JSF2, it doesn’t work. Here is how I use it:

<?xml version="1.0" encoding="UTF-8"?>
<!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:d="http://jsftutorials.com/"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
    <h:body>
        <f:view>
          <d:ticker>Hello World!</d:ticker>
        </f:view>
    </h:body>
</html>

Here is how the component is created for JSF1:

faces-config.xml

<?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>ticker</component-type>
        <component-class>ticker.UITicker</component-class>
    </component>
</faces-config>

ticker.tld

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
                          "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>d</short-name>
    <uri>http://jsftutorials.com/</uri>
    <tag>
        <name>ticker</name>
        <tag-class>ticker.TickerTag</tag-class>
        <body-content>JSP</body-content>
    </tag>
</taglib>

TickerTag.java

package ticker;

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

@SuppressWarnings("deprecation")
public class TickerTag extends UIComponentTag {

    public void release() {
        super.release();
    }

    protected void setProperties(UIComponent component) {
        super.setProperties(component);

    }

    public String getComponentType() {
        return "ticker";
    }

    public String getRendererType() {
        return null;
    }
}

UITicker.java

package ticker;

import java.io.IOException;

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

public class UITicker extends UIOutput {

    public void encodeBegin(FacesContext context) throws IOException {
        ResponseWriter writer = context.getResponseWriter();
        writer.startElement("div", this);
    }

    public void encodeEnd(FacesContext context) throws IOException {
        ResponseWriter writer = context.getResponseWriter();
        writer.endElement("div");
    }
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name></display-name>

    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>

    <context-param>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/faces-config.xml</param-value>
    </context-param>

    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>

    <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>*.xhtml</url-pattern>
    </servlet-mapping>
</web-app>

What should I change to get it to work in JSF2?

  • 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-06-16T19:32:03+00:00Added an answer on June 16, 2026 at 7:32 pm

    That’s a JSP tag. JSP is deprecated in JSF 2.0 and succeeded by Facelets (XHTML). You’re indeed using Facelets instead of JSP. Your component would only work when you’re using JSF2 with legacy JSP instead of Facelets. You need to change the old JSP tag to be a Facelets tag.

    Here are the changes you need to make:

    • faces-config.xml: remove the <component> altogether.

    • ticker.tld: rename it to ticker.taglib.xml and replace the content by:

      <?xml version="1.0" encoding="UTF-8"?>
      <facelet-taglib 
          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-facelettaglibrary_2_0.xsd"
          version="2.0">
          <namespace>http://jsftutorials.com</namespace>
          <tag>
              <tag-name>ticker</tag-name>
              <component>
                  <component-type>ticker</component-type>
              </component>
          </tag>
      </facelet-taglib>
      
    • TickerTag.java: remove it altogher. You don’t need it for Facelets.

    • UITicker.java: add the following annotation on the class (this replaces the <component> entry in faces-config.xml)

      @FacesComponent("ticker")
      public class UITicker extends UIOutput {
      

      (note: the annotation value must match <component-type> in the taglib XML file, not <tag-name>)

      As UIOutput does by default not allow text children, it’s basically the wrong choice to represent a <div> component. You’d better extend UIPanel instead.

      @FacesComponent("ticker")
      public class UITicker extends UIPanel {
      

      (note that the standard <h:panelGroup layout="block"> component already renders a <div> like that; I understand that you’re just learning JSF, but just to be sure for the case you are really looking for a JSF component which renders a div)

    • web.xml: add the following context param:

      <context-param>
          <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
          <param-value>/WEB-INF/ticker.taglib.xml</param-value>
      </context-param>
      

      (note: this is unnecessary when you provide the taglib as JAR file in /WEB-INF/lib and have the .taglib.xml file in /META-INF of the JAR)

    When reading/learning something about JSF, assure that you’re reading the right tutorials/resources targeted at JSF2 and not the ones targeted at JSF1. Many, many things are done differently.

    See also:

    • Migrating from JSF 1.2 to JSF 2.0
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple XML file and a DTD file including an entity, but
I wrote a very simple plugin to add custom fields to media library but
I just wrote a simple DirectShow Filter (which inherits from CTransformFilter). But I want
I wrote a custom template engine to let me use my old templates in
How do you control version of your static files in Django? I wrote custom
I want to create a (simple, hopefully) custom Swing component by composing several existing
I wrote a simple game and I want to add custom pointer. I created
I just want to use developer app for creating normal simple custom tab. And
I wrote simple custom validation on javascript based on this doc . I want
I am trying to write a simple Wordpress plugin, which updates a custom field

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.