I’m trying to implement a custom validation annotation in Seam.
We have a list of objects, lets call it arrayA, and arrayA is different dependent on today’s date.
Next we have an input field stringB, stringB is some value in arrayA going through a transformation function funcC(…).
So basically, we can validate stringB using the following loop:
for(a : arrayA)
{
a.equals( funcC( stringB ) )
return true
}
return false
My problem is, how do I do this in seam considering arrayA is dynamic? The seam/hibernate validation annotation seems to take only constants as input. Does anyone know a workaround for this problem?
Thanks!
You can always utilize Seam’s
Component.getInstance()from within your Validator to fetch the Array from your context. This assumes that you have populated a Seam-based Bean containing this array.For example:
Alternately, if the Array can change depending on the page you are validating from; then you can always pass the value to the validator using
<f:attribute>.For example:
And in your validator, in place of the
Component.getInstance()you can load this array via the attribute:[Note if passing the
String[]doesn’t work then pass in the Bean containing it instead.]