JSF Composite Component
Asked Answered
B

2

6

I'm trying to create a composite component for use in my Seam application, and I'm running into problems with the simplest "hello, world" component.

I have placed a file named hello.xhtml in {jboss deploy}/application.ear/application.war/resources/greet :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:composite="http://java.sun.com/jsf/composite">
<head>
<title>My First Composite Component</title>
</head>
<body>

<composite:interface>
    <composite:attribute name="who"/>
</composite:interface>

<composite:implementation>
    <h:outputText value="Hello, #{cc.attrs.who}!"/>
</composite:implementation>

</body>
</html>

Now in home.xhtml, located at the root of my webapp ({jboss deploy}/application.ear/application.war/home.xhtml):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:g="http://java.sun.com/jsf/composite/greet"
            xmlns:s="http://jboss.com/products/seam/taglib"
            template="layout/template.xhtml">
    <ui:define name="content">
    <div id="content">
        <g:hello who="World"/>
        <br/>
    </div>
    </ui:define>
</ui:composition>

But my "hello, world" is not displayed, and I dont get any error messages, even when I turn on debug level logging for com.sun and javax.faces categories.

I've verified that the resources directory is in the proper place, since adding the directory resources/images/test.jpg, then adding this to home.xhtml:

h:graphicImage value="#{resource['images:test.jpg']}"/>

Results in the image being displayed. I just don't know why JSF isn't picking up my xhtml file from the greet directory.

Any ideas?

Basswood answered 15/4, 2010 at 22:12 Comment(0)
P
3

Try putting it into META-INF/resources, not just resources.

Polytrophic answered 15/4, 2010 at 22:41 Comment(6)
Thanks for your suggestion, but I have tried all the following locations with no luck: application.ear/META-INF/resources application.ear/application.war/WEB-INF/resources application.ear/application.war/WEB-INF/classes/resources application.ear/application.war/META-INF/resources (completely non-standard) I'm concerned that I get no debug/info output for this. I have no idea where JSF/Seam is looking for the resource directory.Basswood
Try application.ear/application.war/WEB-INF/classes/META-INF/resources. I don't have experience with the application.ear part, but here's an example of a webapp using a composite component: confluence.highsource.org/x/FoBM. The component xhtml is in war/WEB-INF/classes/META-INF/resources. Also make sure that you're using JSF 2.0, not JSF 1.2. And no, you're not getting any error messages, non-processed namespaces are treated in a "lax" way.Polytrophic
Unfortunately that location doesnt work either. The JSF2 resource location is being seen properly - I updated the original post to show that I can reference resources such as the 'images' library. But the composite component is not seen.Basswood
@purecharger: I'd try deploying the webapp as WAR first of all to check if the problem is in ear step. I can't spot any problems with your code. The namespace seems to be allright. But maybe I'm missing something. Are you sure your "content" fragment is inserted at all?Polytrophic
Lexicore, thanks for your suggestions. I think I figured out the root of my problem: Seam does not work well with JSF 2.0. The faces-config.xml for my app (and all seam examples) specified JSF 1.2. Attempting to use JSF 2.0 causes exceptions on startup.Basswood
Yes, I suspected JSF 1.2 since I know that Richfaces 3.x does not run on JSF 2.0. Good luck further on.Polytrophic
K
3

Here is an example of login composite component where also jsf2 resources are explained: http://jugojava.blogspot.com/2011/09/jsf-composite-component-binding-to.html

Kacykaczer answered 14/9, 2011 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.