Search code examples
validationjsfnextval

model validation of table using extval


My page contains in place editor of values in table. Something like this:

<h:dataTable var="actor" value="#{bean.actors}">
  <h:column>
   <h:input value="#{actor.name}"/>
  <h:column>
</h:dataTable>

I want all actors inside list bean.actors are validated when user clicks on save button. So I put following annotation inside my bean

@BeanValidation(useGroups = Default.class, modelValidation = @ModelValidation(isActive = true))
private List<Actor> actors;

Inside my actor object I have

@NotNull
private String name;

@AssertTrue
public boolean isValid()

So NotNull annotation is validated for all actors, but AssewtTrue does not validated.


Solution

  • After long debug session everything looks clear and straightforward ;-)

    for each binding (e.g #{bean.property1.property2.actors} ) extval analyze 1) base property (property2) 2) bean's class

    Beside other stuff it searched for BeanValidation annotations and if found them, then perform model validation. So to specify that property actors should be valid we need to validate direct parent of it. So correct configuration should looks like:

    @BeanValidation(useGroups = Default.class, modelValidation = @ModelValidation(isActive = true,validationTargets={"#{accountController}"}))
    public class ActorController{
    
       @Valid
       public List<Actor> getActors
    
    
    }
    

    Another strange thing is why @Valid not working if I put on field level. But I do not have time to check this