Friday, February 16, 2007

moving it here

Marquee in HTML is defined using the marquee tag

<marquee>hello world!</marquee>

We can define marquee inside the JSF page within verbatain tag,

<f:verbatim><marquee>hello world!</marquee></f:verbatim>

which is a mixup of html and jsf tags. If we don't want to mix html and JSF together , the only option is creating a custom component which replaces the above with

<mycomp:marquee value="Hello World !!" />

cool huh ? :)

Creating a JSF component is simple and straight forward, hoping that you have basic understanding about JSF and web environment. 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.

Component Class

package com.mycomponent;

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 getFamily() {
return null;

public String getValue() {
return value;

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

public void encodeBegin(FacesContext context) throws IOException {

ResponseWriter writer = context.getResponseWriter();

Tag Class

package com.mycomponent;

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

public class MarqueeTag extends UIComponentTag {

private String value;

public String getValue() {
return value;

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

public MarqueeTag() {

public String getComponentType() {
// this String constant should match the component-type defined in faces-config.xml
return "com.mycomponent.MarqueeComp";

public String getRendererType() {
return null;

protected void setProperties(UIComponent component) {

Marquee marquee = (Marquee) component;

if(null != value){


TLD file for the marquee component

Give this a name (marquee.tld) and keep the file inside WEB-INF folder

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

<taglib> <tlib-version>



Edit your faces-config.xml to register the new component.





I'm using XML markup for my jsp , if you are using HTML markup, the syntax for defining the marquee namespace will be different.

<?xml version="1.0" encoding="ISO-8859-1" ?>
<jsp:root xmlns:jsp=""
xmlns:f="" version="2.0"
xmlns:mycomp="/jsf-marquee" // this should match the uri defined in TLD file

<comp:marquee value="Hello World !!" />

That's it !! In-case you are stuck at somewhere let me know, i would be happy to help you out ..

Happy coding !


Anonymous said...

still not working for me....

Anonymous said...

UIComponentTag is deprecated now.
i tried with UIComponentELTag but still there is no error and no scrolling message... thanks in advance for any help

raj said...

check it here.

Anonymous said...

Fantastic post but I was wondering if you could write a litte more on
this topic? I'd be very grateful if you could elaborate a little bit further. Cheers!

Here is my webpage :: guate mala porn (