This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JSF and the fly likes Getting JS error Object Expected for Richfaces validator tag (client side validation) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Getting JS error Object Expected for Richfaces validator tag (client side validation)" Watch "Getting JS error Object Expected for Richfaces validator tag (client side validation)" New topic
Author

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

Brian Wheeler
Ranch Hand

Joined: Dec 06, 2010
Posts: 30
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

Joined: Jun 25, 2001
Posts: 16158
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Brian Wheeler
Ranch Hand

Joined: Dec 06, 2010
Posts: 30
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

Joined: Jun 25, 2001
Posts: 16158
    
  21

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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting JS error Object Expected for Richfaces validator tag (client side validation)