【发布时间】:2011-03-26 05:05:19
【问题描述】:
我创建了一个简单的检票口 Web 应用程序,用于在我在 TextField 中设置 require 为 true 并在 Textfield 中以空值提交时使用描述此问题。我有一个反馈面板消息(这听起来不错)但我的用例我想从模式窗口获取我的数据并发送回这个表单,但它不能 AjaxRequestTarget 更新 TextField 数据并且不能在其他文本字段上输入任何内容。我无法解决有这个问题。请帮助我。但是当我再次运行网络应用程序并使用模式窗口时,我可以在文本字段上设置我的数据。
这是我的示例代码
用户实体:
public class User implements Serializable {
private String username;
private String password;
public User(String username, String password){
this.username = username;
this.password = password;
}
public User() {
// TODO Auto-generated constructor stub
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
我的页面
public class FormPage extends WebPage{
private User user;
private ModalWindow modal;
private TestForm form;
public FormPage() {
user = new User();
modal = new ModalWindow("modal");
modal.setOutputMarkupId(true);
modal.setInitialHeight(300);
modal.setInitialWidth(300);
add(modal);
form = new TestForm("form");
add(form);
}
private class TestForm extends Form {
private FeedbackPanel feedback;
private TextField<String> username;
private AjaxLink popupButton;
private AjaxButton submitButton;
private TextField<String> password;
public TestForm(String id) {
super(id);
feedback = new FeedbackPanel("feedback");
feedback.setOutputMarkupId(true);
add(feedback);
username = new TextField<String>("username", new PropertyModel<String>(FormPage.this, "user.username"));
username.setOutputMarkupId(true);
username.setRequired(true);
add(username);
password = new TextField<String>("password", new PropertyModel<String>(FormPage.this, "user.password"));
password.setOutputMarkupId(true);
password.setRequired(true);
add(password);
popupButton = new AjaxLink("popupButton") {
@Override
public void onClick(AjaxRequestTarget target) {
UserPopup popup = new UserPopup(modal.getContentId()) {
@Override
public void onSuccess(AjaxRequestTarget target, User user) {
FormPage.this.user = user;
target.addComponent(username);
target.addComponent(password);
modal.close(target);
}
};
modal.setContent(popup);
modal.show(target);
}
};
add(popupButton);
submitButton = new AjaxButton("submitButton", this) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
// TODO Auto-generated method stub
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
target.addComponent(feedback);
}
};
add(submitButton);
}
}
}
我的弹出窗口:
public abstract class UserPopup extends Panel{
private User user;
public UserPopup(String id) {
super(id);
user = new User("name","pass");
add(new AjaxLink("userLink"){
@Override
public void onClick(AjaxRequestTarget target) {
onSuccess(target, user);
}
});
}
public abstract void onSuccess(AjaxRequestTarget target,User user);
}
【问题讨论】:
标签: java web-applications wicket