0

我为我的输入制作了一个 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 );

例如,当我使用构建检票口验证方法时,它的效果很好: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)
4

1 回答 1

1

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

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

这样,您将准确看到尝试了哪些属性文件。对于验证器,YourWicketAppClass.properties在与您的类相同的文件夹/包中YourWicketAppClass应该可以工作。

于 2011-11-21T13:24:46.573 回答