简体   繁体   English

GWT CellTable输入验证

[英]GWT CellTable Input Validation

I would like to implement something similar to the Cell Validation showcase example, which can be found here 我想实现类似于“细胞验证”展示柜示例的方法,可以在此处找到

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

After looking through the code and trying to implement it, there seems to be a class/variable deffinition missing for template. 浏览完代码并尝试实现后,似乎缺少模板的类/变量定义。 which shows up in the code in 2 places 该代码显示在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>");
}

After searching the web i found a few examples of what the template variable definition should be and came up with 在网上搜索后,我找到了一些有关模板变量定义的示例,并提出了

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

with the above code added in there are no compiler warning howver when the code is executed i get this error 在添加了上述代码的情况下,没有编译器警告执行代码,但是出现此错误

SafeStyles used in a non-CSS attribute context. 在非CSS属性上下文中使用的SafeStyles。 Did you mean to use java.lang.String or SafeHtml instead? 您是要改用java.lang.String还是SafeHtml?

Any ideas of how to fix this problem? 关于如何解决此问题的任何想法?

The template definition you are looking for, misses the @ShowcaseSource annotation, hence you do not see it in the source tab of the validation sample. 您要查找的模板定义@ShowcaseSource批注,因此您不会在验证示例的“源”选项卡中看到它。

Anyway, here is the original code. 无论如何, 是原始代码。 And the template is: 模板是:

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

The error you see is because you are using a SafeStyle element (referenced by {1} ) as a value of the size attribute (instead of style ). 您看到的错误是因为您正在使用SafeStyle元素(由{1}引用)作为size属性(而不是style )的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM