在某些情况下如何禁用检票口的setRequired

时间:2018-12-12 12:42:05

标签: javascript java html user-interface wicket

我对wicket很陌生,刚遇到setRequired。

我有5个文本字段

    final TextField<String> mfnField = new TextField<>("mfn",
                model(criteriaModel, on(RechercheServiceFunctionCriteria.class).getMfn()));
        form.add(mfnField);
        mfnField.setOutputMarkupId(true);
        form.add(new FdsInfoButton("mfn.infoButton", new ResourceModel("mfn.infoButton")));
        form.add(new FormComponentFeedbackPanel("mfnFeedbackPanel", mfnField));

final TextField<String> pbField = new TextField<>("pid",
                model(criteriaModel, on(RechercheServiceFunctionCriteria.class).getPBId()));
        form.add(pbField);
        pbField.setOutputMarkupId(true);
        form.add(new FormComponentFeedbackPanel("pidFeedbackPanel", pbField));

        final TextField<String> gpidField = new TextField<>("gpid",
                model(criteriaModel, on(RechercheServiceFunctionCriteria.class).getGpid()));
        form.add(gpidField);
        gpidField.setOutputMarkupId(true);
        form.add(new FormComponentFeedbackPanel("gpidFeedbackPanel", gpidField));

        final TextField<String> tidField = new TextField<>("tid",
                model(criteriaModel, on(RechercheServiceFunctionCriteria.class).getTransaction_id()));
        form.add(tidField);
        form.add(new FdsInfoButton("tid.infoButton", new ResourceModel("tid.infoButton")));
        form.add(new FormComponentFeedbackPanel("tidFeedbackPanel", tidField));
final TextField<String> ibanField = new TextField<>("iban",
                model(criteriaModel, on(RechercheServiceFunctionCriteria.class).getIban()));
        form.add(ibanField);
        ibanField.setOutputMarkupId(true);
        form.add(new FormComponentFeedbackPanel("ibanFeedbackPanel", ibanField));   

我有一个fromfield和一个tofield:

final DateTimePicker fromInput = new DateTimePicker("from",
                model(criteriaModel, on(RechercheServiceFunctionCriteria.class).getFromDate()),
                DateTimePicker.START_OF_DAY);
        form.add(fromInput);
        form.add(new FormComponentFeedbackPanel("fromFeedbackPanel", fromInput));

        final DateTimePicker toInput = new DateTimePicker("to",
                model(criteriaModel, on(RechercheServiceFunctionCriteria.class).getToDate()),
                DateTimePicker.END_OF_DAY);
        form.add(toInput);
        form.add(new FormComponentFeedbackPanel("toFeedbackPanel", toInput));

在5个文本字段中:

  • 如果在前四个字段中输入了任何内容,那么我也需要输入fromfield和tofield,因此对于此setRequired应该为真
  • 但是如果在tidField中输入了任何内容,则不管其他文本字段为空还是填充,对于frominput和toinput,setRequired都应该为false。

我的问题是如何设置对与错。

或者除了setRequired之外,还有其他我可以使用的东西吗?

1 个答案:

答案 0 :(得分:1)

我找到了解决方案: 我不得不使用isRequired而不是setRequired

final DateTimePicker fromInput = new DateTimePicker("from",
                model(criteriaModel, on(RechercheServiceFunctionCriteria.class).getFromDate()),
                DateTimePicker.START_OF_DAY) {
            /**
             *
             */
            private static final long serialVersionUID = 1L;

            @Override
            public boolean isRequired() {
                return Strings.isBlank(tidField.getConvertedInput());
            }

        };
        form.add(fromInput);
        form.add(new FormComponentFeedbackPanel("fromFeedbackPanel", fromInput));

        final DateTimePicker toInput = new DateTimePicker("to",
                model(criteriaModel, on(RechercheServiceFunctionCriteria.class).getToDate()),
                DateTimePicker.END_OF_DAY) {

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

            @Override
            public boolean isRequired() {
                return Strings.isBlank(tidField.getConvertedInput());
            }
        };
        form.add(toInput);