Search code examples
silverlightjsf-2facelets

How do I embed a Silverlight control into a Facelets page?


I am trying to embed a Silverlight control into a JSF 2.0 page, which is using Facelets, however, I am receiving a very ambiguous error message when the page renders.

Can anyone suggest how I can do this? I have my clientaccesspolicy.xml, and silverlight.js in place.

When I remove the <object> tag, the JSF page displays correctly If I place the <object> tag into a vanilla HTML page, the silverlight control renders correctly in my Tomcat 7.0.25.

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:cayman="http://www.fnet.com/cayman/jsf"
template="/WEB-INF/jsf/template.xhtml">

<ui:define name="title">Home Page</ui:define>

<ui:define name="content">

    <h:form>
        <ui:include src="header.xhtml">
            <ui:param name="loginBean" value="#{UserLoginComponent}" />
        </ui:include>
        <div>
            <p:growl />
        </div>
        <center>
            <p:panel header="Home Page">
                <f:verbatim escape="#{true}">
                    <object data="data:application/x-silverlight-2,"
                        type="application/x-silverlight-2" width="100%" height="100%">
                        <param name="source" value="Dashboard.xap" />
                        <a
                            href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0"
                            style="text-decoration: none"> <img
                                src="http://go.microsoft.com/fwlink/?LinkId=161376"
                                alt="Get Microsoft Silverlight" style="border-style: none" />
                        </a>
                    </object>
                </f:verbatim>
                <iframe id="_sl_historyFrame"
                    style="visibility: hidden; height: 0px; width: 0px; border: 0px"></iframe>
                <h:inputHidden id="userid" value="ADMINISTRATOR" />
                <h:inputHidden id="password" value="admin" />
                <h:inputHidden id="adminserviceuurl"
                    value="http://129.196.218.35:8080/cayman/services" />


            </p:panel>
        </center>
    </h:form>
</ui:define>


Solution

  • Remove <f:verbatim>. It's a leftover from the old ages of JSF 1.x on JSP and deprecated in JSF 2.x.

    As to the ambiguous error message which you forgot to include in your question, make sure that you're properly escaping XML special characters like &. Facelets is a XML based view technology and will be parsed by a XML parser before generating the HTML. The XML parser will choke when it encounters & which is supposed to represent the start of an entity, but there is no ; to denote the end of an entity or when the entity by itself does not represent anything at all.

    So, replace

    href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0"
    

    by

    href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=4.0.50826.0"