Java 抑制Vaadin中表格中零值整数的显示
与财务表中常见的情况一样,我希望在我的Vaadin表中禁止显示零整数的“0”。如果零值以各种其他方式呈现,则其他数字会变得更加明显:Java 抑制Vaadin中表格中零值整数的显示,java,vaadin,Java,Vaadin,与财务表中常见的情况一样,我希望在我的Vaadin表中禁止显示零整数的“0”。如果零值以各种其他方式呈现,则其他数字会变得更加明显: 空字符串 您可以使用两种方法之一来抑制零值的显示。如果您有许多表和/或某些数据类型的许多列需要这种行为,那么第一种方法很方便。第二个用于特定的单独列 重写formatPropertyValue 您可以在自己的表子类中重写该方法。此方法在显示每个表格单元格时调用。通过测试整型对象的大小写,您可以覆盖为显示给用户而生成的字符串 这种方法应该适用于Vaadin版本
- 空字符串
formatPropertyValue
您可以在自己的表子类中重写该方法。此方法在显示每个表格单元格时调用。通过测试整型对象的大小写,您可以覆盖为显示给用户而生成的字符串
这种方法应该适用于Vaadin版本3.1到7.x
此方法会影响该目标数据类型表中的所有列
// A subclass of Vaadin Table to override formatting of Integer zero values.
public class NonZeroTable extends Table
{
@Override
protected String formatPropertyValue ( Object rowId , Object colId , Property property )
{
// Suppress display of zero-value Integers.
// If the Property is of type Integer with a Value of zero, handle it here.
// For other Property or Value, fallback to the default handling in the Table.
if ( property.getType() == Integer.class ) {
if ( property.getValue().equals( 0 ) ) {
return ""; // Return empty string, to suppress display of zero.
// return "\u2013"; // EN DASH
// return "\u2014"; // EM DASH
}
}
return super.formatPropertyValue( rowId , colId , property );
}
}
感谢收集提供此信息的
为每列指定转换器
或者,您可能希望控制特定列的格式。如果是,请按照页面上的说明为该列提供一个名称
转换器位于。您可以使用两种方法之一来抑制零值的显示。如果您有许多表和/或某些数据类型的许多列需要这种行为,那么第一种方法很方便。第二个用于特定的单独列 重写
formatPropertyValue
您可以在自己的表子类中重写该方法。此方法在显示每个表格单元格时调用。通过测试整型对象的大小写,您可以覆盖为显示给用户而生成的字符串
这种方法应该适用于Vaadin版本3.1到7.x
此方法会影响该目标数据类型表中的所有列
// A subclass of Vaadin Table to override formatting of Integer zero values.
public class NonZeroTable extends Table
{
@Override
protected String formatPropertyValue ( Object rowId , Object colId , Property property )
{
// Suppress display of zero-value Integers.
// If the Property is of type Integer with a Value of zero, handle it here.
// For other Property or Value, fallback to the default handling in the Table.
if ( property.getType() == Integer.class ) {
if ( property.getValue().equals( 0 ) ) {
return ""; // Return empty string, to suppress display of zero.
// return "\u2013"; // EN DASH
// return "\u2014"; // EM DASH
}
}
return super.formatPropertyValue( rowId , colId , property );
}
}
感谢收集提供此信息的
为每列指定转换器
或者,您可能希望控制特定列的格式。如果是,请按照页面上的说明为该列提供一个名称
转换器位于。您可以使用两种方法之一来抑制零值的显示。如果您有许多表和/或某些数据类型的许多列需要这种行为,那么第一种方法很方便。第二个用于特定的单独列 重写
formatPropertyValue
您可以在自己的表子类中重写该方法。此方法在显示每个表格单元格时调用。通过测试整型对象的大小写,您可以覆盖为显示给用户而生成的字符串
这种方法应该适用于Vaadin版本3.1到7.x
此方法会影响该目标数据类型表中的所有列
// A subclass of Vaadin Table to override formatting of Integer zero values.
public class NonZeroTable extends Table
{
@Override
protected String formatPropertyValue ( Object rowId , Object colId , Property property )
{
// Suppress display of zero-value Integers.
// If the Property is of type Integer with a Value of zero, handle it here.
// For other Property or Value, fallback to the default handling in the Table.
if ( property.getType() == Integer.class ) {
if ( property.getValue().equals( 0 ) ) {
return ""; // Return empty string, to suppress display of zero.
// return "\u2013"; // EN DASH
// return "\u2014"; // EM DASH
}
}
return super.formatPropertyValue( rowId , colId , property );
}
}
感谢收集提供此信息的
为每列指定转换器
或者,您可能希望控制特定列的格式。如果是,请按照页面上的说明为该列提供一个名称
转换器位于。您可以使用两种方法之一来抑制零值的显示。如果您有许多表和/或某些数据类型的许多列需要这种行为,那么第一种方法很方便。第二个用于特定的单独列 重写
formatPropertyValue
您可以在自己的表子类中重写该方法。此方法在显示每个表格单元格时调用。通过测试整型对象的大小写,您可以覆盖为显示给用户而生成的字符串
这种方法应该适用于Vaadin版本3.1到7.x
此方法会影响该目标数据类型表中的所有列
// A subclass of Vaadin Table to override formatting of Integer zero values.
public class NonZeroTable extends Table
{
@Override
protected String formatPropertyValue ( Object rowId , Object colId , Property property )
{
// Suppress display of zero-value Integers.
// If the Property is of type Integer with a Value of zero, handle it here.
// For other Property or Value, fallback to the default handling in the Table.
if ( property.getType() == Integer.class ) {
if ( property.getValue().equals( 0 ) ) {
return ""; // Return empty string, to suppress display of zero.
// return "\u2013"; // EN DASH
// return "\u2014"; // EM DASH
}
}
return super.formatPropertyValue( rowId , colId , property );
}
}
感谢收集提供此信息的
为每列指定转换器
或者,您可能希望控制特定列的格式。如果是,请按照页面上的说明为该列提供一个名称
转换器在中。转换器是Vaadin 7中的推荐方式。@HenriKerola您能引用一些文档或进一步讨论该建议吗?查看了7.3的源代码后,我看到
formatPropertyValue
方法只需调用已安装或默认的转换器。所以,在我的例子中,如果您有许多表,其中有许多列需要这种行为,那么子类化表以覆盖该方法似乎是合适的。转换器是Vaadin 7中推荐的方法。@HenriKerola您可以引用一些文档或进一步讨论该建议吗?查看了7.3的源代码后,我看到formatPropertyValue
方法只需调用已安装或默认的转换器。所以,在我的例子中,如果您有许多表,其中有许多列需要这种行为,那么子类化表以覆盖该方法似乎是合适的。转换器是Vaadin 7中推荐的方法。@HenriKerola您可以引用一些文档或进一步讨论该建议吗?查看了7.3的源代码后,我看到formatPropertyValue
方法只需调用已安装或默认的转换器。所以,在我的例子中,如果您有许多表,其中有许多列需要这种行为,那么子类化表以覆盖该方法似乎是合适的。转换器是Vaadin 7中推荐的方法。@HenriKerola您可以引用一些文档或进一步讨论该建议吗?查看了7.3的源代码后,我看到formatPropertyValue
方法只需调用已安装或默认的转换器。所以,若像在我的例子中一样,您有许多表,其中有许多列,您希望这种行为,那个么子类化表以覆盖该方法似乎是合适的。