Search code examples
jsffaces-config

JSF faces-config.xml with external navigation-rules *.xml file


I have my faces-config.xml with a lot of navigation-rules inside, so I was wondering if there's a chance to write an external xml with navigation rules only, and import that nav-rules.xml into faces-config.xml.

I would like to keep well structured my faces-config, because a lot of navigation rules made it too long.

Thank you in advance !!!


Solution

  • Yes, it's possible to split webapp's own /WEB-INF/faces-config.xml file's contents over multiple files. You only need to alter the web.xml to specify the javax.faces.CONFIG_FILES context parameter with comma separated webcontent-relative paths to all external files:

    <context-param>
        <param-name>javax.faces.application.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/navigation-config.xml</param-value>
    </context-param>
    

    Alternatively, if you're already on JSF 2.x, then you could also get rid of all navigation cases altogether by utilizing the JSF 2.0 new implicit navigation feature. I.e. just make the from-outcome exactly the same as to-view-id as in return "/result.xhtml"; or return "/result"; instead of return "success";. This way the whole navigation case becomes superflous and can be removed from faces-config.xml.