未被捕获的ReferenceError:当javax.faces.PROJECT_STAGE为Production

时间:2018-07-22 07:20:23

标签: jsf jsf-2.2 mojarra

免责声明

尽管这个问题被问过几次,但没有一个能够为我的问题提供解决方案。


以下是示例代码:

web.xml

<?xml version='1.0' encoding='UTF-8'?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    version="3.1">
    <display-name>MyApp</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
</web-app>

template.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <f:view locale="en_US">
        <ui:insert name="fmetadata" />
        <h:head>
            <ui:include src="/includes/head.xhtml" />
            <title>
                <ui:insert name="title" />
            </title>            
        </h:head>
        <h:body>
            <ui:insert name="content" />
        </h:body>
    </f:view>
</html>

includes / head.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="Pragma" content="no-cache"/>

    <h:outputStylesheet name="style/style.css" />
</ui:composition>

login.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    template="/templates/template.xhtml">
    <ui:define name="fmetadata" />

    <ui:define name="title">
        <h:outputText value="Login" />      
    </ui:define>

    <ui:define name="content">
        <div id="login">
            <h2>
                <h:outputText value="Login" escape="false" />
            </h2>
            <h:messages styleClass="errorMessage" />
            <h:form>
                <label>
                    <h:outputText value="Login"
                        escape="false" />
                </label>
                <br />
                <h:inputText value="#{authenticationController.view.login}"
                    required="true"
                    requiredMessage="Please enter a User Name"
                    styleClass="inputText" />
                <br />
                <label>
                    <h:outputText value="Password"
                        escape="false" />
                </label>
                <br />
                <h:inputSecret value="#{authenticationController.view.password}"
                    required="true"
                    requiredMessage="Please enter a password"
                    styleClass="inputText" />
                <div class="inputButton">
                    <h:commandLink value="Login"
                        action="#{authenticationController.authenticate}" />
                </div>
            </h:form>
        </div>
    </ui:define>
</ui:composition>

AuthenticationController

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.ConfigurableNavigationHandler;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ComponentSystemEvent;

@SessionScoped
@ManagedBean(name = "authenticationController")
public class AuthenticationController implements Serializable {

    private static final long serialVersionUID = -6685652208738725676L;

    @EJB
    private UserServiceRemote userService;

    private LoginView view;

    public AuthenticationController() {

    }

    @PostConstruct
    public void init() {
        view = new LoginView();     
    }

    public String authenticate() {
        String login = view.getLogin();
        String password = view.getPassword();

        boolean isAuthenticated = userService.authenticate(login,password); 

        if(isAuthenticated) {
            return "home.xhtml?faces-redirect=true";
        } else {
            FacesContext.getCurrentInstance().addMessage(null,new FacesMessage("Invalid User Name / Password"));
            return "login.xhtml?faces-redirect=true";
        }           
    }   

    public LoginView getView() {
        return view;
    }

    public void setView(LoginView view) {
        this.view = view;
    }
}

LoginView

public class LoginView implements Serializable {

    private static final long serialVersionUID = -9139791962440768607L;

    private String login;
    private String password;

    public LoginView() {

    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

单击登录h:commandLink时遇到的错误是:

error

jsf.js以HTML呈现,URL:http://localhost:6180/myapp/javax.faces.resource/jsf.js.xhtml?ln=javax.faces可以访问:

jsf.js-Production

当我将context-param javax.faces.PROJECT_STAGE的值更改为Development时,错误消失了。在这种情况下,jsf.js的URL呈现为:http://localhost:6180/myapp/javax.faces.resource/jsf.js.xhtml?ln=javax.faces&stage=Developmentjsf.js-Development

环境:

  • JSF Mojarra-2.2.17
  • Java-1.8.0_181
  • TomEE-7.0.4

1 个答案:

答案 0 :(得分:1)

我不认为您实际上正在使用Mojarra:

  1. TomEE ships with MyFaces
  2. 您发布的(jsf.js的)第一张屏幕截图充满了MyFaces参考

因此,我的赌注与您的(Maven定义的?)Mojarra(如果您在类路径中的任何位置)以及应用服务器随附的Myfaces发生冲突。 You can force Mojarra's version of jsf.js

或者,您可以通过将lib文件夹中的必要jar替换为Mojarra随附的工具,来在TomEE上强制使用Mojarra