tapestry3创建自己定义组件

两种方法创建自己定义标签:

一.通过AbstractComponent父类渲染,此种方法直接在java类中编写页面脚本。然后输出。

1.编写java类com/ailk/ech/ecop/view/test/jwc/LiuzfTest2.java

package com.ailk.ech.ecop.view.test.jwc;

import org.apache.tapestry.AbstractComponent;
import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;

public abstract class LiuzfTest2 extends AbstractComponent{
	public abstract String getLink();
	public abstract String getValue();
	@Override
	protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
		// TODO Auto-generated method stub
		writer.begin("a");
		writer.attribute("href", getLink());
		writer.print(getValue());
		renderInformalParameters(writer, cycle);
	}
}

2.编写jwc配置文件web\ecop\test\jwc\LiuzfTest2.jwc。定义组件參数和映射的java类

<?

xml version="1.0" encoding="UTF-8"?> <!DOCTYPE component-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN" "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd"> <component-specification allow-body="yes" allow-informal-parameters="yes" class="com.ailk.ech.ecop.view.test.jwc.LiuzfTest2"> <parameter name="value" direction="in" type="java.lang.String"/> <parameter name="link" direction="in" type="java.lang.String"/> </component-specification>

3.在application中引入组件

<component-type type="LiuzfTest2" specification-path="/ecop/test/jwc/LiuzfTest2.jwc"/>

4.然后就能够使用了,使用效果。输出一个<a href=" http://www.baidu.com">test2</a>

<span jwcid="@LiuzfTest2" link="http://www.baidu.com" value="test2" />



二.通过BaseComponent父类渲染,此种方法须要定义html规范,通过html规范输出html代码,无需在java类中输出html

1.编写java类LiuzfTest3.java

package com.ailk.ech.ecop.view.test.jwc;

import org.apache.tapestry.AbstractComponent;
import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;

public abstract class LiuzfTest3 extends BaseComponent{
	public abstract String getLink();
	public abstract String getValue();
}
2.编写jwc配置文件,定义组件的參数。映射类

<?

xml version="1.0" encoding="UTF-8"?> <!DOCTYPE component-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN" "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd"> <component-specification allow-body="yes" allow-informal-parameters="yes" class="com.ailk.ech.ecop.view.test.jwc.LiuzfTest3"> <parameter name="value" direction="in" type="java.lang.String"/> <parameter name="link" direction="in" type="java.lang.String"/> </component-specification>

3.编写html规范,html文件与jwc配置文件放在同一个文件夹下

<html>   
<body jwcid="$content$">   
<hr>   
<a jwcid="@Any" href="ognl:link"><span jwcid="@Insert" value="ognl:value"></span></a>
</body>   
</html>
4.在application中引入这个组件

<component-type type="LiuzfTest3" specification-path="/ecop/test/jwc/LiuzfTest3.jwc"/>
5然后就能够使用了,效果也是输出一个链接

<td><span jwcid="@LiuzfTest3" link="http://www.baidu.com" value="test3"  /></td>








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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值