2017-09-13 1 views
2

Accorrding au documentation of ui:include tagui: include inclut mauvais fichier dans JSF 2.2

cette balise, qui est très similaire à la jsp de JSP: inclure à encapsuler et réutiliser le contenu entre plusieurs pages XHTML. Il y a trois choses cette balise peut inclure: XHTML simple, et les pages XHTML qui ont un tag de composition ou un tag de composant.

Vous indiquez un nom de fichier, via l'attribut src de ui: include pour JSF à include. Ce nom de fichier est relatif au fichier XHTML qui a été rendu à la suite de la dernière requête. Ainsi, par exemple, si JSF a chargé le voir login.xhtml, et que le fichier inclus pageDecorations/header.xhtml, et pageDecorations/header.xhtml inclus companyLogo.xhtml, alors companyLogo.xhtml ne sera pas trouvé s'il est dans le répertoire pageDecorations , car companyLogo.xhtml doit être dans le même répertoire que login.xhtml.


J'ai créé un test simple:
webapp/login.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:h="http://java.sun.com/jsf/html"> 

<h:body> 

    <ui:include src="pageDecorations/header.xhtml" /> 

</h:body> 
</html> 

webapp/pageDecorations/header.xhtml

<ui:include 
     src="logo.xhtml" 

     xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:ui="http://xmlns.jcp.org/jsf/facelets" 
/> 

webapp/pageDecorations/logo.xhtml

<h:outputText 
     value="Logo in /pageDecorations" 
     xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html" 
/> 

webapp/logo.xhtml

<h:outputText value="Logo in /" 
     xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html" 

/> 

Lorsque j'ai couru ce test (login chargé .xhtml p âge) en utilisant JSF 2.2 sur WildFly 10.1, j'ai obtenu Logo in /pageDecorations, alors que selon la documentation, il devrait être: Logo in /

Quel est le problème? Y a-t-il un bug dans la documentation ou la mise en œuvre de Mojarra?
Ou ma compréhension est erronée?

+0

Oui webapp/pageDécorations/logo.xhtml devrait être appel, car vous êtes actuellement dans webapp/pageDecorations/et il trouvera webapp/pageDecorations/logo.xhtml –

Répondre

1

Tout d'abord, vous êtes à l'intérieur webapp/ et l'exécution webapp/login.xhtml à l'intérieur que vous obtenez src="pageDecorations/header.xhtml" et pour exectuing que vous êtes pageDecorations et de header.xhtml vous Tring trouver src = « logo.xhtml » qui obtiendrez-vous dans le même répertoire (pageDecorations) de sorte qu'il imprimera "Logo dans/pageDecorations". Le document semble incorrect dans ce cas.