Question

I have some difficulties deploying my web app on JBoss AS 6.1. My current Project is separated into the main web app (controller/managed beans & web frontend using JSF 2 facelets) and one jar with the composite components + backing beans. But when I try to access the page I got an error that the specified component type could not be instantiated.

Copying the backing bean into the main web app solves the problem, but this isn't what I want. So is there anything to pay attention to?

The backing bean looks like

@FacesComponent(value = "elementBase")
public class ElementBase extends UINamingContainer {
    ...
}

and the composite components interface

<composite:interface componentType="elementBase">
... some attributes
</composite:interface>

The structure of the jar is the following

-- META-INF
    |-- resources
    |    |-- components
    |         |-- elementBase.xhtml
-- com
    |-- example
    |    |-- ElementBase.class

I've also tried to add faces-config.xml within META-INF folder, with the component type, but the component type was still not found.

Was it helpful?

Solution

Through the BalusC's answer to the question JEE6> Packaging JSF facelets (xhtml) and ManagedBeans as JAR

As to the managed beans and other JSF classes like validators, converters, etc, just annotate them with @ManagedBean, @FacesValidator, @FacesConverter, etc and package them in the JAR the usual way. You only need to provide a JSF 2.0 compatible /META-INF/faces-config.xml file in the JAR.

<?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>

This way JSF will be triggered to scan the classes in the JAR for JSF specific annotations. Alternatively you can also just register them in the JAR's faces-config.xml the JSF 1.x way.

and Java EE6 Tutorial: Application Configuration Resource File

You can have more than one application configuration resource file for an application. The JavaServer Faces implementation finds the configuration file or files by looking for the following:

  • A resource named /META-INF/faces-config.xml in any of the JAR files in the web application’s /WEB-INF/lib/ directory and in parent class loaders. If a resource with this name exists, it is loaded as a configuration resource. This method is practical for a packaged library containing some components and renderers. In addition, any file with a name that ends in faces-config.xml is also considered a configuration resource and is loaded as such.

  • A context initialization parameter, javax.faces.application.CONFIG_FILES, in your web deployment descriptor file that specifies one or more (comma-delimited) paths to multiple configuration files for your web application. This method is most often used for enterprise-scale applications that delegate to separate groups the responsibility for maintaining the file for each portion of a big application.

  • A resource named faces-config.xml in the /WEB-INF/ directory of your application. Simple web applications make their configuration files available in this way.

.. I could fix my problem.

Step by step solution

  1. Create backing bean

    @FacesComponent(value = "elementBase")
    public class ElementBase extends UINamingContainer {
        ...
    }
    
  2. and a composite components with the following interface

    <composite:interface componentType="elementBase">
        ... some attributes, value holder, ..
    </composite:interface>
    
  3. provide a faces-config.xml within the deployed jar, to indicate that the jar contains annotated classes. The structure of the deployed jar should look like

    -- META-INF
        |-- resources
        |    |-- components
        |         |-- elementBase.xhtml
        |-- faces-config.xml
    -- com
        |-- example
        |    |-- ElementBase.class
    
  4. deploy the jar within the /WEB-INF/lib folder of the web application.

Research/Related links and topics

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top