When facing the problem of validating a property in a JSF2 application there are two main approaches.
Defining the validation on the ManagedBean using an Annotation
@ManagedBean
public class MyBean {
@Size(max=8)
private String s;
// Getters setters and other stuff.
}
or declaring it on the jsf page:
<h:inputText value="#{myBean.s}">
<f:validateLength maximum="8"/>
</h:inputText>
It happens that I can't decide for none of them. The first one is nice because it removes some code from the jsf pages (which is always good since those pages are not eye friendly by definition) but makes harder to see 'at a glance' what's going on with the page when checking the jsf file.
Which one do you think is clearer? Nicer? Better?