gpt4 book ai didi

java - 验证 boolean 值 true

转载 作者:太空宇宙 更新时间:2023-11-04 14:10:59 27 4
gpt4 key购买 nike

我在复选框中有一个 boolean 值,我想验证它是否设置为 True。

所以我的实体对象看起来有点像这样

@Validate("required,min=1")
private int Int1;

在我的 tml 文件(我使用 Tapestry 5.3.8)中有一个 Textfield,它允许我为 Int1 设置值

这非常有效。如果我输入其他内容,然后输入一个数字(或一个 int 小 1),它会显示一个错误对话框。

但我不知道如何用 boolean 值来做到这一点。需要对其进行检查,以便用户在错误输入时获得与 Int1 相同的行为。

将其视为同意 TOS 复选框,始终必须选中该复选框才能继续。

问候伊尔贾

最佳答案

如果我没记错的话,复选框可以与 boolean 值一起使用。因此,以下内容应该可以达到您的结果:

@Component(id = "agreeCheckbox")
private Checkbox agreeCheckbox;

@OnEvent(component = "agreeCheckbox", value = EventConstants.VALIDATE)
private void handleAgreeValidate(boolean agree) {
if(!agree) {
throw new ValidationException("Hey there! You have to agree or we can't do business with you.");
}
}

免责声明:我尚未测试此代码。

关于java - 验证 boolean 值 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28324670/

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