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