2011-05-24 71 views

回答

5

我发现这个使用javascript的解决方案。这是因为GWT不支持Collat​​or。

http://osdir.com/ml/GoogleWebToolkit/2009-06/msg01572.html

public class Collator { 

    public static final Collator getInstance() { 
     return instance; 
    } 

    private static final Collator instance = new Collator(); 

    public native int compare(String source, String target); /*-{ 
    return source.localeCompare(target); 
    }-*/ 
} 

我从来没有使用过个人,但它看起来很有希望。 您可能需要进行更改才能确保没有跨浏览器问题。

编辑:
阅读JSNI。
这允许GWT在你的Java代码中调用原始的“javascript”代码。这就是我们在上述课堂上所做的。 “比较”方法使本地调用javascript。
http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html#writing

将Collat​​or.java添加到您当前的工作空间。

您应该能够比较如下。

Collator customCollator = Collator.getInstance(); 
if (customCollator.compare(srcString , targetString) > 0) 
{ 
    //the compare method will return an int. 
    // write your code here. 
} 

希望这会有所帮助。

+0

我发现它也,但我不知道如何使用它;/ – Samoth 2011-05-30 10:30:13

+0

@Samoth希望帮助。编辑我的回答 – 2011-05-30 12:37:03

+0

是的,它帮助我:)谢谢! – Samoth 2011-05-30 12:56:57

0

最简单的方法是将locale属性添加到常量类。

我有的像这样

import com.google.gwt.i18n.client.Constants; 

public interface GeneralConstants extends Constants { 

    @DefaultStringValue("de") 
    String locale(); 

定义的GeneralConstants类在每一个常量I类可以继承的语言环境,我可以把它在每一种语言很容易地定义

知道我是什么样的语言环境。我只是叫属性

private static GeneralConstants c = GWT.create(GeneralConstants.class); 

...

formData.getForm().getName(c.locale()) 

还有一种方式来获得当前设置的语言环境,但我不记得:-)

+2

这对字符串比较有帮助吗? – Smalcat 2013-04-30 10:15:09