找不到JSF xhtml页面

时间:2019-01-06 00:10:21

标签: spring-boot jsf-2.2

我一直在尝试着各种文章来设置我的第一个JSF应用程序,但是找不到我的第一个xhtml页面。在浏览器中,我不断收到错误消息“此应用程序没有/ error的显式映射,因此您将其视为后备”。

在浏览器中,键入http://localhost:8080/modelSimulation.xhtml来获取此错误,在控制台中,我看到: ...:获取“ /modelSimulation.xhtml”,参数= {} ...:没有GET /modelSimulation.xhtml

的映射

我的spring boot应用程序添加了使用spring boot设置JSF所需的各种功能,但是很明显,我缺少能够查看我的modelSimulation.xhtml页面的东西。我想念什么?谢谢!

我也尝试过http://localhost:8080,但也没有出现对应的映射错误。


src / main / webapp / WEB-INF / modelSimulation.xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:p="http://primefaces.org/ui">
<ui:composition template="layout.xhtml">
    <ui:define name="content">
        <h:form id="mainForm">
            <p:panel header="Details">
                <h:panelGrid columns="1">
                    <p:outputLabel for="symbol" value="Symbol: " />
                    <p:inputText id="symbol" value="#{tradingModelSimulationController.symbol}" />
                    <p:outputLabel for="ranking" value="ranking: " />
                    <p:inputNumber id="ranking" value="#{tradingModelSimulationController.ranking}" />
                    <h:commandButton value="apply" action="#{tradingModelSimulationController.apply}" />
                </h:panelGrid>
            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>
</html>

src / main / webapp / WEB-INF / web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="3.1">
    <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>*.jsf</url-pattern>
    </servlet-mapping>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
</web-app>

我将2个必需的bean添加到了 SpringBootApplication类

@Bean
public ServletRegistrationBean servletRegistrationBean() {
    FacesServlet servlet = new FacesServlet();
    return new ServletRegistrationBean(servlet, "*.jsf");
}
@Bean
public FilterRegistrationBean rewriteFilter() {
    FilterRegistrationBean rwFilter = new FilterRegistrationBean(new RewriteFilter());
    rwFilter.setDispatcherTypes(EnumSet.of(DispatcherType.FORWARD, DispatcherType.REQUEST,
            DispatcherType.ASYNC, DispatcherType.ERROR));
    rwFilter.addUrlPatterns("/*");
    return rwFilter;
}

这是支持豆(我不明白@Join ...)

@Scope(value = "session")
@Component(value = "tradingModelSimulationController")
@ELBeanName(value = "tradingModelSimulationController")
@Join(path = "/modelSimulation", to = "/modelSimulation.jsf")
public class TradingModelSimulationController {

    ModelSimulation modelSimulation = new ModelSimulation();

    String symbol;
    int ranking;

    public void apply() {

        System.out.println("Applied: " + modelSimulation.toString());

        RequestContext.getCurrentInstance()
            .execute("handleMsg('applied!');");
    }

    public ModelSimulation getModelSimulation() {
        return modelSimulation;
    }

    public String getSymbol() {
        return symbol;
    }

    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }

    public int getRanking() {
        return ranking;
    }

    public void setRanking(int ranking) {
        this.ranking = ranking;
    }
}

0 个答案:

没有答案