1

I've a little problem with a composite component. This component's implementation looks like:

<composite:implementation>
    <h:outputStylesheet name="foo.css" library="bar"/>

    <div id="#{cc.clientId}">
        <composite:insertChildren/>
    </div>
</composite:implementation>

It is included dynamically into a facelet page which include this component with JSTL core tags. The facelet page is similar to the following one.

<h:panelGroup id="viewport" layout="block">
    <c:if test="#{controller.object != null}">
        <c:forEach items="#{controller.object.elements}" var="element">
            <c:if test="#{element.type == 'type1'}">
                <my:componentTypeOne id="#{element.id}"/>
            </c:if>

            <c:if test="#{element.type == 'type2'}">
                <my:componentTypeTwo id="#{element.id}"/>
            </c:if>
        </c:forEach>
    </c:if>
</h:panelGroup>

So when I only render the viewport of the page the components are rendered but without the stylesheet defined within the composite component my:component. Is there any way to include the stylesheet on the fly without rendering the whole page?

EDIT: extension of the example code..

Checkoff
  • 400
  • 5
  • 14
  • Do you really need to use JSTL? You could change `` for ``, and `` for the `rendered` attribute. JSTL doesn't run in sync with JSF, although I can't tell if that's the problem. – RinaldoDev Sep 11 '12 at 23:54
  • No I don't think so. It should be possible to replace the `` but I need an equivalent for the `` tag because there should be more component types in future – Checkoff Sep 12 '12 at 00:28
  • That's not a problem, just wrap all of the components inside a and set its rendered attribute. – RinaldoDev Sep 12 '12 at 00:32
  • I will try this way tommorrow. Thanks so far for your suggestion! – Checkoff Sep 12 '12 at 00:39
  • @RinaldoPJr: replacing `` by `` would only result in duplicate component ID errors. Not really what the OP wanted. – BalusC Sep 12 '12 at 11:15
  • @BalusC The ID is not static, why would that happen? And, as I said, I don't know if that would solve his problem, it was only a suggestion. :) – RinaldoDev Sep 12 '12 at 11:23
  • @RinaldoPJr: you end up with multiple components with the same ID in the component tree, which are only conditionally rendered. Multiple components with the same ID in one tree is invalid. JSTL runs during view build time, not during view render time and that's why this approach works only with JSTL. You end up with only one component in the tree instead of multiple which is conditionally rendered when using `` and `rendered` instead of `` and ``. Read this answer carefully and try it out yourself: http://stackoverflow.com/questions/3342984 – BalusC Sep 12 '12 at 11:24
  • @BalusC Yes, I understood what you said. I just hadn't seen that he edited the question and added another component with the same ID. It wasn't there. :P Although I don't think I'd have spotted it anyway. – RinaldoDev Sep 12 '12 at 11:41
  • If there exists another way to add composite components of various types dynamically to the page this would be helpful too! – Checkoff Sep 12 '12 at 13:43

0 Answers0