4

El function cannot be found using within validator attribute, which is dependent on dynamic or repeated values?

Function 'el:min' not found
#{el:min(a + b, c)}
<f:validateLongRange maximum="#{el:min(foo.bar, 10)}"/>

Just printing out the value is working where it is not working in the validator.

djmj
  • 5,579
  • 5
  • 54
  • 92

2 Answers2

2

This construct should work just fine. The problem is most likely the scope of the variables which you've there and the timing (i.e. when do you need them? when are they "behind the scenes" changed?).

You need to understand that taghandlers like <f:xxx> run during view build time (like JSTL <c:xxx>). So their attribtues are resolved during view build time and would be filled with bean's default values. Perhaps you're performing some business logic on them while submitting the form and expecting that they would be reflected into the taghandler attribute. But this is not true. They were already evaluated during view build time and won't re-evaluate the values during processing the form submit.

If this is indeed the case, then you've basically the same problem which is already outlined and answered with various possible solutions in this answer: How to set converter properties for each row of a datatable? Apart form homegrowing a Validator for this, you could use OmniFaces <o:validator> for this:

<o:validator validatorId="javax.faces.LongRange" maximum="#{el:min(a + b, c)}" />
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Always the same problem, view and build time. There must be a big performance issue why such components were designed to run during build time. This did not solved the question but was still an issue for me. Your answer definetly saved time or a new question, and led to the solution i found^^ – djmj Feb 02 '13 at 01:29
2

The error message Function 'el:min' not found was so misleading. The problem was never the construct but it was an underlying NullPointerException on the nested property.

Since in one case the value was depending on a different component selection it was updated via ajax and the default value was null. Since the default value was null this misleading exception was thrown.

The value was a nested property, so it was not catched within the el function

Solution: disable the validator on default

<o:validator validatorId="javax.faces.LongRange" maximum="#{el:min(foo.bar, 10)}"
    disabled="#{foo eq null}"/>
djmj
  • 5,579
  • 5
  • 54
  • 92