Myfaces+Richfaces的自定义组件问题。

问题描述:

    要写一个继承<rich:dataTable>的组件。

环境:

  • tomcat 6.0.14
  • myfaces1.1.5
  • richfaces 3.1.2

相应的配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			classpath:spring-platform-base.xml,classpath:spring-platform-service.xml
		</param-value>
	</context-param>
	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>
	<description>Platform Application</description>
	<display-name>Platform</display-name>
	<context-param>
		<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
		<param-value>.xhtml</param-value>
	</context-param>
	<context-param>
		<param-name>facelets.REFRESH_PERIOD</param-name>
		<param-value>2</param-value>
	</context-param>
	<context-param>
		<param-name>facelets.DEVELOPMENT</param-name>
		<param-value>true</param-value>
	</context-param>
	<context-param>
		<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
		<param-value>server</param-value>
	</context-param>
	<context-param>
		<param-name>com.sun.faces.validateXml</param-name>
		<param-value>true</param-value>
	</context-param>
	<context-param>
		<param-name>com.sun.faces.verifyObjects</param-name>
		<param-value>true</param-value>
	</context-param>

	<context-param>
		<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
		<param-value>com.sun.facelets.FaceletViewHandler</param-value>
	</context-param>
	<context-param>
		<param-name>org.ajax4jsf.COMPRESS_SCRIPT</param-name>
		<param-value>false</param-value>
	</context-param>

	<filter>
		<display-name>Ajax4jsf Filter</display-name>
		<filter-name>ajax4jsf</filter-name>
		<filter-class>org.ajax4jsf.Filter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>ajax4jsf</filter-name>
		<servlet-name>Faces Servlet</servlet-name>
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>INCLUDE</dispatcher>
		<dispatcher>ERROR</dispatcher>
	</filter-mapping>
	<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>*.jsf</url-pattern>
	</servlet-mapping>
	<login-config>
		<auth-method>BASIC</auth-method>
	</login-config>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>index.html</welcome-file>
	</welcome-file-list>

	<!-- 标签配置开始 -->

	<!-- 标签配置结束 -->
</web-app>

 

tag组件源文件:PFHtmlTableGridTag.java

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

public class PFHtmlTableGridTag extends UIComponentTag {
	
	public PFHtmlTableGridTag() {
		System.out.println("hello world");
	}

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

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

	@Override
	protected void setProperties(UIComponent component) {
		super.setProperties(component);
	}

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

 

component组件PFHtmlTableGrid.java

import java.io.IOException;
import java.util.Date;

import javax.faces.component.html.HtmlDataTable;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

public class PFHtmlTableGrid extends HtmlDataTable {
	@Override
	public void encodeBegin(FacesContext context) throws IOException {
		ResponseWriter writer = context.getResponseWriter();
		writer.startElement("div", this);
		writer.writeAttribute("style", "color:red", null);
		writer.writeText("Hello World! today is:"+new Date(), null);
		writer.endElement("div");
	}
		
	@Override
	public void encodeEnd(FacesContext context) throws IOException {

	}
	
	@Override
	public void decode(FacesContext context) {
		super.decode(context);
	}
	
	@Override
	public String getFamily() {
		return null;
	}
}

 

faces-config.xml相应配置:

<component>
		<component-type>
			PFHtmlTableGrid
		</component-type>
		<component-class>
			com.dongyun.platform.component.jsf.tablegrid.PFHtmlTableGrid
		</component-class>
	</component>

 

标签库文件(存放在WEB/INF目录下):

 

<?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>
	<!-- ============== Tag Library Description Elements ============= -->
	<tlib-version>1.2</tlib-version>
	<jsp-version>1.2</jsp-version>
	<short-name>tags</short-name>
	<uri>/WEB-INF/tags.tld</uri>
	<display-name>bookstore</display-name>
	<description>
		This tag library contains tags used by the bookstore
		application.
	</description>

	<!-- ===================== tags for image map component ============================ -->
	<tag>
		<name>tableGrid</name>
		<tag-class>
			com.dongyun.platform.component.jsf.tablegrid.PFHtmlTableGridTag
		</tag-class>
		<description>
			Description of a single hotspot in a client side image map.
			This tag MUST be nested inside a <map> tag. To specify
			the hotspot characteristics, you must specify EITHER a value
			OR the alt, coords, and shape attributes.
		</description>
	</tag>
</taglib>
 

 

引用该自定义标签的页面:

<?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:rich="http://richfaces.org/rich"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j" 
	xmlns:cd="/WEB-INF/tags.tld"
	xml:lang="en" lang="en">
	<head>
		<title>日志管理界面</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" />
	</head>
	<body>
		<cd:tableGrid />
	</body>
</html>

 

tomcat正常启动没有问题。但是当用firefox打开这个Log.jsf页面时,什么东西都没显示出来。

查看其原代码如下:

<?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:cd="/WEB-INF/tags.tld" xml:lang="en" lang="en">
	<head>
		<title>日志管理界面</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" />
	</head>
	<body>

		<cd:tableGrid></cd:tableGrid>
	</body>
</html>

 

是不是xhtml什么地方没配对,为什么

<cd:tableGrid></cd:tableGrid>

还显示在页面上呢?

大家帮我看看。谢谢了!

 

 

 

 

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值