【问题标题】:Custom wicket from validator message from database来自数据库的验证器消息的自定义检票口
【发布时间】:2011-06-23 15:09:10
【问题描述】:

我在应用程序启动时加载了自己的 wicket(1.5.x) 自定义字符串加载器,它从我的数据库中的字典表中获取数据。

现在,尽管加载了默认字符串加载器,但当我使用此加载器时;在我的验证文本中,它不会像用户名/密码那样显示 ${component} 标签。它就像“字段''是必需的”,其中提交的名称保持为空。我该如何解决这个问题?

我尝试了一种解决方案。这是我的代码:

1) 我在我的应用程序类中加载了我的字符串加载器:

  getResourceSettings().getStringResourceLoaders().add(0,
            new ClassStringResourceLoader(MyApplication.class));

    getResourceSettings().getStringResourceLoaders()
       .add(1, new DictionaryLoader((IDicitureService)
        applicationContext.getBean(IDicitureService.class)));

这里的DictionaryLoader 只是IStringResourceLoader 的一个实现。

2) 在我的登录表单中,我添加了这样的用户名和密码字段:

    final FeedbackPanel feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    form.add(feedback);
    form.add(new FormComponentFeedbackBorder("username_border")
            .add(new RequiredTextField("username",String.class)
                    .setLabel(new StringResourceModel("COMP:0:0", this, null))));
    form.add(new FormComponentFeedbackBorder("password_border").
            add(new PasswordTextField("password")
                    .setLabel(new StringResourceModel("COMP:1:0", this, null))));
    add(form);

wherenew StringResourceModel("COMP:1:0", this, null) 只返回一个字符串,如用户名...密码等。

现在,如果我检查我的页面,当我使用 TextField.setLabel() 实际上是用于验证器标签时,它会用我提供的文本替换验证器内容。但我没有在这里使用 ${label}。

这是一个好方法吗?或者可以通过其他方式完成。

谢谢。

【问题讨论】:

    标签: java wicket


    【解决方案1】:

    您可以发布“COMP:0:0”和“COMP:1:0”消息键的值吗?

    您应该使用与默认情况下 wicket 相同的语法:

    Required=Field '${label}' is required.
    

    ${label} 是实际标签(如果您设置了标签)或字段 ID(如果您没有设置标签)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-21
      • 2013-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-24
      相关资源
      最近更新 更多