将keyvalue(消息key)中的动态参数传递给package.properties
我尝试将动态参数传递给 keyvalue(要显示的消息)
,我将通过 package.properties
将动态参数传递给 Action
类代码>getText() 方法。要获取消息,我们可以使用 getText(String keyvalue) 方法。我应该如何通过 getText()
方法传递一些参数并随消息检索参数?
我看到一些 API 可以传递动态参数。但我不知道如何使用,这些是以下API,请点击此处 查看 Struts 2 API 文档。
getText(String aTextName, List
getText(String key, String[] args)
getText(String key, String defaultValue, String[] args ) )
提前致谢..
I have tried to pass dynamic parameters to keyvalue(message to display)
which I will get from package.properties
to the Action
class through the getText()
method. To get the message, we can use getText(String keyvalue)
method. What should I do to pass some parameters and retrieve the parameters with the message through the getText()
method?
I saw some API's to pass dynamic parameters. But I don't know how to use, these are the following API's, click here to see the Struts 2 API Documentation.
getText(String aTextName, List<Object> args)
getText(String key, String[] args)
getText(String key, String defaultValue, String[] args)
Thanks in advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您的
package.properties
中有以下属性username.required=user name is required
password.required=password is required
您可以使用
getText()
现在如果我们想使用
getText(String key, String[] args)
我们必须传递以下参数aTextName -
需要搜索的资源包key forargs -
在 MessageFormat 消息中使用的列表 args这意味着消息格式模式和其他静态字符串当然将从资源包中获取。其他参数将在运行时动态确定。
例子
我们在资源文件中有以下条目
,其中
{1}
和{0}
是动态参数,将在运行时确定,因此args
将包含这些参数的值。所以最终调用将是
getText(disk.data, testArgs);
它将显示
Please go through MessageFormat 了解如何工作
I suppose that you have following properties in your
package.properties
username.required=user name is required
password.required=password is required
you can use
getText()
asNow if we want to use
getText(String key, String[] args)
we have to pass following parametersaTextName -
the resource bundle key that is to be searched forargs -
a list args to be used in a MessageFormat messageThat means the message format pattern and other static strings will, of course, be obtained from resource bundles. Other parameters will be dynamically determined at runtime.
example
we have following entry in resource file
in this
{1}
and{0}
are the dynamic parameters and will be determined at run time soargs
will contain the value of these parameters.So final call will be
getText(disk.data, testArgs);
and it will show
Please go through MessageFormat to know how this work