2013-07-15 37 views
0

我想实现类似于单元验证展示例如东西,这可以在这里找到GWT CellTable输入验证

http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellValidation

翻翻代码,并试图实现它之后,似乎有模板缺少类/变量定义。这表明了在2个地方

public ValidatableInputCell(String errorMessage) { 
    super("change"); 
    if (template == null) { 
    template = GWT.create(Template.class); 
    } 
    this.errorMessage = SimpleHtmlSanitizer.sanitizeHtml(errorMessage); 
} 

SafeStyles safeColor = SafeStylesUtils.fromTrustedString("color: " + color + ";"); 
sb.append(template.input(pendingValue != null ? pendingValue : value, safeColor)); 

if (invalid) { 
    sb.appendHtmlConstant(" <span style='color:red;'>"); 
    sb.append(errorMessage); 
    sb.appendHtmlConstant("</span>"); 
} 

代码搜索网站后,我发现的模板变量的定义应该是什么样的几个例子,并与

interface Template extends SafeHtmlTemplates { 
    @Template("<input type=\"text\" value=\"{0}\" tabindex=\"-1\" size=\"{1}\"></input>") 
    SafeHtml input(String value, SafeHtml safeStyles); 
} 
private Template template; 

在加入上面的代码上来当代码执行时没有编译器警告,我得到这个错误

在非CSS属性上下文中使用的SafeStyles。你的意思是使用java.lang.String还是SafeHtml?

有关如何解决此问题的任何想法?

回答

1

您正在查找的模板定义错过了@ShowcaseSource注释,因此您没有在验证示例的源选项卡中看到它。

无论如何,here是原始码。而模板是:

interface Template extends SafeHtmlTemplates { 
    @Template("<input type=\"text\" value=\"{0}\" style=\"{1}\" tabindex=\"-1\"/>") 
    SafeHtml input(String value, SafeStyles color); 
} 

您所看到的错误是因为你使用的是SafeStyle元素(由{1}引用)作为size属性(而不是style)的值。