当前位置:首页 > 开发 > Web前端 > 前端 > 正文

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

发表于: 2008-01-07   作者:chxkyy   来源:转载   浏览次数:
摘要: 问题描述:     要写一个继承<rich:dataTable>的组件。 环境: tomcat 6.0.14 myfaces1.1.5 richfaces 3.1.2 相应的配置文件如下: <?xml version="1.0" encoding="UTF-8"?> <

问题描述:

    要写一个继承<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>

还显示在页面上呢?

大家帮我看看。谢谢了!

 

 

 

 

  

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

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
有时需要写一个自定义的UITableView,这里的自定义UITableView指的是自定义列表内容,通常就是实现
  工作了这么久,封装过一部分Helper,也写过一些控件,但也没写过属于自己的框架,这次写的这个
有时候需要自定义组件使得Web程序更加丰富,ExtJS也提供了自定义组件的功能,主要通过Ext.define来
先看效果...... 现在很多的应用效果都需要做的炫些,像UC,以及天天静听,效果很炫的,源码已经对外
解决组件与父组件监听冲突问题 相信大家在做android开发的时候,都会有遇到组件与父组件的监听相互
1、效果图 2、Canvas对象详解 1.translate(x,y):平移,将画布的坐标原点向左右方向移动x,向上下方
这一次的Flex 实践将要实现以下功能: 1、自定义一个简单的 Flex 组件 2、创建一个Index. mxml 来调
AddressForm.mxml <?xml version="1.0" encoding="utf-8"?> <mx:Form xmlns:mx="http://ww
<iframe align="top" marginwidth="0" marginheight="0" src="http://www.zealware.com/46860.htm
这两天正好在做一些android方面的研究,于是乎写了一个组件,在此与大家分享交流。先上图一张,看效
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号