首页 > 解决方案 > jsf中不能调用Bean?

问题描述

我正在使用 jave 的 JSF 框架。我有一个问题。当我使用 url-pattern 是 /faces/* 时,我可以调用 bean。但是当我将 url-pattern 更改为 *.xhtml 时,我不能。我必须如何解决这个问题。

我的豆子

@ManagedBean
@Named(value = "employerBean")
@SessionScoped
public class EmployerBean implements Serializable {

//    private final static EmployerService epmservice = new EmployerService();

    /**
     * Creates a new instance of EmployerBean
     */
    public EmployerBean() {
    }


    public List<String> getCompanies() {
        List<String> messages = Arrays.asList("Hello", "World!", "How", "Are", "You");
        return messages;
    }
}

web.xml

<web-app version="3.1" 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">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</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>/faces/*</url-pattern>-->
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

标签: javajsf

解决方案


推荐阅读