1

I have a problem with validation in my JSF application: I have a <h:selectManyListbox> which is backed by a Set in the bean. The Set is annotated with @NotNull and @Size(min=5, max=9999).

My Problem now is: The set will not be validated until the user not select at least one entry in the listbox. If he select one, two or three entries its not possible to save: validation error. But if he never select an entry in the list he can save with empty set.

Any ideas how I can fix that?

Elias Dorneles
  • 22,556
  • 11
  • 85
  • 107
chris
  • 43
  • 6
  • Are you deploying to Tomcat? If so, do you have the correct JARs in the classpath already? Check out this answer: http://stackoverflow.com/a/7548821/149872 – Elias Dorneles Jan 24 '13 at 01:23
  • Yes i'm deploying to tomcat but the JAR's are in the classpath. Validation for simple String/textinput works, but not for the h:selectManyListbox. And there also only if nothing selected! – chris Jan 24 '13 at 15:14
  • Do you have the context-param `javax.faces.VALIDATE_EMPTY_FIELDS` set to false in your `web.xml`? – Elias Dorneles Jan 24 '13 at 15:45
  • no its set to true: ` javax.faces.VALIDATE_EMPTY_FIELDS true ` – chris Jan 24 '13 at 16:33
  • I published the project as zip: https://dl.dropbox.com/u/22315615/easylearncards-server-dev.zip You can find JSF Layer including configuration in -webapp and backing beans in -data project. – chris Jan 24 '13 at 16:39
  • man, I have no idea why you're getting that behavior. I suggest you try making an unit test creating a [Validator](http://docs.oracle.com/javaee/6/api/javax/validation/Validator.html) with [ValidatorFactory](http://docs.oracle.com/javaee/6/api/javax/validation/ValidatorFactory.html) and try to validate an empty set, to see if you get the same behavior. – Elias Dorneles Jan 24 '13 at 17:23
  • Yes! We are two without any idea ;-) Best thing is: Unit test says: [ConstraintViolationImpl{interpolatedMessage='muss zwischen 1 und 2147483647 liegen', propertyPath=categories, rootBeanClass=class de.unibremen.nosuchgroup.easylearncards.server.domain.ServerCard, messageTemplate='{javax.validation.constraints.Size.message}'}] - so it validates the bean correct. My feeling is, that no validator is called for categories if nothing selected. even if VALIDATE_EMPTY_FIELDS is set to true! – chris Jan 24 '13 at 18:07
  • Yeah, that's quite weird... It seems that you are getting exactly the behavior as if VALIDATE_EMPTY_FIELDS is set to false. Try putting on a page the expression `#{initParam['javax.faces.VALIDATE_EMPTY_FIELDS']}` and see what value shows up -- just to check if it is really getting the value we expect. – Elias Dorneles Jan 24 '13 at 18:15
  • `#{initParam['javax.faces.VALIDATE_EMPTY_FIELDS']}
    #{addCardBean.card.categories.isEmpty()}` both show true ...
    – chris Jan 24 '13 at 18:25
  • Yeah, no clue. Well then, the next step would be to backup the project, and start to remove everything not related to the problem. You could to create a new minimal Web project with the bare minimum of classes and dependencies to reproduce the problem. If you pull that off and the problem still persists, get excited: you got to file a bug! :) – Elias Dorneles Jan 24 '13 at 18:42
  • 1
    I think i already found him after debuging into myfaces: https://issues.apache.org/jira/browse/MYFACES-3687 – chris Jan 24 '13 at 19:01
  • Nice work, I think that's it! :) Maybe it's worth to give Mojarra a try, then. – Elias Dorneles Jan 24 '13 at 19:36

0 Answers0