3

I try to recover the constants in my xhtml jsf in using Omnifaces library, but when I run my project I get:

Cannot find type 'fr.epsi.utils.ConstantsPages' in classpath.

Here is my xhtml page :

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:o="http://omnifaces.org/ui">
<o:importConstants type="fr.epsi.utils.ConstantsPages" />
<h:head>
    <title>Acceuil</title>
    <h:outputStylesheet name="css/style.css"/>
</h:head>
<h:body>
    <h:panelGrid columns="3" cellpadding="10">
        <h:link value="Home" outcome="#{ConstantsPages.LOGIN_PAGE}" />
    </h:panelGrid>
<h:body>
</html>

And my ConstantsPages class :

package fr.epsi.utils;

public class ConstantsPages {    
    /* GENERAL */
    public static final String LOGIN_PAGE = "/General/login";
    public static final String LOGIN_CLIENT_PAGE = "/General/loginClient";
    public static final String LOGIN_TECHNICIEN_PAGE = "/General/loginTechnicien";
    public static final String ACCUEIL_PAGE = "/General/accueil";
}

And the stack trace :

java.lang.IllegalArgumentException: Cannot find type 'fr.epsi.utils.ConstantsPages' in classpath.
at org.omnifaces.taghandler.ImportConstants.toClass(ImportConstants.java:173)
at org.omnifaces.taghandler.ImportConstants.collectConstants(ImportConstants.java:134)
at org.omnifaces.taghandler.ImportConstants.apply(ImportConstants.java:117)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:774)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: fr.epsi.utils.ConstantsPages
at com.sun.enterprise.loader.ASURLClassLoader.findClassData(ASURLClassLoader.java:808)
at com.sun.enterprise.loader.ASURLClassLoader.findClass(ASURLClassLoader.java:696)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at org.omnifaces.taghandler.ImportConstants.toClass(ImportConstants.java:156)
... 36 more

Please help me!

Tiny
  • 27,221
  • 105
  • 339
  • 599
lopez.mikhael
  • 9,943
  • 19
  • 67
  • 110

1 Answers1

2

You need to make sure that the class file is properly compiled and placed in webapp's runtime classpath. E.g. as /WEB-INF/classes/fr/epsi/utils/ConstantsPages.class inside the WAR.

This exception says that it is not. There's really no other cause. If you're using an IDE, make sure that the class file is inside Java source folder of the web project and that you've cleaned, rebuilt and redeployed the project and restarted the server.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I have mine in a jar, would that be okay? – Karl Kildén Dec 31 '13 at 17:37
  • I am working with maven. It is in the `/WEB-INF/classes/de.....`. They are also inside the Java source folder of the web project. Is there any difference? – alexander May 07 '15 at 17:17
  • @Alexander: and OmniFaces is in WAR's `/WEB-INF/lib`? I could imagine that it may fail when OmniFaces is incorrectly placed in EAR's `/lib`. – BalusC May 07 '15 at 18:54
  • omnifaces-2.0.jar is in the lib folder of the war, yes (`/WEB-INF/lib/omnifaces-2.0.jar`). Other components such as `{now}` are working. – alexander May 07 '15 at 19:05
  • @Alexander: which appserver? Are you inside a test managed bean able to perform `Class#forName()` on that class with `Thread.currentThread().getContextClassLoader()`? – BalusC May 07 '15 at 19:08
  • WildFly 8.2. As alternate approach: Can I follow this one: http://stackoverflow.com/questions/4706726/jsf-2-using-enums-in-the-rendered-attribute ? – alexander May 07 '15 at 20:14
  • @BalusC Yes - it is working perfectly (Sorry, missed your edit I guess). – alexander May 07 '15 at 20:37
  • @Alexander: OK this is weird. Is it a default WildFly or with a modified `standalone.xml`? I've never seen this before on our own WildFly setups. – BalusC May 07 '15 at 20:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/77247/discussion-between-alexander-and-balusc). – alexander May 07 '15 at 20:48
  • @BalusC Did you found any solution here? – alexander May 11 '15 at 13:00