一个Wicket验证示例

Java文件:
add(new RequiredMaxLengthTextField("name", new PropertyModel<String>(getData(), "name")).add(new AbstractValidator<String>() {
      @Override
      protected void onValidate(IValidatable<String> validatable)
      {
        final String groupname = validatable.getValue();
        if (groupname == null) {
          return;
        }
        getData().setName(groupname);
        if (groupDao.doesGroupnameAlreadyExist(getData()) == true) {
          error(validatable);
        }
      }

      @Override
      protected String resourceKey()
      {
        return "group.error.groupnameAlreadyExists";
      }
    }));


I18nResources.properties文件:
group.error.groupnameAlreadyExists=Group name already exists.

你可能感兴趣的:(验证,wicket)