反馈错误后,Wicket 1.4.9 无法使用模式中的 AjaxRequestTarget!

发布于 2024-09-13 00:13:09 字数 3703 浏览 4 评论 0原文

当我在 TextField 中设置 require 为 true 并在 Textfield 中使用 null 值提交时,我创建了一个简单的 wicket Web 应用程序来使用描述此问题。我收到一条反馈面板消息(这听起来不错),但我的用例我想从模式窗口获取数据并将其发送回此表单,但它无法 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);

}

I create a simple wicket web app for using description this problem when i set require is true at TextField and submit with null value in Textfield. i have got a feedback panel message (This sound good) but my use case i want to get my data from modal windows and send back to this form but it can not AjaxRequestTarget update TextField data and cannot input anything on other textfield.i cannot solve with this problem.please help me.but when i run web app again and used modal windows i can setting my data on text field.

This is my sample Code

User Entity :

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;
}
}

My Page

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);

    }

}

}

my popup :

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);

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独难免 2024-09-20 00:13:09

试试这个。 onSuccess 方法,设置用户名和密码字段的模型对象。

@Override
                public void onSuccess(AjaxRequestTarget target, User user) {
                    FormPage.this.user = user;
                    username.setModelObject(user.getUsername());
                    password.setModelObject(user.getPassword());
                    target.addComponent(username);
                    target.addComponent(password);
                    modal.close(target);
                }

我有一个类似的用例并且它有效。您的英语似乎很困难,所以我可能不太明白您的问题。

下面是我针对类似问题的代码。

public class ReleaseDetailPanel extends Panel {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private Form<Release> frmRelease ;

    private TextField<String> txtName ;

    private TextArea<String> txtDescription;

    private TextField<Project> txtProject;

    private AjaxLink<String> lnkLookupProject ;

    private ModalWindow mdProjectLookup ;

    @Inject
    private Dao dao ;


    public ReleaseDetailPanel(String id, Release release) {
        super(id);

        frmRelease = new Form<Release>("frmRelease", new Model<Release>(release)){
            /**
             * 
             */
            private static final long serialVersionUID = 8075962334880413343L;

            protected void onSubmit() {
                Release r = this.getModelObject();
                dao.save(r);
            };
        };

        txtName = new TextField<String>("txtName", new PropertyModel<String>(release, "name"));
        frmRelease.add(txtName);

        txtDescription = new TextArea<String>("txtDescription", new PropertyModel<String>(release, "description"));
        frmRelease.add(txtDescription);

        txtProject = new TextField<Project>("lstProject", new PropertyModel<Project>(release, "project") );
        frmRelease.add(txtProject);
        txtProject.setEnabled(false); 
        txtProject.setOutputMarkupId(true);

        lnkLookupProject = new AjaxLink<String>("lnkLookupProject"){
            /**
             * 
             */
            private static final long serialVersionUID = -1014715631761886636L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                mdProjectLookup.show(target);
            }


        };
        frmRelease.add(lnkLookupProject);
        add(frmRelease);

        mdProjectLookup = new ModalWindow("mdProjectLookup");
        mdProjectLookup.setContent(new ProjectListPanel(mdProjectLookup.getContentId()){

            @Override
            public Component getGridMenu(String id) {

                return new Label(id);
            }

            @Override
            public Component getGridItemMenu(String componentId, final Project project) {
                return new LabeledAjaxFallbackLink(componentId, "Select"){

                    /**
                     * 
                     */
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void doClick(AjaxRequestTarget target) {
                        txtProject.setModelObject(project);
                        target.addComponent(txtProject);
                        mdProjectLookup.close(target);
                    }


                };

            }

        });

        add(mdProjectLookup);
    }

try this. onSuccess method, set the model object of your username and password fields.

@Override
                public void onSuccess(AjaxRequestTarget target, User user) {
                    FormPage.this.user = user;
                    username.setModelObject(user.getUsername());
                    password.setModelObject(user.getPassword());
                    target.addComponent(username);
                    target.addComponent(password);
                    modal.close(target);
                }

I had a similar usecase and it worked. You seem to be struggling with your english and so i may not have understood your question well.

Below is my code on similar problem.

public class ReleaseDetailPanel extends Panel {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private Form<Release> frmRelease ;

    private TextField<String> txtName ;

    private TextArea<String> txtDescription;

    private TextField<Project> txtProject;

    private AjaxLink<String> lnkLookupProject ;

    private ModalWindow mdProjectLookup ;

    @Inject
    private Dao dao ;


    public ReleaseDetailPanel(String id, Release release) {
        super(id);

        frmRelease = new Form<Release>("frmRelease", new Model<Release>(release)){
            /**
             * 
             */
            private static final long serialVersionUID = 8075962334880413343L;

            protected void onSubmit() {
                Release r = this.getModelObject();
                dao.save(r);
            };
        };

        txtName = new TextField<String>("txtName", new PropertyModel<String>(release, "name"));
        frmRelease.add(txtName);

        txtDescription = new TextArea<String>("txtDescription", new PropertyModel<String>(release, "description"));
        frmRelease.add(txtDescription);

        txtProject = new TextField<Project>("lstProject", new PropertyModel<Project>(release, "project") );
        frmRelease.add(txtProject);
        txtProject.setEnabled(false); 
        txtProject.setOutputMarkupId(true);

        lnkLookupProject = new AjaxLink<String>("lnkLookupProject"){
            /**
             * 
             */
            private static final long serialVersionUID = -1014715631761886636L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                mdProjectLookup.show(target);
            }


        };
        frmRelease.add(lnkLookupProject);
        add(frmRelease);

        mdProjectLookup = new ModalWindow("mdProjectLookup");
        mdProjectLookup.setContent(new ProjectListPanel(mdProjectLookup.getContentId()){

            @Override
            public Component getGridMenu(String id) {

                return new Label(id);
            }

            @Override
            public Component getGridItemMenu(String componentId, final Project project) {
                return new LabeledAjaxFallbackLink(componentId, "Select"){

                    /**
                     * 
                     */
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void doClick(AjaxRequestTarget target) {
                        txtProject.setModelObject(project);
                        target.addComponent(txtProject);
                        mdProjectLookup.close(target);
                    }


                };

            }

        });

        add(mdProjectLookup);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文