簡體   English   中英

GWT CellTable輸入驗證

[英]GWT CellTable Input Validation

我想實現類似於“細胞驗證”展示櫃示例的方法,可以在此處找到

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?

關於如何解決此問題的任何想法?

您要查找的模板定義@ShowcaseSource批注,因此您不會在驗證示例的“源”選項卡中看到它。

無論如何, 是原始代碼。 模板是:

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

您看到的錯誤是因為您正在使用SafeStyle元素(由{1}引用)作為size屬性(而不是style )的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM