Using validator with a variable attribute in ui:repeat

…衆ロ難τιáo~ 提交于 2019-11-27 16:12:14
BalusC

This is indeed specified/expected behavior. The attributes of taghandlers like <f:validateXxx> are evaluated during view build time. So they can't refer a variable which is only available during view render time like the currently iterated variable of <ui:repeat>. It would indeed work when you use an iterator which runs during view build time like JSTL <c:forEach>. A more elaborate explanation about view build time versus view render time is given here: JSTL in JSF2 Facelets... makes sense?

You have basically the same problem as explained in detail here: How to set converter properties for each row of a datatable? It outlines various solutions in detail. One of the solutions in your particular case would be using OmniFaces <o:validator> which enables render-time evaluation of all attributes, so that you can just replace

<f:validateLongRange minimum="#{question.minimumValue}"
                     maximum="#{question.maximumValue}" />

by

<o:validator validatorId="javax.faces.LongRange" 
             minimum="#{question.minimumValue}"
             maximum="#{question.maximumValue}" />

in order to get it to work as desired.

See also:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!