我是 Tapestry 的新手,如果我犯了一个错误,很抱歉,我已经阅读了文档,但不知道如何在前端计算数据。
我的例子:
Hello.Java
public class Hello {
@Property
@Persist
private int numberA;
@Property
@Persist
private int numberB;
void onPrepare(){
this.numberA = 2;
this.numberB = 3;
}
}
Hello.tml
<!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" t:type="layout"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
xmlns:p="tapestry:parameter">
Total: <input type="number" value="${numberA+numberB}"></input>
</html>
运行时出现此错误:
org.apache.tapestry5.ioc.internal.util.TapestryException: Could not convert 'numberA+numberB' into a component parameter binding
任何信息将不胜感激。
谢谢
最佳答案
Tapestry 的表达式语言有意最小化,并且排除了诸如数学表达式之类的内容。任何比属性评估复杂得多的东西都属于相应的组件类(同名的 Java 文件)。否则会导致同一文件中标记和代码的混合逐渐变得越来越困惑。
只需创建一个简单的 getter - 例如 getSum() - 返回您想要的总和,然后在 tml 文件中使用表达式 ${sum}
关于java - 如何在Tapestry tml中进行计算?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49126474/