• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF submit form says...'Validation error'  RSS feed

 
Leo Rocha
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I know this topic is repeated, but I really can't find the way. In my web application (jsf 2.2 + prime 5), when I click the submit button, JSF says: "validation error". Reading some web posts, I think the problem is related to my equals method contract.

Debugging the equals method, the type received by this method is "Short" (my PK type) and not the object type to compare (professional type in this case). So, equals will return false always!

PK declaration in Entity Class


equals method:



Is this correct?
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JSF Validation Error means that the values of one or more of the controls on the form are invalid. The best way to get details on what item(s) are invalid is to add one of these to the form:


Also, be sure to define explicit (and unique!) "id=" attributes on all the form controls, because the automatically-generated defaults are hard to make sense of.

There are ways to extend the validation framework into things like ORM systems, but those sorts of validations are to permit an ORM model entity to inform JSF that validation should check for values that are null, out of range, or otherwise superficially invalid. Validation cannot check for things that are semantically invalid (such as "color cannot be blue if model=basic"). A fault in the ORM equals() method would never trigger a validation exception.
Incidentally, I have no idea how this statement could even compile:


Since as far as I know, there's no "Objects" class in core Java.

The more usual implementation looks like this:


I broke my rule on always including braces for brevity. That particular comparison, of course, only works if "id" is a class object. If "id" is a primitive, then it's


If you managed to have "this.id" be a class object and "other.id" to be a primitive, something would be really wrong.
 
Leo Rocha
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Tim,

but 'Objects' (java.util.Objects) class is in the Java 7 core. About the validation error, Balusc (a java guru) told that that this error can be generated by the following:
1) equals method broken or invalid;
2) If a custom Converter is involved, then it has returned the wrong object in getAsObject(). Perhaps it's even null.
3) The selected item is missing in the list of available items. This can happen if the list of available items is served by a request scoped bean which is not properly reinitialized on subsequent request, or is incorrectly doing the business job inside a getter method which causes it to return a different list in some way.

Yes, I'm using id tags in all components. I'm using p:messages too. If someone could help...!
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class java.util.Objects is new to Java 7 and evidently wasn't widely advertised in the announcements. This is the first I've heard of it.

I think actually my custom converters have simply thrown exceptions when they attempt to work with improper types.

Item #3 is correct and it's one of the reasons why "Request Scope is (almost) Useless" in JSF.

Rereading what you originally said, there is a possibility that there is a type mismatch coming in from the View. This is probably because the View is text and it's not uncommon for data that's sent out to the View (and thus converted to text) to be converted to the wrong binary object when coming back from the View.

The determinant for that is the View template and the actual backing bean definition and you didn't provide those items, so that's merely the best guess I can make. If you can provide samples of the offending View form control XML and the matching get/set method definitions, I could say more.
 
Leo Rocha
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bingo!

Thank you Tim:


Instead of:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!