在不更改页面参数的情况下设置默认表单值

Set default Form value without changing page parameters

加载日志查看页面时,如何设置 Form<BgwElasticSearchFields> 的默认值?基本上在加载页面之前,我需要为 BicdtTodtFrom 设置默认值。我试过 setDefaultModel 但我不太明白。有什么帮助吗?谢谢!

@Override
protected Form<ElasticSearchFields> getSearchForm() {
    Form<ElasticSearchFields> logSearchForm = new Form<ElasticSearchFields>("searchFields",
            new CompoundPropertyModel<>(searchFields)) {

    logSearchForm.add(new DateTextField("dtTo", new PropertyModel<>(searchFields, "dtTo"), "yyyy-MM-dd").setRequired(true));
    logSearchForm.add(new DateTextField("dtFrom", new PropertyModel<>(searchFields, "dtFrom"), "yyyy-MM-dd").setRequired(true));

    List<String> bics = Arrays.stream(Bic.values())
            .map(Bic::name)
            .collect(Collectors.toList());

    logSearchForm.add(new DropDownChoice<>(
            "bic",
            new PropertyModel<>(searchFields, "bic"),
            bics).setNullValid(true).setRequired(false));

    return logSearchForm;
}

您需要初始化 searchFields 中的默认值。成功提交后,Wicket 将使用浏览器发送的值覆盖它们。

我用的是 setDefaultModel,但没用。它与 setDefaultModelObject.

完美配合