当发生验证错误时,在JSF 2.0中突出显示一个inputText [英] Highlight an inputText in JSF 2.0 when a validation error occurs

查看:121
本文介绍了当发生验证错误时,在JSF 2.0中突出显示一个inputText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有很多inputText的表单,我想要的是突出那些没有填充正确数据的人。



我试图使用'component 。



这是代码:

 < h:column> 
< h:outputText value =#{msg ['Nom']}/> ;: *
< / h:column&
< h:column>
< h:inputText value =#{creerPersonne1.nom}id =nomstyle =#{not nom.valid?'border-color:red;':'border-color:black; '}>
< f:validateRegex
pattern =^ [a-zA-Z] + $>< / f:validateRegex>
< rich:validator />
< / h:inputText>
< / h:column>

这是结果:



img src =https://i.stack.imgur.com/pDybL.pngalt =始终无效>



请注意,该字段也会突出显示


解决方案

您应该使用 component.valid 而不是 nom.valid



component 是当前输入组件的隐式EL对象。并且 component.valid 调用服务器端组件的 isValid()方法。 id 参数不能以这种方式使用。



所以你应该更改你的代码如下:

  style =#{component.valid?'border-color:black;':'border-color:red;'}

(不相关,但应该更好地使用样式类而不是硬编码样式有效的检查适用于 styleClass 属性)。


I have a form with a lot of inputText, what I want is to highlight those who are not being filled with correct data.

I tried to use 'component.valid' but it always return that the field is invalid (i.e. fields are always red).

this is the code :

                        <h:column>
                            <h:outputText value="#{msg['Nom']}" />: *     
                        </h:column>
                        <h:column>
                            <h:inputText value="#{creerPersonne1.nom}" id="nom" style="#{not nom.valid ? 'border-color:red;' : 'border-color:black;'}">
                                <f:validateRegex
                            pattern="^[a-zA-Z]+$"></f:validateRegex>
                            <rich:validator />
                            </h:inputText>
                        </h:column>

this is the result :

note that the field is also highlighted when the page is loaded for the first time.

解决方案

You should use component.valid instead of nom.valid.

component is an implicit EL object for the current input component. And component.valid calls the isValid() method of the server side component. The id argument cannot be used this way.

So you should change your code as follows:

style="#{ component.valid ? 'border-color:black;' : 'border-color:red;'}"

(Not related but you should better use style classes instead of hard coded styles. The valid check works for the styleClass attribute as well).

这篇关于当发生验证错误时,在JSF 2.0中突出显示一个inputText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆