7

We're trying to use the <f:view contracts="xxx" /> feature from JSF 2.2, with many simultaneous contracts, as "contract1,contract2".

In our contract1, we have a file style1.css, and in our contract2, a style2.css. We include both in our views through <h:outputStylesheet /> tags.

If I only use contracts="contract1" in the view, JSF logs than style2.css is missing, which is logical.

If I use contracts="contract1,contract2", JSF imports both style1.css and style2.css, but with a faulty url (it uses &con=contract1 instead of &con=contract2 to get the resource).

Is it a bug? Is it normal? I can't find any documentation about the use of many simultaneous contracts.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Xavier Portebois
  • 3,354
  • 6
  • 33
  • 53
  • I haven't read the spec on this yet, but it makes logically sense that all contracts ("themes") should consist of exactly the same resource files. Basically, it aren't the resources which change, but the contents of the resources. The answer would then be to rename those two files to have the same name `style.css`. – BalusC Apr 27 '14 at 19:51
  • But if each contract have to define all resources, then what is the point to allow many contracts at the same time? If I set `contracts="c1,c2"`, and if c1 and c2 both define all resources, then one of them will always be muted by the other, am I right? – Xavier Portebois Apr 28 '14 at 08:00
  • Hmm, you're perhaps right. I've just read the spec on this, but the spec itself doesn't seem to say anything about using multiple contracts in ``. – BalusC Apr 29 '14 at 11:29

1 Answers1

4

That's normal behaviour, as I've found in the Apress Pro JSF and HTML 5 text book. An excerpt:

It's possible to map multiple contracts to a single mapping. In that case, it will go through each contract sequentially to look for the required templates. Once a template has been found, it will stop processing other templates.

As to why it's allowed, if all it's going to do is pick the first suitable option, I'm with you on the fact that it may be pointless after all.

Reference:

kolossus
  • 20,559
  • 3
  • 52
  • 104
  • So, that means that JSF looks for the 1st resource, tries to find a matching contract, and then only uses this one for all the following resources? Pointless indeed :-/ – Xavier Portebois May 01 '14 at 14:43
  • 2
    I'd however report it to the JSF spec guys at https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC I believe that the spec is broken here. If a resource is not found (which is easy to check), it should search in the next contract, if any. – BalusC May 01 '14 at 14:59