JSF 必需=是,不在数据表内工作?
我到处搜索但找不到解决方案。我正在尝试使用 required=yes 来验证值是否存在。我在输入文本中使用它。 问题是它在数据表中不起作用。如果我将文本框放在数据表之外,它就可以工作。我使用的是 JSF 1.7,因此没有 JSF 2.0 中的 validateRequired 标记。
我什至使用了验证器类,但它仍然无法工作。有谁知道为什么数据表内的输入文本中的 required=yes 或 validator='validationClass' 不起作用。
我很感激你的帮助。
谢谢。
I searched everywhere but could not find a solution to this. I am trying to used
required=yes to validate whether a value is present or not. I am using it inside inputtext.
The problem is it does not work inside a datatable. If I put the text box outside the datatable it works. I am using JSF 1.7 so I don't have the validateRequired tag from JSF 2.0.
I even used a validator class but it is still not working. Does anyone know why does required=yes or validator='validationClass' inside a inputtext inside a datatable is not working.
I appreciate the help.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,
required
属性的正确属性值是布尔值true
或false
,而不是字符串值Yes
。它是一个接受布尔表达式的属性。以下是正确的使用示例:
至于它在
中不起作用的问题,当数据模型没有正确保存时可能会发生(数据模型是任何表在其value
属性中检索)。当托管 bean 处于请求作用域并且在其(后)构造期间没有准备数据模型时,就会发生这种情况,这会导致在 JSF 即将收集、转换和处理数据时数据模型为null
或为空。验证提交的值。您需要确保表单提交请求的应用请求值阶段的数据模型与显示带有表的表单的初始请求的渲染响应阶段的数据模型完全相同。一个简单的快速测试是将 bean 放入会话范围内。如果这解决了问题,那么您肯定需要重写数据模型保留逻辑。您还可以使用 Tomahawk 的
或
将数据模型存储在视图范围中(就像 JSF2 的新的视图范围正在执行)。最后,JSF 1.7 并不存在。也许您指的是 JSF 1.2?
First of all, the proper attribute values of the
required
attribute are the boolean valuestrue
orfalse
, not a string value ofYes
. It's an attribute which accepts a boolean expression.The following are proper usage examples:
As to the problem that it doesn't work inside a
<h:dataTable>
, that can happen when the datamodel is not been preserved properly (the datamodel is whatever the table retrieves in itsvalue
attribute). That can in turn happen when the managed bean is request scoped and doesn't prepare the datamodel during its (post)construction which causes that the datamodel isnull
or empty while JSF is about to gather, convert and validate the submitted values.You need to ensure that the datamodel is exactly the same during the apply request values phase of the form submit request as it was during the render response phase of the initial request to display the form with the table. An easy quick test is to put the bean in the session scope. If that fixes the problem, then you definitely need to rewrite the datamodel preserving logic. You could also use Tomahawk's
<t:saveState>
or<t:dataTable preserveDataModel="true">
to store the datamodel in the view scope (like as JSF2's new view scope is doing).Finally, JSF 1.7 doesn't exist. Perhaps you mean JSF 1.2?