Custom tag for Marquee in JSF
sandeepgowda Oct 18, 2010 1:50 PMI am trying to develop Custom tag for Marquee,since my requirement is to display some dynamic data.
below is the code i am using, please let me known any changes required.
regards
Sandeep. please help me
package customtags;
import java.io.IOException;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
/**
* @author SandeepGowda
*
*/
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();
writer.startElement("marquee", this);
writer.write(getValue());
writer.endElement("marquee");
}
}
/**
*
*/
package customtags;
import javax.faces.component.UIComponent;
import javax.faces.webapp.UIComponentELTag;
/**
* @author SandeepGowda
*
*/
public class MarqueeTag extends UIComponentELTag {
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 "marqueecomp";
}
public String getRendererType() {
// TODO Auto-generated method stub
return null;
}
protected void setProperties(UIComponent component) {
super.setProperties(component);
Marquee marqComp = (Marquee) component;
if (marquee != null) {
marqComp.setValue(marquee);
}
}
}
faces config:
<component>
<display-name>marqueecomp</display-name>
<component-type>marqueecomp</component-type>
<component-class>customtags.Marquee</component-class>
</component>
marquee.tld
<?xml version="1.0" encoding="UTF-8"?>
<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-jsptaglibrary_2_1.xsd"
version="2.1">
<tlib-version>1.0</tlib-version>
<short-name>marqueecomp</short-name>
<uri>http://tags.org/marquee</uri>
<tag>
<name>marqueecomp</name>
<tag-class>customtags.MarqueeTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
marquee.taglib.xml-- in classpath/lib
<?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://tags.org/marquee</namespace>
<tag>
<tag-name>marqueecomp</tag-name>
<component>
<component-type>customtags.MarqueeTag</component-type>
</component>
</tag>
</facelet-taglib>
xhtml page
<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" xml:lang="en" lang="en"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich" xmlns:mycomp="http://tags.org/marquee">
<head>
<title>DEBTDOC Home Page</title>
<meta http-equiv="keywords" content="enter,your,keywords,here" />
<meta http-equiv="description"
content="A short description of this page." />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../css/common.css"></link>
<script language="javascript" src="../script/common.js"></script>
</head>
<body>
<f:view>
<h:form>
<div align="center" style="position: relative;"><h:outputText
style="text-align:center;color:red;font-size:20px;font-style:italic;font-weight: bold;"
value="Customer Tracking System"></h:outputText></div>
<h:panelGrid style="width:700px;" columns="1">
<f:verbatim>
<mycomp:marqueecomp value="hello World"></mycomp:marqueecomp>
</f:verbatim>
<mycomp:marqueecomp value="hello World"></mycomp:marqueecomp>