문제

I'm working on a web solution using myfaces and primefaces. We have several pages in our solution, and some of the get this mystical error myfaces not defined because there is a javascript file that is not included on the page, namely the jsf.js file:

<script type="text/javascript" src="/driwkraft-hig/javax.faces.resource/jsf.js.xhtml?ln=javax.faces&stage=Development">

The error occurs when clicking on certain commandlinks on the page, where the generated javascript has been set to onClick="myfaces.oam.submitForm...

Now, I understand that this is something that the JSF framework adds to the page based on some mystical criteria which I fail to understand. There are pages that appear to be equal with regards to what elements are used, and it succeeds on one and fails on the other.

I have tried to create a test-file where I copied content of one of the failing pages and then removed parts until it would work to figure out what was the source of the problem, but this did not give me anything. My next hunch is that it might be some configuration-error somewhere. But I am completely and utterly blank as to where to start.

I understand I should probable add some code or xml in to this question, but I cannot post the entire solution so I think it is best to do so upon request. Would the web.xml be useful? How about the faces-config.xml?

Any guidance and thoughts are much appreciated!


Edit - adding template

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <ui:insert name="metadata" />
    <h:head>
        ....
        <title>
            <ui:insert name="title">
                ....
            </ui:insert>
        </title>

    </h:head>
    <h:body>
        ....
        <ui:insert name="content">
            ....
        </ui:insert>
        ...
    </h:body>
</html>

Edit - adding template client

<!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:dp="http://java.sun.com/jsf/composite/dapsys">
    <ui:composition template="/templates/default.xhtml">
        <ui:define name="title">TITLE</ui:define>
        <ui:define name="metadata">
            <f:metadata>
                <f:viewParam name="customerId" value="#{CustomerController.customerId}">
                </f:viewParam>
                <f:viewParam name="edit" value="#{CustomerController.edit}">
                </f:viewParam>
                <f:viewParam name="activeTab" value="#{CustomerController.activeTab}">
                </f:viewParam>
            </f:metadata>
        </ui:define>
        <ui:define name="content">
            ...
        </ui:define>
    </ui:composition>
</html>
도움이 되었습니까?

해결책

It's auto-included if there's a <h:head> in the template which automatically renders CSS/JS dependencies from UIViewRoot#getComponentResources() which are added via @ResourceDependency annotation on the JSF component.

Those problem symptoms suggests that there's no <h:head> in the template, but a plain <head>. Therefore JSF is unable to auto-include CSS/JS resource dependencies which in turn causes this JS error.

To fix this problem, just make sure that there's a <h:head> instead of <head> in the template.

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head> <!-- Look here. -->
        <title>Blah</title>
    </h:head>
    <h:body>
        <h1>Blah</h1>
        <p>Blah blah.</p>
    </h:body>
</html>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top