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 );
当我使用构建检票口验证方法时,它效果很好,例如: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)
I made a ComponentFeedbackPanel for my inputs where I display message for form components. I have inputs for pass change, where you type your old pass, new pass and repeat new pass:
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 );
It works great when I use build-up wicket validation methods for example: EqualPasswordInputValidation return nice message that inputs don't match next to one of the components. However when I create own class that extends AbstractValidator and implements 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 );
}
}
}
I get warning that error message could not be locate:
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.
I tried to put .properties for every single page that might be connected with this form, the page structure looks like this:
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
Combination for .properties file I tried:
mp-oldpass.wrong_pass = "Wprowadzono błędne hasło"
UserPassValidator = "Wprowadzono błędne hasło"
And properties files I tried:
EditPassForm.properties
ProfileEditPass.properties
ProfilePanel.properties
AjaxTabbedPanels.properties
MemberTemplatePage.properties (its basically a template, extended by AjaxTabbedPanels)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将以下内容添加到 log4j.properties 文件中,以显示有关资源本地化的更多详细信息:
这样,您将准确地看到尝试了哪些属性文件。对于验证器,与
YourWicketAppClass
类位于同一文件夹/包中的YourWicketAppClass.properties
应该可以工作。You can add the following to your log4j.properties file to display more verbose information about resource localization:
With that, you will see exactly which property files are tried. For validators,
YourWicketAppClass.properties
in the same folder/package as yourYourWicketAppClass
class should work.