简体   繁体   English

Apache Wicket-表单未提交

[英]Apache Wicket - Form not being submitted

Simple, I click on the input that has the type="submit" , and the form isn't submitted. 很简单,我单击具有type="submit"的输入,并且不提交表单。

I've searched solutions to this issue but they say I should check if I have nested forms, which I don't, I'm only using one. 我已经搜索了此问题的解决方案,但他们说我应该检查我是否有嵌套表单,而我没有,只是使用了一个。 They also said it could be some misplaced tag, but I've gone through the whole HTML and the tags are fine. 他们还说这可能是放错了位置的标记,但是我已经遍历整个HTML,并且标记很好。

I have this block in the HTML: 我在HTML中有以下代码块:

<div id="form-options-div" style="margin-top:10px;">
    <input class="btn btn-primary" type="submit" wicket:id="saveClientButton" id="save-client-button" />
    <input class="btn" type="button" id="close-client-button" wicket:id="closeClientButton"/>
</div>

I'm using an AjaxButton in the java code to represent the saveClientButton . 我在Java代码中使用AjaxButton表示saveClientButton

I'm overriding the onSubmit(AjaxRequestTarget, Form<?>) . 我重写onSubmit(AjaxRequestTarget, Form<?>) I would post the whole java code, but I have a logger at the start of the method to see if it's being called: 我会发布整个Java代码,但是在方法的开头有一个记录器,以查看是否被调用:

logger.debug("ON SUBMIT");

So it's not inside the method. 因此它不在方法内部。 An interesting thing is that when I override the Form onSubmit() method, instead of the AjaxButton one, the page actually reloads. 有趣的是,当我重写Form onSubmit()方法而不是AjaxButton方法时,页面实际上会重新加载。 But it's only that, the onSubmit method still isn't called. 但仅此而已,仍未调用onSubmit方法。

Why is this happening? 为什么会这样呢?

EDIT: 编辑:

private Button saveClientBtn;

saveClientBtn = new AjaxButton(WICKET_ID_SAVE_CLIENT_BUTTON) {

        @Override
        public void onError() {
            logger.debug("Error on submit...");
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
           //code....
        }
};

Could the closeClientButton be interfering with the normal behavior? closeClientButton会干扰正常行为? I don't know, because the button type is button , not submit . 我不知道,因为按钮类型是button ,而不是submit

editClientForm = new Form<Client>(WICKET_ID_EDIT_CLIENT_FORM);

add(editClientForm);

editClientForm.add(saveClientBtn);

EDIT 2: 编辑2:

OK, instead of using AjaxButton, I decided to override the Form onSubmit() and onError() . 好的,我决定不使用形式onSubmit()onError() ,而不是使用AjaxButton。 When clicking the button, I see that onError() is called. 单击按钮时,我看到调用了onError() Now I need to find the reason why. 现在,我需要找到原因。

Ok, I put a FeedbackPanel. 好的,我放了一个FeedbackPanel。 It gives me the following message: 它给了我以下信息:

'[Page class = EditClientPage, id = 6, render count = 1]' is not a valid EditClientPage.

Also, the error appears 4 times, as in: 此外,该错误还会出现4次,如下所示:

'[Page class = EditClientPage, id = 6, render count = 1]' is not a valid EditClientPage.

'[Page class = EditClientPage, id = 6, render count = 1]' is not a valid EditClientPage.

'[Page class = EditClientPage, id = 6, render count = 1]' is not a valid EditClientPage.

'[Page class = EditClientPage, id = 6, render count = 1]' is not a valid EditClientPage.

What does this error means? 此错误是什么意思?

Make sure you have a form tag. 确保您有一个表单标签。

eg: 例如:

<html>
  <body>
    <form wicket:id="form">
       <div wicket:id="registration">
          Display the RegistrationInputPanel
       </div>
       <input type=”submit” wicket:id="register" value="Register"/>
    </form>
 </body>
</html>

and the java class: 和java类:

public class RegistrationPage extends Page {
    public RegistrationPage(IModel<Registration> regModel) {
        Form<?> form = new Form("form");
        form.add(new RegistrationInputPanel("registration", regModel);
        form.add(new SubmitButton("register") {
            public void onSubmit() {

            }
        });
        add(form);
    }
}

In my case, it appears I was not setting a "required" value within the form. 就我而言,似乎我没有在表单中设置“必需”值。

This was ascertained by adding an "onError" method to the form object (sure enough, onError was being called, you can tell "what" the error was like 这是通过向表单对象添加“ onError”方法来确定的(确定,onError被调用,您可以告诉“什么”错误

String responseTxt = wicketTester.getLastResponse().getDocument();

And dig through it to look for the error message. 并通过它查找错误消息。

To actually set the value, in my case, was 就我而言,实际设置值是

FormTester formTester = wicketTester.newFormTester("formName");
formTester.setValue("requiredElementName", "value");

Then the onSubmit method started being called within tests, as was expected. 然后按预期在测试中开始调用onSubmit方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM