如何使用 ZK 在 UI 中迭代和加载属性文件值? [英] How to iterate and load property file values in UI using ZK?

查看:36
本文介绍了如何使用 ZK 在 UI 中迭代和加载属性文件值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为ABC.properties"的属性文件,其值例如

I have a property file named "ABC.properties" having values such as

A="APPLE"
B="BALL"
C="CAT"

现在我需要获取这些值并加载到我的 UI 中.进行迭代,然后需要加载,因为同样明智的是,该属性文件中可能有 50 个以上的值.

Now i need to get these values and load in my UI. Have iterate and then need to load because like wise there may be more than 50 values in that property file.

有人可以帮我解决这个问题吗?

Can anyone please help me with this?

推荐答案

首先不知道是不是property文件中的项目多然后需要去取.
注意:多个属性文件都以这种方式读取并且可以在同一个地图中访问.
如果是:

First of all, I don't know if there are more items in the property file then you need to fetch.
Note : Multiple properties files all readed in this way and are accessible in the same map.
If yes :

用小节转换密钥:

FRUIT.APPLE = apple
FRUIT.ORANGE = orange
TOYS.BALL = ball
TOYS.DOLL = doll

等等.
接下来的事情就像@BhushanPatil 已经提到的:

and so on.
The next thing is as @BhushanPatil already mentioned :

在你的 zk.xml 文件中,给出你想要读取的属性文件的路径.

In your zk.xml file, give the path of properties file you wanted to read.

<zk>
    <system-config>
        <label-location>/path/to/ABC.properties</label-location>
   </system-config>
</zk>

然后你在标签.
这是我们将使用的方法.

Then you have the following method getSegmentedLabels under Labels.
This is the method we will use.

所以如果你只想在 zul 中声明它,下一步就是你必须做的:

So if you want to declare it only in the zul, the next step is what you have to do :

<?xel-method 
    prefix="prop" name="all" class="org.zkoss.util.resource.Labels"
    signature="java.util.Map getSegmentedLabels()"?>

<vlayout forEach="${prop:all().get('FRUIT')}">
    <label value="${each.key} : ${each.value}"/>
</vlayout>

Xel-method 用于声明静态方法(在 ZK 8 之前访问静态方法的唯一方法).
现在我们想要获取我们所有的 FRUIT 标签,因此我们使用 Xel 方法名称 all() 调用 getSegmentedLabels.
这将返回一个 Map,其中所有标签都在其中.
我们只对 FRUIT 小节感兴趣,所以我们得到了 FRUIT 键后面的值.
这个对象又是一个 Map,其中包含 FRUIT 下的每个键.
在这个例子中,它包含 <'APPLE','apple'>,<'ORANGE','orange'>.

The Xel-method is for declaring the static method (only way to acces a static method before ZK 8).
Now we want to get all our FRUIT labels, so we call the getSegmentedLabels with the Xel-method name all().
This return a Map<String,Object> where all the labels are in.
We are interested only in the subsection FRUIT so we get the value behind the key FRUIT.
This object is again a Map<String,Object> wich contains every key under the FRUIT.
In this example it contains <'APPLE','apple'>,<'ORANGE','orange'>.

接下来我们需要做的是迭代 Map 并显示 Map 的所有值.

The next thing we need to do is iterating over the Map and showing all the values of the Map.

我们使用 forEach 属性来实现这一点.
所以 each 对象的值现在是 Entry 类的对象.
现在唯一显示它的是显示值,使用的是 Entry.getValue().

This we do with the forEach attribute.
So the each object's value is now an Object of class Entry<String,Object>.
The only thing to show it now is showing the value, with is Entry.getValue().

这篇关于如何使用 ZK 在 UI 中迭代和加载属性文件值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆