2011-06-23 57 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(如果您沒有設置標籤)。