0

I tried to write in resources/ui/div.xhtml:

<?xml version="1.0" encoding="utf-8"?>
<ui:component xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:composite="http://java.sun.com/jsf/composite"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    >
    <composite:interface>
        <composite:attribute name="binding" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="bodyClass" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="header" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="headerClass" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="id" required="false" type="java.lang.String" />
        <composite:attribute name="ondblclick" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="onkeydown" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="onkeypress" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="onkeyup" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="onmousedown" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="onmousemove" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="onmouseout" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="onmouseover" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="onmouseup" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="rendered" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="style" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="styleClass" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="onclick" required="false"
            type="javax.el.ValueExpression" />
        <composite:attribute name="title" required="false"
            type="javax.el.ValueExpression" />
    </composite:interface>
    <composite:implementation>
        <rich:panel         
            binding="cc.attrs.binding"
            bodyClass="cc.attrs.bodyClass" header="cc.attrs.header"
            headerClass="cc.attrs.headerClass" id="cc.attrs.id"
            ondblclick="cc.attrs.ondblclick" onkeydown="cc.attrs.onkeydown"
            onkeypress="cc.attrs.onkeypress" onkeyup="cc.attrs.onkeyup"
            onmousedown="cc.attrs.onmousedown"
            onmousemove="cc.attrs.onmousemove"
            onmouseout="cc.attrs.onmouseout"
            onmouseover="cc.attrs.onmouseover"
            onmouseup="cc.attrs.onmouseup" rendered="cc.attrs.rendered"
            style="cc.attrs.style" styleClass="cc.attrs.styleClass" 
            onclick="cc.attrs.onclick" 
            title="cc.attrs.title">
            <composite:insertChildren />
        </rich:panel>
    </composite:implementation>
</ui:component>

and calling it from here:

<html
...
xmlns:u="http://java.sun.com/jsf/composite/ui">
...
<u:div styleClass="dualbrand">
    test        
</u:div>
...
</html>

but i'm getting error:

javax.servlet.ServletException: java.lang.String cannot be cast to javax.faces.component.UIComponent javax.faces.webapp.FacesServlet.service(FacesServlet.java:606) org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118) org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65) org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74)

if i changed the implementation into:

<composite:implementation>
    <rich:panel         
        binding="#{cc.attrs.binding}"
        bodyClass="#{cc.attrs.bodyClass}" header="#{cc.attrs.header}"
        headerClass="#{cc.attrs.headerClass}" id="#{cc.attrs.id}"
        ondblclick="#{cc.attrs.ondblclick}" onkeydown="#{cc.attrs.onkeydown}"
        onkeypress="#{cc.attrs.onkeypress}" onkeyup="#{cc.attrs.onkeyup}"
        onmousedown="#{cc.attrs.onmousedown}"
        onmousemove="#{cc.attrs.onmousemove}"
        onmouseout="#{cc.attrs.onmouseout}"
        onmouseover="#{cc.attrs.onmouseover}"
        onmouseup="#{cc.attrs.onmouseup}" rendered="#{cc.attrs.rendered}"
        style="#{cc.attrs.style}" styleClass="#{cc.attrs.styleClass}" 
        onclick="#{cc.attrs.onclick}" 
        title="#{cc.attrs.title}">
        <composite:insertChildren />
    </rich:panel>
</composite:implementation>

i would get:

javax.servlet.ServletException: /WEB-INF/templates/main.xhtml @34,33 styleClass="dualbrand" Cannot convert dualbrand of type class java.lang.String to class javax.el.ValueExpression javax.faces.webapp.FacesServlet.service(FacesServlet.java:606) org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118) org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65) org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74)

what should i do to correctly wrap the panel?

johan.i.zahri
  • 316
  • 6
  • 18

1 Answers1

2

As to your first exception, using attributename="cc.attrs.attributename" is in first place completely wrong. That's not how it works. EL expressions are supposed to be enclosed in #{} as in attributename="#{cc.attrs.attributename}". That's how the specification mandates it.

As to your second exception, that's because you declared the type to be a javax.el.ValueExpression instead of the actual object type behind the expression, which is java.lang.String in case of the styleClass attribute. Fix it accordingly:

<composite:attribute name="styleClass" required="false"
    type="java.lang.String" />

Do the same for the other types. For an overview of the right types, it's helpful to consult the VDL documentation of <rich:panel>, which you're trying to delegate to.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks BalusC, I guess I used the wrong reference http://docs.jboss.org/richfaces/latest_3_3_X/en/tlddoc/rich/panel.html I thought I needed to use the same types as per defined there.. (i couldn't find the latest_4_2_X/en/.. , just saying :D) But it's working, that's what matters (y) – johan.i.zahri Dec 04 '12 at 02:58
  • 1
    @Johan: the 3.3.x documentation tells clearly *"Must evaluate to ..."* in there. – BalusC Dec 04 '12 at 03:01