h:inputText 不会在验证时重新渲染标签
当我尝试在验证时调用 h:inputText 标签字段值时,遇到了一个特殊问题。仅当我将静态值传递给标签字段时它才有效。当我向它传递动态值时,当该字段的某些验证失败时,它无法呈现标签。
<h:inputText id="fullNameField" value="#{newUserFormBean.fullName}"
**label="${nlsSupport.label_fullName}"** required="true" size="32" styleClass="required">
<f:validateLength minimum="3" maximum="64"/>
</h:inputText>
如果最小长度验证失败,错误消息将显示为:
此处没有呈现标签:必须至少 3 个字符
但是当我对标签进行硬编码而不是向其传递动态值时,它会显示有效的验证消息,屏幕上打印有标签名称。
<h:inputText id="fullNameField" value="#{newUserFormBean.fullName}"
**label="Full Name"** required="true" size="32" styleClass="required">
<f:validateLength minimum="3" maximum="64"/>
</h:inputText>
现在,如果最小长度验证失败,错误消息将显示为:
全名:必须至少 3 个字符
我还查看了 JSF 文档,它显示标签接受表达式语言表达式。那么为什么传递的动态值验证失败后不渲染呢?
另外,我需要动态传递标签(从资源包),以便为不同语言添加国家语言功能。这就是迫使我将动态值传递给标签属性而不是静态字段的原因。
谢谢。
I am running into a peculiar problem when I am trying to invoke h:inputText label field value on validation. It only works when I pass a static value to label field. The time I pass a dynamic value to it, it fails to render the label when some validation fails for that field.
<h:inputText id="fullNameField" value="#{newUserFormBean.fullName}"
**label="${nlsSupport.label_fullName}"** required="true" size="32" styleClass="required">
<f:validateLength minimum="3" maximum="64"/>
</h:inputText>
If the validation fails for Minimum length, the error message is displayed as:
no label rendered here: must be minimum 3 characters
But when I hard code the label instead of passing a dynamic value to it, it displays a valid validation message, with label name printed on screen.
<h:inputText id="fullNameField" value="#{newUserFormBean.fullName}"
**label="Full Name"** required="true" size="32" styleClass="required">
<f:validateLength minimum="3" maximum="64"/>
</h:inputText>
Now, if the validation fails for Minimum length, the error message is displayed as:
Full Name: must be minimum 3 characters
I have also looked at the JSF documentation, and it reads that the label accepts expression language expressions. So why is the dynamic value passed not rendering after failure validation?
Also, I need to pass the label dynamically (from Resource bundle), so as to add National Language Feature for different languages. This is the reason which forces me to pass a dynamic value to the label attribute instead of a static field.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
得到了解决方案。
在 xhtml 中加载资源包
我使用
,这会导致加载资源包时出现问题Ajax 验证字段。现在我将其修改为实现 Ajax 支持
并且它现在可以工作了。
Got the solution.
I was loading the resource bundle in xhtml using
<f:loadBundle basename="com.myproject.i18n.nls" var="nlsSupport" />
,which would cause a problem loading the resource bundle field on Ajax validation. Now I modified it to be implement Ajax support
<a4j:loadBundle basename="com.myproject.i18n.nls" var="nlsSupport" />
and it works now.