2011-06-23 55 views
2

我有我自己的检票(1.5.x)自定义字符串加载器在应用程序启动时加载,它从我的数据库的字典表中提取数据。来自数据库验证器消息的自定义检票

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

我曾经试过一次solution.Here是我的代码:

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); 

其中new StringResourceModel("COMP:1:0", this, null)刚刚返回喜欢的用户名字符串...密码等

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

这是一个很好的方法吗?或者可以用其他方式完成。

谢谢。

回答

0

您可以发布'COMP:0:0'和'COMP:1:0'消息密钥的值吗?

的检票口的默认操作,您应该使用相同的语法:

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

$ {}标签或者是一个实际的标签(如果你设置一个)或现场ID(如果您没有设置标签)。