ExtVal has the ability to perform some cross field validations. An example is the check if two fields have the same content or to verify the relation between two dates (is one date 'before' the other). Besides the standard field validation and the object validation, it is the third way of performing validations. The advantage of the cross field validation is that the update model phase isn't required to have all the values to perform the validation. Due to the ProcessedInformationRecorder concept, the framework can record all values entered in the screen during the model validation phase. And then in a PhaseListener, these values can be used to perform the cross field validation.
This text explains what happens when you use some more exotic expressions.
No managed bean
We all use a managed bean and his properties to store the values of the inputText tags as follows
<h:inputText value="#{bean.source}" label="source" id="source"/>
So we can created something like this
-- faces-config
<managed-bean>
<managed-bean-name>StringVal</managed-bean-name>
<managed-bean-class>java.lang.String</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
-- bean
@Equals(value = "#{StringVal}")
private String password;
-- screen
password <h:inputText value="#{bean.password}" label="password" id="password"/>
Retype <h:inputText value="#{StringVal}" label="retype" id="retype"/>
The cross field validation feature can use the entered value in the screen, but there is also a model aware version. In that case, the EL is evaluated when the system sees that the same expression isn't used on some inputText decoded in the same request. In this situation, the bean scope isn't required to be specified.
-- faces-config
<managed-bean>
<managed-bean-name>startDate</managed-bean-name>
<managed-bean-class>java.util.Date</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
-- bean
@DateIs(valueOf = "#{startDate}", type = DateIsType.after)
private Date beginDate;
-- screen
Begin date <h:inputText value="#{bean.beginDate}" label="Begin date" id="beginDate"/> <br/><h:inputText value="#{methodBean.doMethod()}" label="method" id="method"/> <br/>
@Equals(value = "#{methodBean.doMethod()}")
private String source;
This format isn't working, because the ProcessedInformationRecorder can't understand method constructs in EL. So the cross field validation performs the model variant, but doesn't see the newly typed text on the screen. And without the brackets, it interprets it as a property and looks for the method getDoMethod.
So is this an issue of ExtVal? I don't think it because I never encountered a possible use case that requires an EL method expression in an inputText tag.
Can't we use then the new features of the Unified Expression Language? Yes it is possible, as we already mentioned in the previous section. If the container supports the UEL, ExtVal uses the result of the expression to compare it to the screen entered value.
Have fun with ExtVal
No comments:
Post a Comment