java - 如何在Tapestry tml中进行计算?

标签 java tapestry

我是 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/

相关文章:

java - 安卓工作室-混淆器 "java.io.IOException ...bin\classes (No such file or directory)"

java - Spring JPA 有时会跳过插入实体

xml - 如何使 eclipse 格式化我的 tml 文件,就像我希望的那样?

hibernate - 使用 Spring Boot 和数据 JPA,尽管有 OpenSesionInViewFilter ,但仍然获得 LazyInitializationException

java - 如何使用Spring云总线刷新应用程序实例以及不受配置服务器控制的数据?

java - 从抽象类调用方法

java - akka actors 工具包 - context.actorOf 与 system.actorOf

java - 在 Apache Tapestry 页面访问上传的文件

Tapestry:页面刷新的方法

javascript - @PublishEvent、ajax 和传递数据