JSF Marquee Component | Java Example | FlexiGrid using Servlet + JSON |

JSF Marquee Component with ValueBinding.

with 2 comments

Included Valuebinding …

I was looking around at JavaRanch and somone posted question on JSF marquee component. I don’t think it comes along with jsf jar so I thought to write a component since its easy and maybe it help to a basic understanding of JSF custom component!!

P.S: I created this component around Feb 2007 and was using JSF 1.0 for the development.  Maybe some of the classes are deprecated if you are using the latest version but I guess this will work without any errors. If you experience any problems , feel free to comment at the bottom of the page and I will try my best to help you.

Requirements :

Basic Java Knowledge, Eclipse, Apache Tomcat

For developing a custom component in JSF all we need to have is

1. Component class.
2. Tag class.
3. Renederer ( optional ) . I am not using the Renderer for this component
4. Define a TLD file for the component tags.
5. Register the component in faces-config.

I am using Eclipse 3.3.1

create package in your “src”  , right click src -> New -> package

give the package name as com.jsf.component.marquee

Now its time to create  the Component classes


package com.jsf.component.marquee;

import java.io.IOException;

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

public class Marquee extends UIComponentBase {

private String value;

public String getValue() {
return value;

public void setValue(String value) {
this.value = value;

public String getFamily() {
// TODO Auto-generated method stub
return null;

public void encodeBegin(FacesContext context) throws IOException {

ResponseWriter writer = context.getResponseWriter();
String hellomsg = (String)getAttributes().get(“marquee”);
writer.startElement(“marquee”, this);
if (hellomsg != null)



package com.jsf.component.marquee;

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

public class MarqueeTag extends UIComponentTag {

private String marquee;

public String getMarquee() {
return marquee;

public void setMarquee(String marquee) {
this.marquee = marquee;

public String getComponentType() {
// TODO Auto-generated method stub
return “com.component.marqueecomp”;

public String getRendererType() {
// TODO Auto-generated method stub
return null;

protected void setProperties(UIComponent component) {

Marquee marqComp = (Marquee) component;

if (marquee != null)  {

if (isValueReference(marquee))    {

FacesContext context = FacesContext.getCurrentInstance();

Application app = context.getApplication();

ValueBinding vb = app.createValueBinding(marquee);

marqComp.setValueBinding(“marquee”, vb);

}  else {






New file JavaBean.java

package com.jsf.bean;

public class JavaBean {

String label;

public String getLabel() {

return label;


public void setLabel(String label) {

this.label = label;



This is how my faces-config.xml looks like  ( JSFMarquee\WebContent\WEB-INF\faces-config.xml )

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE faces-config PUBLIC
“-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN”









<value>JSF Marquee</value>




remember , im using JSF 1.1 so my dtd file maybe different from yours if you are using latest version. Don’t worry about it if  its not same..

Create file marquee.tld and save it under JSFMarquee\WebContent\WEB-INF\

This is the content of tld file

<!DOCTYPE taglib
PUBLIC “-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN”



create a jsp file and save it under webcontent


<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<%@taglib uri=”http://java.sun.com/jsf/html&#8221; prefix=”h”%>
<%@taglib uri=”http://java.sun.com/jsf/core&#8221; prefix=”f”%>
<%@taglib uri=”/jsf-marquee” prefix=”mycomp”%>


<meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″ />
<title>Insert title here</title>
<mycomp:marquee marquee=”hello World”/>

<mycomp:marquee marquee= “#{javaBean.label}” />

Now its time to run the application and see how the component looks like

Download and install tomcat . Add tomcat as a server to your Eclipse. I hope you already have Tomcat installed.To add Tomcat to Eclipse,  go to Window -> Show View -> Servers

in the server tab, right click and add server. select tomcat 6.0 or which ever version you have installed.

now  right click on MarqueeTest.jsp and select “Run as” -> “Run on Server” and select tomcat from the servers listing.. I was getting “faces Servlet  not found error and to resolve it easily i created “lib” folder in WebContent/WEB-INF and copied jars in there.. here is my screenshot :=]  ( click on the pic to get an enlarged view )


Written by speedrace703

December 16, 2009 at 7:28 am

2 Responses

Subscribe to comments with RSS.

  1. Hello, I tried your example it’s really good. But i am getting an error when i am trying to execute it.
    The error is:
    Failed to execute JSP lifecycle.
    javax.faces.FacesException: java.lang.ClassCastException: testingprojectjsf.MarqueeTag cannot be cast to javax.faces.component.UIComponent

    Can you please provide me the solution for this.
    Thanks in advance, i am in need of this.

    Sri Varun

    November 29, 2010 at 7:22 am

    • Does your Tag class extends UIComponentTag ?
      testingprojectjsf.MarqueeTag extends UIComponentTag


      November 30, 2010 at 1:53 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: