问题
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)
回答1:
You can add the following to your log4j.properties file to display more verbose information about resource localization:
log4j.logger.org.apache.wicket.resource=DEBUG
log4j.logger.org.apache.wicket.Localizer=DEBUG
With that, you will see exactly which property files are tried. For validators, YourWicketAppClass.properties
in the same folder/package as your YourWicketAppClass
class should work.
来源:https://stackoverflow.com/questions/8212055/wicket-1-5-not-found-error-message