2

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 !!!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
kavrosis
  • 169
  • 1
  • 4
  • 11
  • If you're using JSF 2.X version, you had better surpass it and let your backing-beans/facelets do the job instead. – Omar Oct 09 '13 at 16:35

2 Answers2

4

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you for your support. I decided to manage navigation rules on faces-config because my partners could change the name of .jsf files, and keeping rules in xml could be easier to maintain instead of change every outcome where I set the rule ("i.e. /result"). Thank you, this answer has helped me out and it's working now !!! – kavrosis Oct 09 '13 at 17:11
  • Regardless, this still doesn't smell a properly designed application. See also among others http://stackoverflow.com/a/15523045/ – BalusC Oct 09 '13 at 17:13
0

Multiple faces-config.xml file can be collated at runtime. So, you can create a faces-config.xml file and store it in the META-INF/faces-config.xml file in some jar and it will get picked up at runtime.

What portions of the original file, you decide to put in it is up to you.

Harsha R
  • 707
  • 6
  • 12
  • Do you mean to create a .jar with another faces-config.xml? I need to set this .jar into my classpath in both development and production environment, I think. Or maybe I get you wrong? – kavrosis Oct 09 '13 at 17:14
  • That is correct. Let us say you are building modular pieces of code .. so you might pull jars of all the modules in to your final application. In such a scenario, you can keep the JSF declarations for that module in a faces-config.xml file which is packaged in that module's jar file. Hope that helps. – Harsha R Oct 09 '13 at 17:19