简体   繁体   English

Tapestry5 Grid Componenet中的翻译器功能

[英]Translator functionality in Tapestry5 Grid Componenet

Today I will have question regarding formatting numbers in Tapestry5 grid. 今天,我将对在Tapestry5网格中格式化数字有疑问。 I have couple of fields in Grid component that I need to format due to some rules that concerns decimal mark and thousands separator. 由于一些涉及小数点和千位分隔符的规则,我需要格式化Grid组件中的几个字段。 For textfields I'm using translator defined for whole application (like in this example) but I have no idea how to get same functionality for grid (or even if it is possible at all).I would like to have same mechanism available for all grids in my whole applications. 对于文本字段,我正在使用为整个应用程序定义的翻译器(如例所示),但我不知道如何为网格获得相同的功能(甚至根本不可能)。我希望对所有对象都具有相同的机制整个应用程序中的网格。

Of course not all numeric grid field will be currencies so there should be some kind of possibility to configure them. 当然,并非所有的数字网格字段都将是货币,因此应该有某种可能性来配置它们。

I know that with grid I can use ValueEncoder but I think that this won't work in that case because it encodes whole object displayed in grid, not only some defined fields. 我知道使用网格可以使用ValueEncoder,但是我认为在这种情况下这是行不通的,因为它可以对显示在网格中的整个对象进行编码,而不仅仅是对某些定义的字段进行编码。

One more thing: I know that I can define each field to get value from method and there do all functionality, but I'm looking for something more flexible - like mentioned earlier "translator" for textfields. 还有一件事:我知道我可以定义每个字段以从方法中获取值,并且可以完成所有功能,但是我正在寻找更灵活的东西-如前面提到的用于文本字段的“翻译器”。

You can override the default grid cell rendering behaviour by defining a block property named xCell (where x is the column name). 您可以通过定义一个名为xCell的块属性(其中x是列名)来覆盖默认的网格单元格渲染行为。 The documentation gives an example of customising rendering of the lastName column. 文档提供了一个自定义lastName列呈现的示例。

<t:grid source="users" row="user">
    <p:lastNameCell>
        <t:pagelink page="user/view" context="user.id">${user.lastname}</t:pagelink>
    </p:lastNameCell>
</t:grid>

This can be done by the combination of a few things 这可以通过几件事的组合来完成

  1. A DataTypeAnalyzer which produces a String datatype given a PropertyAdapter 一个DataTypeAnalyzer ,它在给定PropertyAdapter的情况下生成String数据类型
  2. A DisplayBlockContribution which maps the datatype to a block (see also EditBlockContribution). 一个DisplayBlockContribution ,它将数据类型映射到块(另请参见EditBlockContribution)。
  3. Contribute the DisplayBlockContribution to the BeanBlockSource 将DisplayBlockContribution贡献给BeanBlockSource

Note that this will not only affect the grid, it will also affect all bean based components (eg BeanDisplay). 注意,这不仅会影响网格,还将影响所有基于bean的组件(例如BeanDisplay)。

Jumpstart example here 快速入门示例在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM