How to reference JSF managed beans which are provided in a JAR file?
2012-11-20 14:05
561 查看
How
to reference JSF managed beans which are provided in a JAR file?
up vote3down votefavorite 2 | I have a WAR file with the following structure: The JSF managed bean BusinessObjectTypeListControlleris located in commons-web-1.0.jarin /WEB-INF/liband referenced in BusinessObjectTypeListView.xhtml. When I run my web application and I call that view, I get the following error: javax.servlet.ServletException: /view/common/businessObjectTypeListView.xhtml @34,94 listener="#{businessObjectTypeListController.selectData}": Target Unreachable, identifier 'businessObjectTypeListController' resolved to null Why isn't the controller class found? It should be in the classpath, is it? java java-ee jsf-2 jar managed-bean
| ||||
|
2 Answers
activeoldestvotesup vote7down voteaccepted | You need to have a JSF 2.0 compliant /META-INF/faces-config.xmlfile in the commons-web-1.0.jarfile in order to get JSF to scan the JAR file for classes with JSF annotations like @ManagedBeanand auto-register them. <?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"> </faces-config> JSF does namely not scan every class of every single JAR file in the classpath, that would have been too expensive. Only JARs with the above /META-INF/faces-config.xmlfile will be scanned. You should also ensure that you do not have the metadata-complete="true"attribute in the <faces-config>declaration of webapp's own /WEB-INF/faces-config.xmlfile, otherwise JSF will assume that this faces config is complete and therefore won't auto-scan JAR files for annotations. If none of those conditions are (or can be) met, then you need to manually register the bean as <managed-bean>in webapp's own /WEB-INF/faces-config.xmlinstead of relying on annotations. See also chapter 11.4.2 of JSF 2.0 specification (emphasis mine). ... |
share|improve this answer | edited Oct 28 '11 at 11:13 | answered Oct 5 '11 at 15:37 BalusC 333k43494767 |
Now it works! Thank you very much!! – Francesco Oct 5 '11 at 16:01 | |
You're welcome. – BalusC Oct 5 '11 at 16:02 |
相关文章推荐
- How to invoke the method of managed bean and render view in JSF when we are outside the lifecycle of JSF
- How to determine which checkboxes are checked in postback (sqlstr="delete spprod where id in ("&request("sid")&")")
- How to avoid Excel from prompting "The file you are trying to open, , is in a different format than specified by the file extension"? (转)
- How to clear the views which are held in the ListView's RecycleBin?
- How to load the specified mscordacwks.dll for managed debugging when multiple .NET runtime are loaded in one process
- How to pass SOAP headers into python SUDS that are not defined in WSDL file
- How to include JavaScript file in JSF
- How to Recover Datafile Which Deleted Accidentally in Linux
- How to get a path to a resource in a Java JAR file
- how-to-load-resource-from-jar-file-packaged-in-a-war-file
- How to Read, Write XLSX File in Java - Apach POI Example---reference
- how to delete .tmp file in server which is created during file upload
- EPLAN API 入门系列- 提高篇(How to get all connections which are not in location box)
- Openvms-C-Sourcecode- How to Find which Processes are using a specific pagefile or swapfile
- How to create and execute JAR file in Java – Command line Eclipse Netbeans
- How to install an APK file in the Android emulator?
- How to share text to Message in the app you are building(iOS platform)
- How can I force Python's file.write() to use the same newline format in Windows as in Linux (“\r\n”
- How to Run a .Jar Java File
- How to generate file name according to datetime in bat command