Sunday, June 3, 2012

Multiple Faces-Config.xml file

Multiple faces-config.xml  file in Single Application:

It is possible to have more than one faces-config.xml in any java EE  web application or fusion web application .

By default newly created  Fusion web application has following configuration file -

1-one web.xml  file (Deployment descriptor)
    Part of any j2ee application.
2-one faces-config.xml (does not have any entry in web.xml file)
    Part of the jsf application
3-one adf-config.xml (does not have any entry either in web.xml or faces-config.xml file)
   Part of the adf application

In Any web based application there will only one web.xml file but may have more than one faces-config.xml and adf-config.xml file.

We observed following point when we  have created second faces-config.xml file in our application.

1-When we created one more faces-config.xml file in application then in this case newly created file entry will added into web.xml which have following code :


<context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config1.xml</param-value>
  </context-param>

If you crated on more faces-config.xml  then code will look like following code

<context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config1.xml,/WEB-INF/faces-config2.xml</param-value>
  </context-param>


It will add newly created faces-config,xml file entry comm separated in <param-value> tag.

*Previously when we have single faces-config.xml file there we did not have  entry in the web.xml .

2-If your web based application size is huge or it became very tough to maintains application  navigation rule(because of the confusion )  then in this case it is recommended to split your  faces-config.xml file  in two or more faces-config.xml.Even it also use full if your team size is big.One team  can has one individual faces-config.xml file(what they want they can do freely.but one thing they should have keep in mind before going to create the jsf navigation rule that is uniqueness of rule).

3-
Suppose if  we  have two faces-config.xml .One faces-config.xml contians two pages (page A and page B) with GO jsf Navigation rule.And in second faces-config.xml also contains two page (page A and page C)  with GO(which is same as in first config file) jsf Navigation rule.If you run the page A which has one command button which has GO as Action then in this case it will navigate to page B.


even  second faces-config has same jsf navigation rule but it will navigate to B.
Because it has given  priority to first faces-config.xml file not second faces-config.xml file .

4-Navigation rule searching approach :If the first faces-config.xml does not match the jsf navigation rule then in this case it will search in second faces-config.xml and  so on ... and if it's find navigate rule in the first faces-config (like third point )it will not going to search next faces-config.xml file.

For checking above behavior  i changed the jsf navigation rule GO to GO1 in  first faces-config.xml and  By the way page A command button still has same action (Go).


 So in this case  if you run the first page and click on command button it will first search in faces-config no navigation rule matched then it will search in the second faces-config.xml.In our case it will find the navigation rule in second faces-config.xml  so  it is navigate to Page C.

I will keep add new point if i will find any    :)

Thanks
Prateek


1 comment:

  1. thanks for the post.
    What if I need to add multiple adf-config.xml files

    ReplyDelete