2011-06-08 74 views
4

我正在研究一个新的应用程序,我需要使用键查找值(如ConstantsWithLookup,但有能力接收参数)来查找消息接口。我正在研究Dictionary类的功能,但它缺少通过参数定制消息。GWT消息接口与查找支持

随着ConstantsWithLookup我可以做如下:

myConstantsWithLookupInterface.getString("key"); 

和得到的东西,如:

Field must be filled with numbers 

但我必须这样做:

myMessagesWithLookupInterface.getString("key", "param1", "param2",...); 

和得到的东西,如:

Field _param1_ must be filled with numbers greater than _param2_ 

我不知道该怎么做。

回答

1

使用GWT regular expressions

//fields in your class 
RegEx pattern1 = RegEx.compile("_param1_"); 
RegEx pattern2 = RegEx.compile("_param2_"); 

public String getString(String key, String replace1, String replace2){ 
    // your original getString() method 
    String content = getString(key); 
    content = pattern1.replace(content,replace1); 
    content = pattern2.replace(content,replace2); 
    return content; 
} 

如果数据中包含Field _param1_ must be filled with numbers greater than _param2_那么这将与字符串replace1的内容替换_param1_

+2

这需要使用ConstantsWithLookup,而我真的需要额外的消息功能(支持@PluralCount和SafeHtml作为返回类型)。 – 2014-12-04 10:47:56