gpt4 book ai didi

java - 如何在 DropDownChoice Wicket 中保留 "Choose One"选项?

转载 作者:太空狗 更新时间:2023-10-29 22:37:12 25 4
gpt4 key购买 nike

当我第一次加载页面时,下拉选项中的默认选项是“选择一个”。即使我选择了一个选项,有没有办法将其保留在下拉列表中?
(以防我以后不想放任何东西)

最佳答案

您需要使用 DropDownChoice.setNullValid()方法。来自 javadoc:

Determines whether or not the null value should be included in the list of choices when the field's model value is nonnull, and whether or not the null_valid string property (e.g. "Choose One") should be displayed until a nonnull value is selected. If set to false, then "Choose One" will be displayed when the value is null. After a value is selected, and that change is propagated to the underlying model, the user will no longer see the "Choose One" option, and there will be no way to reselect null as the value. If set to true, the null string property (the empty string, by default) will always be displayed as an option, whether or not a nonnull value has ever been selected. Note that this setting has no effect on validation; in order to guarantee that a value will be specified on form validation, FormComponent.setRequired(boolean). This is because even if setNullValid() is called with false, the user can fail to provide a value simply by never activating (i.e. clicking on) the component.

如果您想保留 NullValid = true 的“Choose One”文本,您可以在 Application.properties 文件中使用类似于以下行的行:

nullValid=[Choose one]

关于java - 如何在 DropDownChoice Wicket 中保留 "Choose One"选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6984466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com