自定义binding prefix tapestry

详细解决Vue的警告:Property or method “xxx“ is not defined on the instance but referenced during render 全网详细解决Vue的警告:Property or method "name" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property 阅读详情

在教程的第四部分(http://www.blogjava.net/usherlight/archive/2009/06/20/283396.html)我们已经粗略地介绍了Tapestry的前缀,其中提及最常用的两种literal和prop。这里顺便再介绍一下其他的几个前缀.
1、context,这个经常在引用图片的时候用到。比如:<img src="${context:images/icon.png}"/> 这样就能够在页面上显示在web-inf/images/icon.png
2、message,这个是需要I18N的应用必用的前缀。${message:some-key}
3、var,用于定义生成一个临时变量。比如:<li t:type="loop" source="1..10" value="var:index">${var:index}</li>。如果没有加这个前缀var:的话,就需要在页面类中添加一个property: index以及相应的getter和setter。
我们这次介绍自定义一个cycle前缀,这个可以用于在表格中显示不同背景的行(也就是斑马条)。
比如:
<t:grid ....  rowClass="cycle:line1,line2">
...
</t:grid>
或者
<t:loop ...>
<div class="${cycle:line1,line2}">aaaa</div>
</tloop>

自定义prefix一般来说是3个步骤,
1、定义一个BindingFactory,这个需要实现BindingFactory接口
2、定义一个Binding继承AbstractBinding
3、注册这个Binding

看一下具体的prefix的类:

 1import java.util.ArrayList;
 2import java.util.List;
 3
 4import org.apache.tapestry5.Binding;
 5import org.apache.tapestry5.BindingConstants;
 6import org.apache.tapestry5.ComponentResources;
 7import org.apache.tapestry5.ioc.Location;
 8import org.apache.tapestry5.services.BindingFactory;
 9import org.apache.tapestry5.services.BindingSource;
10
11/**
12 * Implementation of the cycle: binding prefix -- we parse list of bindings
13 * and generate delegate bindings for each element<br>
14 * default binding is literal, other bindings can be used by specifying prefix.<br>
15 * example: "cycle:prop:name,prop:lastName,sth,sth else"
16 */

17public class CycleBindingFactory implements BindingFactory {
18    private final BindingSource _bindingSource;
19
20    public CycleBindingFactory(BindingSource source){
21        this._bindingSource = source;
22    }

23    
24    public Binding newBinding(String description, ComponentResources container, ComponentResources component,
25            String expression, Location location)
26    {
27        List<Binding> delegates = new ArrayList<Binding>();
28        String[] bindingNames = expression.split(",");
29
30        for (String bindingName : bindingNames){
31            String defaultBinding = BindingConstants.LITERAL;
32
33            Binding binding = _bindingSource.newBinding(description, container, component, defaultBinding, bindingName, location);
34            delegates.add(binding);
35        }

36        
37        CycleBinding cycleBinding = new CycleBinding(delegates);
38        container.addPageLifecycleListener(cycleBinding);
39            
40        return cycleBinding;
41    }

42}

 1import java.util.List;
 2
 3import org.apache.tapestry5.Binding;
 4import org.apache.tapestry5.internal.bindings.AbstractBinding;
 5import org.apache.tapestry5.runtime.PageLifecycleListener;
 6
 7
 8public class CycleBinding extends AbstractBinding implements PageLifecycleListener{
 9    private final List<Binding> delegates;
10    private int index = 0;
11
12    public CycleBinding(List<Binding> delegates) {
13        this.delegates = delegates;
14    }

15
16    public Object get() {
17        Object ret = delegates.get(index).get();
18        index ++; 
19        if(index>=delegates.size()) index = 0;
20        return ret;
21    }

22    
23    @Override
24    public boolean isInvariant() {
25        return false;
26    }

27    
28    @Override
29    public Class<Object> getBindingType() {
30        return Object.class;
31    }

32
33
34    public void containingPageDidDetach() {
35        index=0;
36    }

37
38    public void containingPageDidAttach() {/*not interested*/}
39    
40    public void containingPageDidLoad() {/*not interested*/}
41}

Binding和BindingFactory写好了,注册后就可以使用了,注册的过程是在AppModel中添加以下一段代码:
1    public static void contributeBindingSource(
2            MappedConfiguration<String, BindingFactory> configuration,
3            BindingSource bindingSource
4            )
5    {
6        configuration.add("cycle",new CycleBindingFactory(bindingSource));
7    }
 

出现 Property or method “xx“ is not defined on the instance but referenced during render 解决方法(全面分析) 出现 Property or method "xx" is not defined on the instance but referenced during render 解决方法(全面分析) 阅读详情

相关推荐

前端项目-sortable.zip

前端项目-sortable,最简单、最优雅的表格排序方法。

Tapestry 最新版5.1.0.5教程(十二):自定义前缀prefix

<br />在教程的第四部分(http://www.blogjava.net/usherlight/archive/2009/06/20/283396.html)我们已经粗略地介绍了Tapestry的前缀,其中提及最常用的两种literal和prop。这里顺便再介绍一下其他的几个前缀.<br />1、context,这个经常在引用图片的时候用到。比如:<img src="${context:images/icon.png}"/> 这样就能够在页面上显示在web-inf/images/icon.png<br

maniacbin 631

SUMO从入门到精通:手把手教你用开源工具完成智能网联车仿真(附Python接口教程)

本文提供了一份SUMO开源交通仿真工具的完整实战指南,从环境搭建、基础仿真到Python接口TraCI的深度应用。重点讲解了如何利用SUMO的高度可定制性进行智能网联车仿真,包括实现动态信号优先等核心算法,并介绍了与网络仿真器集成以构建高保真车联网通信环境的方法。

weixin_28327051的博客 538

Tapestry组件前序

1.字符串转换为日期<br />Date dt = new Date();<br />  try {<br />   dt = new   SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2010-04-14 00:00:00");<br />  } catch (ParseException e) {<br />   e.printStackTrace();<br />  }2. 变量类型默认初始值<br />int类型变量默认初始值为0<br />float

sun5208的专栏 700

雷光联动自动化标校方法

动态标校需要利用动目标,在雷达和光电同时看到目标时记录光电的方位、俯仰,以及利用雷达给的目标信息计算的方位俯仰,手动记录两者的数值,多方位,多距离段记录,费时费力,且人工记录数据不全,计算容易出差错,耗费成本和精力太大。目标相距设备的水平距离 = acos(cos(设备纬度弧度值) * cos(目标纬度弧度值) * cos(设备经度弧度值 – 目标经度弧度值) + sin(设备纬度弧度值) * sin(目标纬度弧度值)) * 6378137;本发明涉及光电技术领域,安防领域,尤其涉及雷达光电动态标校等。

u013358093的博客 1580

ScottPlot vs LiveCharts:WPF图表库性能对比与MVVM适配方案

本文深度对比了WPF图表库ScottPlot与LiveCharts在性能与MVVM架构适配上的表现。通过十万级数据点的基准测试,ScottPlot在渲染速度与内存占用上优势显著。文章重点探讨了两种库在MVVM模式下的集成方案,为开发者根据项目需求(如实时监控或快速原型)进行技术选型提供了实战指导。

lll78的博客 245

BUG汇总 ---- 每日更新

spring boot 中的bug解决

weixin_46048259的博客 1023

信号编辑软件ZX/SignalEditing

信号编辑软件ZX/SignalEditing

weixin_45661395的博客 958

“Property or method “***“ is not defined on the instance but referenced during render.”报错的原因及解决方案

报错问题: 在使用vue-cli运行项目的过程中,在VScode中不报错,但在浏览器调试工具中发出 [Vue warn]: Property or method "pic" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by in.

酷爱前端的小陈博客 18万+

SpringCloud Alibaba - Seata 实现高可用和异地容灾

这里不仅仅要实现高可用,还需要实现异地容灾. 异地容灾就是说,如果你整了好几个节点部署起来,全部放到一个机房里面,那么如果这个机房出了故障,就意味着整个集群就完了,所以对于一个大型的集群来讲,都会把这些服务异地部署.问题2:如果我们要实现异地容灾,也就说某一个机房挂了,需要快速的切换到另一个可用的机房,但是这个配置在配置文件中写死了,如果要改配置文件,还需要重启服务器,这是我们不希望看到的,怎么办?进入 seata/bin 目录,运行 seata-server.bat 文件,默认端口为 8091。

CYK_byte的博客 975

【AI智能体】Skills 智能体驱动开发从使用到项目实战详解

Skills 智能体驱动开发从使用到项目实战详解

congge 6608

Vue报错笔记(1) [Vue warn]: Property or method "name" is not defined on the instance but referenced.....

  [Vue warn]: Property or method "name" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. 原因:在data中没有定义一个name, 致错 解决方...

qq_28659933的博客 8万+

华为OD机试 - 音乐小说内容重复识别 - 并查集(Java 双机位C卷 200分)

华为OD机试 双机位C卷题库疯狂收录中,刷题。

学Java,找哪吒 159

(转载)Tapestry最新版5.1.0.5教程(十二):自定义前缀prefix

在教程的[url=http://guofengcn.iteye.com/blog/828488]第四部分[/url]我们已经粗略地介绍了Tapestry的前缀,其中提及最常用的两种literal和prop。这里顺便再介绍一下其他的几个前缀。 1、context,这个经常在引用图片的时候用到。 比如: [code="html"] [/code] 这样就能够...

guofengcn的专栏 187

彻底解决JDK安装包点击后无反应

jdk双击无法安装,jdk双击没反应,jdk安装包双击后没反应。

renkai721的专栏 8939

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Property or method “xxx“ is not defined on the instance but referenced during render.

解决方法:查看相应位置的代码,未定义的方法在methods中进行定义,名称不一致的改成一致的。错误原因:一种是未定义的方法被引用;另一种是定义了方法,但是定义的名称和引用的名称不一致。方法或特性违背定义就被引用。点击的事件处理是无效的。

lingxi53的博客 7495

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

vue组件Property or method “row” is not defined on the instance but referenced during render报错原因及解决办法

vue组件Property or method “row” is not defined on the instance but referenced during render报错原因及解决办法 在做表格计算方法时遇到报错 开始以为是某个地方未定义,找了半天,又百度了半天,找到的比较好的答案是:“在使用VUE的elementui组件渲染表格时,不能在渲染过程中对row的属性做修改!引用row会报错!//结论:最好不要在模板中使用方法计算row的属性值”。 结果错误原因是在用@change传参数时的参数命

Codeape_Sn的博客 9210

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Vue2.0出现 tableRowClassName is not defined 的问题

在Vue项目中遇到prototype of tableClassName is not defined的问题 出现的警告指向连接深度反应性https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties在这里我用的是Element 2.13.0,是因为Vue的深度反应性导致不能给Dom动态添加 所以需要给table绑定...

你若成风,我则化雨 2533

报错:Property or method “xxx“ is not defined on the instance but referenced during render.

因为无法确保该属性在挂载前已经初始化,不能保证该属性是响应式的,有的时候这种错误写法带来的报错不会对页面展示有任何影响,有时反复刷新页面数据会时而正常显示,时而不显示,有的时候则反复刷新也完全无法显示。分析:这个错误的解释很明确,属性“tableData”并没有在“Data”中定义,而是直接在页面初始化的过程中对其进行赋值并在页面中引用其数据。属性或方法“tableData”不是在实例上定义的,而是在呈现期间被引用的。通过初始化该属性,确保该属性是响应性的,无论是在data选项中,还是在基于类的组件中。

IT枫斗者的博客 2941

Property or method “XXX“ is not defined on the instance but referenced during render. Make sure that

Property or method "xxxxx" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See:

SSHLY3的博客 1157

如何解决 Property or method “rowView“ is not defined on the instance but referenced during render. 报错

但在渲染过程中被引用。通过初始化属性,确保该属性在数据选项中或在基于类的组件中是反应性的。“click”的事件处理程序出错:“TypeError:_vm.rowView不是函数”未改之前,我将name="详情" 写成了:name="详情"(属性或方法“详情“未在实例上定义,但在渲染过程中引用。,对话框弹不出来,F12查看Console 就已经报错了。我的原因是将View()方法写在了methods的外面。将View()方法放到methods中就行了。返回的data(){}中我写的是。

明思齐的博客 1956

已定义,但提示 Property or method is not defined

分明已经定义了变量name,但依然提示: [Vue warn]: Property or method "name" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. 原

QQ2856639881的专栏 1万+

Vue报错笔记(1)vue.js:515 [Vue warn]: Property or method “name“ is not defined on the instance but refere

报错:vue.js:515 [Vue warn]: Property or method "name" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. (found in root instan

Blog 5万+

class not defined

运行时找不到类错误可能原因:(1)、类名错误(2)、没有导入包(3)、classPath设置有错误。

ld513508088的专栏 922
上一篇: Using mockito in java
下一篇: ibaits与hibernate的比较
mrying
博客等级 码龄17年 18粉丝 17原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值