Tim Holloway wrote:ALL form submits are validated. That's a fundamental part of the JSF contract.
RichFaces offers two extensions to the standard form validation process. One is client-based, using generated Javascript and one is server-based, using AJAX.
This element:
runs client-side validation. There is an implied (default) 'event="change"' on the validator tag. I've had occasional grief with change events, so I tend to use the blur event, instead.
This tag is ONLY available on RichFaces 4 and will be silently ignored if you're using RichFaces 3.
The other extension is the "ajaxValidator" tag. It is available for RichFaces 3 and it basically submits the form as though the containing control was the only control on the form, JSF runs the validation, then short-circuits past the update and action phases, so that only validation is done.
Actually, RF3 also supports a beanValidator, but that's another story.
Tim Holloway wrote:JSF validators are done at the GUI level. JSR-303 validations are executable at multiple levels. For example, I use them on ORM record fields to catch bad data before it commits to the database. You can also mix and match, which can be good, for example, if you are connected to an ORM record, but for the particular task in the GUI, you want additional restrictions above and beyond the default ORM validations.
Web clients don't care about "moving outside the form", but if you move outside the control, a JavaScript onblur event is fired to indicate that the control has lost focus. Normally you have to explicitly code any AJAX handling of that event, but if you use appropriate AJAX-friendly tags, they can handle the job for you. The base JSF tags do not do any javascript events without external help.
Tim McGuire wrote:
Brian Wheeler wrote:Hey Everyone,
I got my client side validation to work using this example provided here RichFaces Client Side Validation
Notice, that there is no validation errors until you type and click out of that input form. Not a use case I want.
I'm trying to validate the input forms during an on submit action. Similar to to example provided here. rich:message demo
Using the above example source code, the problem I'm having is when I click the submit button nothing happens. No validation error and no submit action. Am I missing something? Can someone experienced with what I'm trying to do give me some feedback?
Thanks in Advance.
To be clear, you want validation to happen when you click submit button? I can't give feedback unless I see the code you use. Can you post the code that you are using?
Tim Holloway wrote:You can't use the "@NotNull" validation on a property that has been populated from a web form (JSF or otherwise). That's because HTML doesn't support binary constructs such as "null" and so what you'll get instead is an empty string. Which isn't the same thing, and therefore passes validation. So you either need a "required=true" attribute on your View Definition (xhtml) or you need an annotation that forbids a zero-length (empty) string on the backing bean property.
Your javascript error is probably due to syntax errors in your EL expression. It should be "#{data.name}". The braces make all the difference.