0

I am running a JSF 2 application on JBoss AS 6.

Somehow the Annotations, like @FacesComponent or @FacesValidator, etc are not processed by the container. If I annotate a Bean with @FacesValidator("fooValidator") and try to set the validatorId on some component to "fooValidator" I get:

Caused by: javax.faces.FacesException: Expression Error: Named Object: fooValidator not found.
at com.sun.faces.application.ApplicationImpl.createValidator(ApplicationImpl.java:1530) [:2.0.3-]
...

However, If I add

    <validator>
      <validator-id>fooValidator</validator-id>
      <validator-class>foo.MyClass</validator-class>
    </validator>

To my faces-config.xml everything works as expected. Same goes for components and converters.

Any idea why the annotations are not processed? I am out of ideas...

Thanks in advance...

Mo.
  • 15,033
  • 14
  • 47
  • 57

2 Answers2

3

Got it. It is very similar to this one: Why doesn't JSF 2.0 RI (Mojarra) scan my class' annotations?

My project uses a skinny war, so the lib folder in the war is empty/nonexistent. And to make it worse, the Controller Beans are not located in the war but in a seperate jar. As this jar is not in the war, the jsf annotation processor does not scan it.

I guess, I will restructure the project and likely throw out the skinny war. That should fix it.

Community
  • 1
  • 1
Mo.
  • 15,033
  • 14
  • 47
  • 57
0

So, you were using @Named instead of @ManagedBean on your managed beans? :)

This can happen if the faces-config.xml is not declared conform JSF 2.0 spec. Ensure that the root declaration look like this:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">

    <!-- config here -->

</faces-config>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Good catch with then @Named :) – Mo. Jun 16 '11 at 12:28
  • My faces-config looks kind of like yours but i'll try c/p your header into my faces-config. – Mo. Jun 16 '11 at 12:29
  • Are you using the JBoss built-in JSF deployer? What JSF version is been used according server startup log? This sounds much like as if it's just running in JSF 1.2 modus without annotation scanning support, or as if you've replaced the JBoss-supplied Mojarra 2.0.3 with Mojarra 2.1.0 which exposes a bug in annotation scanning logic (but which should in turn already have shown a big and pretty self-explaining exception/stacktrace in the server startup logs). – BalusC Jun 16 '11 at 12:55
  • Thank you for your help. I got the root problem. See my answer for details. – Mo. Jun 17 '11 at 08:32
  • Interesting. Thanks for posting the answer. – BalusC Jun 17 '11 at 11:49