• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting JS error Object Expected for Richfaces validator tag (client side validation)

 
Brian Wheeler
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Everybody,

I'm trying to validate input forms on my page using using this client side validation method explained here 'Client Side Validation'.

However, I'm getting this JavaScript error 'Object Expected' and no validation error gets rendered. Does anyone know why this is happening?

Heres the code snippet from my project.

Bean


xhtml


Thanks in advance

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian Wheeler
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


Thanks Tim for the FYI on the @NotNull annotation. By the way, this issue was due to using <body>. Replaced it with <h:body> and it fixed it.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Wheeler wrote:
By the way, this issue was due to using <body>. Replaced it with <h:body> and it fixed it.


Yes, depending on the implementation, the h:body (and h:head) tags have gone from not supported to optional to mandatory, as I learned painfully.

The JSF versions of those tags generate critical javascript and CSS anchor points.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic