Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从tml页面访问公共最终静态字段_Java_Tapestry - Fatal编程技术网

Java 从tml页面访问公共最终静态字段

Java 从tml页面访问公共最终静态字段,java,tapestry,Java,Tapestry,我有一个网格,我想在其中加载方法中的数据。此方法将字符串作为参数,并生成必要的列表作为输出。 例如,它可以如下所示: public List<SomeObject> getContactBasedOnType(final String type) { final List<SomeObject> returnList = new ArrayList<>(); ...//based on "type" list will

我有一个网格,我想在其中加载方法中的数据。此方法将字符串作为参数,并生成必要的列表作为输出。 例如,它可以如下所示:

public List<SomeObject> getContactBasedOnType(final String type)
    {
        final List<SomeObject> returnList = new ArrayList<>();
        ...//based on "type" list will be populated by different data
        return returnList;
    }
然后在我的tml页面中,我将按如下方式使用它:

<t:grid t:source="getSomeData('STRING')"...
>...</t:grid>
现在,我想用非组件类的公共静态字符串字段替换“字符串”,例如:

<t:grid t:source="getSomeData(com.example.Class.STATIC_FINAL_FIELD)"...
>...</t:grid>

我有没有办法直接做到这一点?那么,在组件类或注释字段中不使用任何其他方法

有一种方法可以实现你的要求,但这是一种可怕的技巧

请注意,在您的问题中,组件类中的方法名为getContactBasedOnType,而在tmls中您正在引用getSomeData。当然,方法名称必须匹配

同样,上面提到的是一个可怕的黑客攻击,但我得到的唯一解决方案是在组件类可能不被触及的约束下工作

将列表作为组件类的属性并将其填充到setupRender方法中将是一个更好的设计

<t:grid
t:source="getSomeData(getClass().getClassLoader().loadClass('com.example.Class').getField('STATIC_FINAL_FIELD').get(getClass().getClassLoader().loadClass('com.example.Class').getField('STATIC_FINAL_FIELD').getType().newInstance()))">
...
</t:grid>