【发布时间】:2011-11-07 04:01:55
【问题描述】:
当您输入电子邮件、旧密码、新密码并重复新密码以修改您的个人资料时,我有一些基本表格。我想要实现的是在通过错误时显示反馈消息。一段代码如下所示:
public class EditProfileForm extends Form<Void>
{
private static final long serialVersionUID = 1L;
// El-cheapo model for form
private final ValueMap properties = new ValueMap();
private ModalWindow modalWindow;
@SpringBean
UserManager userManager;
@SpringBean
Validator validator;
private User user;
private static final String EMAIL = "mp-email";
private static final String OLD_PASS = "mp-oldpass";
private static final String NEW_PASS = "mp-newpass";
private static final String NEW_PASS_REPEAT = "mp-newpassrepeat";
private static final String ERROR_WRONG_PASS = "Wrong pass";
private static final String ERROR_PASS_DIFF = "Pass diff";
private static final String ERROR_EMAIL_INVALID = "Wrong email";
private static final String ERROR_EMAIL_EXISTS = "Email used";
public EditProfileForm( String id, final ModalWindow modalWindow,final User u )
{
super( id );
this.user = u;
this.modalWindow = modalWindow;
add( new TextField<String>( EMAIL, new PropertyModel<String>( properties, EMAIL ) ).setRequired(true).setOutputMarkupId(true) );
add( new PasswordTextField( OLD_PASS, new PropertyModel<String>( properties, OLD_PASS ) ).setOutputMarkupId(true) );
add( new PasswordTextField( NEW_PASS, new PropertyModel<String>( properties, NEW_PASS ) ).setOutputMarkupId(true) );
add( new PasswordTextField( NEW_PASS_REPEAT, new PropertyModel<String>( properties, NEW_PASS_REPEAT ) ).setOutputMarkupId(true) );
final FeedbackPanel feedbackPanel = new FeedbackPanel( "feedback" );
feedbackPanel.setOutputMarkupId( true );
//feedbackPanel.setMaxMessages( 5 );
add( feedbackPanel );
AjaxSubmitLink closeBtn = new AjaxCloseCancelBtn( "close-x", this );
AjaxSubmitLink cancelBtn = new AjaxCloseCancelBtn( "cancel", this );
add( new AjaxSubmitLink( "save", this )
{
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit( AjaxRequestTarget target, Form<?> form )
{
if ( !user.getCryptedPassword().equals( CypherUtil.encodeMd5( getOldPassword() ) ) )
{
error( ERROR_WRONG_PASS );
}
else if ( !getNewPassword().equals( getNewPasswordRepeat() ) )
{
error( ERROR_PASS_DIFF );
}
else if ( !validator.validateEmailFormat( getEmail() ) )
{
error( ERROR_EMAIL_INVALID );
}
else if ( validator.emailExists( getEmail() ) )
{
error( ERROR_EMAIL_EXISTS );
} else
{
//save user data
}
}
@Override
protected void onError( AjaxRequestTarget target, Form<?> form )
{
target.add( feedbackPanel );
}
} );
add( closeBtn );
add( cancelBtn );
}
/**
* @return
*/
private String getEmail()
{
return properties.getString( EMAIL );
}
/**
* @return
*/
private String getOldPassword()
{
return properties.getString( OLD_PASS );
}
/**
* @return
*/
private String getNewPassword()
{
return properties.getString( NEW_PASS );
}
/**
* @return
*/
private String getNewPasswordRepeat()
{
return properties.getString( NEW_PASS_REPEAT );
}
}
现在,当我将这些表单留空时,我会收到很好的反馈消息,表明有字段是必需的。同时,当我输入错误的通行证、电子邮件或其他任何内容时,我一无所获,并且我的服务器日志留下这样的消息:
WARNING: Component-targetted feedback message was left unrendered.
This could be because you are missing a FeedbackPanel on the page.
Message: [FeedbackMessage message = "Wrong pass", reporter = save, level = ERROR]
表单位于弹出式网页中:
public class ProfilePopup extends WebPage
{
private static final long serialVersionUID = 2929269801026361184L;
public ProfilePopup(final ModalWindow modal, final User user)
{
add( new EditProfileForm("profileModifyForm", modal, user).setOutputMarkupId(true) );
}
}
和 HTML,将反馈放在表单之外也无济于事:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body class="stats-popup-body">
<div class="stats-popup" id="car-info-edit-popup">
<p class="popup_title"> Edytuj Profilu </p>
<form wicket:id="profileModifyForm" class="stats-popup-form">
<div>
<label class="popup_field_label">Email:</label>
<input type="text" wicket:id="mp-email" />
</div>
<div class="clear9"></div>
<div>
<label class="popup_field_label">Stare hasło:</label>
<input type="password" name="E-mail" title="E-mail1" id="E-mail2" wicket:id="mp-oldpass" />
</div>
<div>
<label class="popup_field_label">Nowe hasło:</label>
<input type="password" wicket:id="mp-newpass" />
</div>
<div>
<label class="popup_field_label">Powtórz nowe hasło:</label>
<input type="password" wicket:id="mp-newpassrepeat" />
</div>
<span wicket:id="feedback"></span>
<div class="button-box-bottom">
<input class="btn btn_save" style="margin-right: 9px;"
wicket:id="save" type="button" value="Zapisz"
onmousemove="this.className='btn btn_save btn_hover'"
onmouseout="this.className='btn btn_save'" />
<input
class="btn btn_cancel" wicket:id="cancel"
value="Anuluj" type="button"
onmousemove="this.className='btn btn_cancel btn_hover'"
onmouseout="this.className='btn btn_cancel'" />
</div>
<div class="stats-popup-close-x" wicket:id="close-x"></div>
</form>
</div>
</body>
</html>
【问题讨论】:
标签: wicket