2013-07-15 35 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)的值。