views:

24

answers:

1

Hi folks,

I implemented my validation logic as follows:

        <h:inputText id="title" value="#{...}" 
            required="true" requiredMessage="...some..text..." 
            validatorMessage="...some..other..text..." >
            <f:validateLength minimum="10" maximum="50"/>
        </h:inputText>

I read a lot about clientside and serverside validation and about their advantages and disadvantages. But I have no idea about what the code above does.

Can somebody please explain that :-)

Cheers

+2  A: 

In client side validation, it's the client (webbrowser) which validates the input with help of a client side language, e.g. JavaScript. In server side validation, it's the server (webserver) which validates the input with help of a server side language, e.g. Java.

You should never do only client side validation, because the result is controllable (and thus also hackable/spoofable) by the enduser. Usually, you'd like to use client side validation because it gives much sooner feedback. The enduser doesn't need to wait for the form submit being completed and doesn't need to face a "flash of content" (page blanks out and then redisplays with new content). You'd like to use server side validation to ensure the integrity of the submitted data. The enduser has in no way control over the outcome of the server side validation.

In case of JSF, the validation is always server side. Since JSF 2.0 it's possible to submit a form (and thus also validate the form) using builtin ajaxical functionality. This combines the best of the two worlds: having instant feedback without flash of content and the robustness/integrity of the server side validation.

BalusC
Thank you for these wise words. Could you please give me a link (or an example) how to include ajax to my code :-) that would be great :-) ...or is it simply the sometimes confusing <f:ajax> tag?
Sven
Yes, `f:ajax` is one way to introduce javascript/AJAX to your code. For pointers of how to start using it, see a relevant question: http://stackoverflow.com/questions/3138488/how-to-use-ajax-with-jsf-2-0
Tuukka Mustonen
@Sven: put `<f:ajax execute="@form" render="@form" />` inside `UICommand` component. Or if you want to validate on blur of each input element, put `<f:ajax event="blur" render="messageid" />` inside each `UIInput` component.
BalusC