wicket 1.5未找到错误消息

时间:2011-11-21 12:48:30

标签: java wicket wicket-1.5

我为输入创建了一个ComponentFeedbackPanel,用于显示表单组件的消息。我有传球改变的输入,你输入旧传球,新传球和重复新传球:

final PasswordTextField oldPass = createOldPassField();
final PasswordTextField newPass = createNewPassField();
final PasswordTextField newPassRepeat = createNewPassRepeatField();

add( oldPass );
add( newPass );
add( newPassRepeat );

final ComponentFeedbackPanel oldPassFeedbackPanel = new ComponentFeedbackPanel(OLD_PASS_ERROR, oldPass);
    oldPassFeedbackPanel.setOutputMarkupPlaceholderTag( true );

final ComponentFeedbackPanel newPassFeedbackPanel = new ComponentFeedbackPanel(NEW_PASS_ERROR, newPass);
    newPassFeedbackPanel.setOutputMarkupPlaceholderTag( true );

final ComponentFeedbackPanel newPassRepeatFeedbackPanel = new ComponentFeedbackPanel(NEW_PASS_REPEAT_ERROR, newPassRepeat);
    newPassRepeatFeedbackPanel.setOutputMarkupPlaceholderTag( true );

add( oldPassFeedbackPanel );
add( newPassFeedbackPanel );
add( newPassRepeatFeedbackPanel );

当我使用build-up wicket验证方法时,它非常有用: EqualPasswordInputValidation 返回输入与其中一个组件不匹配的好消息。但是,当我创建自己的类,扩展 AbstractValidator 并实现 IValidator

/**
 * Error msgs
 */
private static final String ERROR_WRONG_PASS = "wrong_pass";

(...)

private class UserPassValidator extends AbstractValidator<String> implements IValidator<String>
{
    private static final long serialVersionUID = 1L;

    @Override
    protected void onValidate( IValidatable<String> arg0 )
    {
        final String oldPass = arg0.getValue();
        if ( !user.getCryptedPassword().equals( CypherUtil.encodeMd5( oldPass ) ) )
        {
            error( arg0, ERROR_WRONG_PASS );
        }
    }

}

我收到警告,无法找到错误消息:

Could not locate error message for component: PasswordTextField@profileModifyForm:mp-oldpass and error: [ValidationError message=[null], keys=[wrong_pass, EditPassForm$UserPassValidator], variables=[]]. Tried keys: mp-oldpass.wrong_pass, wrong_pass, mp-oldpass.EditPassForm$UserPassValidator, EditPassForm$UserPassValidator.

我试图为可能与此表单连接的每个页面放置.properties,页面结构如下所示:

MainPage
  |
  |---AjaxTabbedPanels (it basically works like from wicket example http://www.wicket-library.com/wicket-examples/ajax/tabbed-panel?1)
          |
          |---ProfilePanel (extends Panel)
              |
              |---editProfileWindow (a Modal Window, opened on button click)
                   |
                   |---ProfileEditPass (extends WebPage, pageCreator for modalWindow)
                       |
                       |---EditPassForm (extends Form<Void>, class for form)
                           |
                           |--oldPass (PasswordTextField)
                           |--newPass (PasswordTextField)
                           |--newPassRepeat( PasswordTextField)
                           |--oldPassFeedbackPanel (ComponentFeedbackPanel)
                           |--...and so on for the rest

.properties文件的组合我尝试过:

mp-oldpass.wrong_pass = "Wprowadzono błędne hasło"
UserPassValidator = "Wprowadzono błędne hasło"

我试过的属性文件:

EditPassForm.properties
ProfileEditPass.properties
ProfilePanel.properties
AjaxTabbedPanels.properties
MemberTemplatePage.properties (its basically a template, extended by AjaxTabbedPanels)

1 个答案:

答案 0 :(得分:1)

您可以将以下内容添加到log4j.properties文件中,以显示有关资源本地化的更详细信息:

log4j.logger.org.apache.wicket.resource=DEBUG
log4j.logger.org.apache.wicket.Localizer=DEBUG

通过它,您将确切地看到尝试了哪些属性文件。对于验证程序,与YourWicketAppClass.properties类相同的文件夹/包中的YourWicketAppClass应该有效。