com.sun.faces.context.FacesFileNotFoundException: /protected-area/index.xhtml Not Found in ExternalContext as a Resource

10,782

be sure that index.xhtml is under webapp folder. if isn't , add sub folders before index.xhtml in welcome tag. for example:

<welcome-file-list>
<welcome-file>/pages/index.xhtml</welcome-file>
</welcome-file-list>
Share:
10,782
user2796954
Author by

user2796954

Updated on June 04, 2022

Comments

  • user2796954
    user2796954 almost 2 years

    I'm developing a web application with jee7 and I would organize my .xhtml files into different folder. I tried to set web.xml and faces-config.xml files but when I click on a button to enter in a folder I have this issue,

    com.sun.faces.context.FacesFileNotFoundException: /protected-area/index.xhtml Not Found in ExternalContext as a Resource
    

    Problem appear when I want enter in both folder, "protected-area" and "public". I hope I was clear, I don't understand because it doesn't work. Many thanks for your help.

    These are my files.

    index.xhtml

    <h:head>
        <title>jingsen</title>
    </h:head>
    <h:body>
        Select where you want to go:
    
        <h:form>
            <h:commandButton value="protected area" action="protected-area"></h:commandButton>
            <h:commandButton value="public" action="public"></h:commandButton>
            <h:commandButton value="testtest" action="test"></h:commandButton>
        </h:form>
    </h:body>
    

    web.xml

        <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/faces-config.xml</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>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>jingsen-realm</realm-name>
        <form-login-config>
            <form-login-page>/login.xhtml</form-login-page>
            <form-error-page>/error.xhtml</form-error-page>
        </form-login-config>
    </login-config>
    <security-constraint>
        <display-name>Admin Pages</display-name>
        <web-resource-collection>
            <web-resource-name>Protected Area</web-resource-name>
            <description/>
            <url-pattern>/protected-area/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>admin</role-name>
            <role-name>cassa</role-name>
            <role-name>cameriere</role-name>
            <role-name>cucina</role-name>
            <role-name>bar</role-name>
        </auth-constraint>
    </security-constraint>
    <security-role>
        <role-name>admin</role-name>
    </security-role>
    <security-role>
        <role-name>cameriere</role-name>
    </security-role>
    <security-role>
        <role-name>cucina</role-name>
    </security-role>
    <security-role>
        <role-name>bar</role-name>
    </security-role>
    

    faces-config.xml

    <navigation-rule>
        <from-view-id>index.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>protected-area</from-outcome>
            <to-view-id>/protected-area/index.xhtml</to-view-id>
            <redirect/>
        </navigation-case>
        <navigation-case>
            <from-outcome>public</from-outcome>
            <to-view-id>/public/index.xhtml</to-view-id>
            <redirect/>
        </navigation-case>
    
        <navigation-case>
            <from-outcome>test</from-outcome>
            <to-view-id>prova.xhtml</to-view-id>
            <redirect/>
        </navigation-case>
    </navigation-rule>