Wednesday, April 2, 2008

sev-en preview - a short example

as mentioned within the previous post:
sev-en has zero required configuration and offers some powerful features such as cross-component validation and extensibility (e.g.: easy custom validation).

the following part illustrates some of these features.
the example uses facelets and trinidad. however, these technologies are not required!
(sev-en supports property and field access.)

sample scenario - the target:
=> first name != last name
=> birthday is (of course) before the final exam
=> old nick name != new nick name (with a direct reference to the old value)
=> old password != new password (without a direct reference to the old value)
=> new password == re-entered new password
=> each input-field is required (within the domain model: re-use jpa annotations)
=> restrict the max. length of string values (also re-use information of jpa annotations)

now hold on a moment and think about the effort of doing such validations.

without sev-en:
the simple parts of the scenario above can be solved with the according tags. if you are using jpa annotations, you already have some of these information within your mapping. -> redundancy (annotations + tags).
ok - let's have a look at the more complex validation scenarios. i'm referring to the date and password validations. there might be e.g. some password components available. does your component lib offer such a feature? ok - nice, if you are one of the lucky one's. however, what's about the next complex requirement within your project? - there might be no adequate component within the available component libs.
or are you using one of the unaesthetic workarounds?

sev-en provides a lot of powerful solutions.

using sev-en:

the registration page:

the page to change the nick name:

the page to change the password:

... oh - it's really straightforward!

the page bean class (backing bean):

... oh - some new annotations - however, it's also really straightforward!
we aren't using jpa annotations here (it's the view layer!)

the domain model class:

... really nice - some simple jpa annotations which are also used for validation.
you aren't using jpa? no problem - you can use conventional validation and/or you can use the sev-en standard or custom annotations ;)

the following screenshot shows an example of a failed validation:

sev-en isn't about specific annotations. sev-en is mainly the core itself. out-of-the-box sev-en will provide some separated modules with nice annotations.

one of the next posts will be about the really easy way to implement custom sev-en annotations.