Bean validation VS JSF validation

Posted by henloke on Stack Overflow See other posts from Stack Overflow or by henloke
Published on 2010-03-19T11:24:13Z Indexed on 2010/03/19 11:31 UTC
Read the original article Hit count: 179

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about j2ee

Related posts about jsf