jsf/icefaces 依赖表单字段和验证的问题

发布于 2024-08-24 22:00:51 字数 779 浏览 1 评论 0原文

我有一个包含 3 个字段的表单(简单示例)。

第一个是复选框。

第二个是

第三个也是

text1 应该只可见当 checkbox1 被选中时。 text2 是必填字段,并且设置了 customvalidator。

因此,我仅使用 #{backingBean.bean.visible} 的第一种方法失败了,因为 text2 是必需的,并且当 text2 字段为空时,会出现一条验证消息(单击复选框后)。 由于验证错误,表单从未完全提交,因此设置了可见属性(从未达到更新模型阶段)。

我还尝试对 selectBooleanCheckBox 使用immediate="true",但这只会导致 required="true" 的验证消息消失,但 mycustomvalidator 的验证仍然触发。

所以我的问题是:如何确保 text1 仅在单击 checkbox1 时可见? 谢谢。

I have a form with 3 fields (simplyfied example).

The first one is a checkbox.

<ice:selectBooleanCheckBox value="#{backingBean.bean.visible}" ID="checkbox1" partialSubmit="true" >

The second one is a

<ice:inputText ID="text1">

The third one is also a

<ice:inputText ID="text2" required="true" validator="mycustomvalidator">

text1 should only be visible when checkbox1 is checked.
text2 is a required field and has customvalidator set.

So my first approach with just using #{backingBean.bean.visible} failed because text2 has is required and a validation message appeared (after the checkbox was clicked) when the text2 field is empty.
Because of ths valdation error the form was never completely submitted such that the visible property is set (update model phase was never reached).

I also tried to use immediate="true" for the selectBooleanCheckBox but that only had the consequence that the validation message for the required="true" disappeared but the validation of mycustomvalidator still triggered.

So my question: how can I make sure text1 is only visible when checkbox1 is clicked?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2024-08-31 22:00:51

为了在这里给出答案,我认为最好的解决方案是使用客户端 Javascript 来隐藏/显示元素。

To give an answer here, I think the best solution is to use client side Javascript for hiding/showing the elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文