• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSF submit form says...'Validation error'

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bingo!

Thank you Tim:


Instead of:
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic