Incluindo páginas via ui:include em JSF

3 respostas
W

Pessoal, estou com um problema na hora de incluir uma página em JSF em uma outra.
Estou usando JSF 2.0 e a tecnologia de display padrão (Facelets), o problema é que a página que eu quero que seja incluída em outra perde a formatação, pois ela deveria se alinhar corretamente dentro da tag , mas quando ela é incluída isso não acontece muito bem.

Os códigos das 2 páginas são estes:

<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>
            <h:outputText value="ProjectTrack - Approve a Project"/>
        </title>
        <link rel="stylesheet" type="text/css" href="stylesheet.css"/>
    </h:head>
    <h:body styleClass="page-background">
        <ui:include src="header.xhtml"/>
        <h:form>
            <h:panelGrid columns="2" cellpadding="5" styleClass="project-background"
                         footerClass="project-background" headerClass="page-header"
                         rowClasses="project-row">
                <f:facet name="header">
                    <h:panelGrid columns="1" width="100%" cellpadding="3"
                                 styleClass="project-background"
                                 headerClass="page-header">
                        <f:facet name="header">
                            <h:outputText value="Approve a Project"/>
                        </f:facet>
                        <h:outputText value="Application messages." styleClass="errors"/>
                    </h:panelGrid>
                </f:facet>
                //Aqui incluo a outra página, e ela não é formatada da maneira correta                
                <ui:include src="project_info.xhtml"/>
                
                <f:facet name="footer">
                    <h:panelGroup>
                        <h:panelGrid columns="1" cellpadding="5"
                                     styleClass="table-background"
                                     rowClasses="table-odd-row, table-even-row">
                            <h:outputLabel for="commentsInput">
                                <h:outputText value="Your Comments:"/>
                            </h:outputLabel>
                            <h:inputTextarea id="commentsInput" rows="10" cols="80"/>
                        </h:panelGrid>
                        <h:panelGrid columns="2" rowClasses="table-odd-row">
                            <h:commandButton value="Approve" action="approve"/>
                            <h:commandButton value="Cancel" action="cancel"
                                             immediate="true"/>
                        </h:panelGrid>
                    </h:panelGroup>
                </f:facet>
            </h:panelGrid>
        </h:form>
    </h:body>
</html>
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:body>
        <h:outputText value="Name:"/>
        <h:outputText value="Inventory Manager v2.0" styleClass="project-data"/>
        <h:outputText value="Type:"/>
        <h:outputText value="Internal Web Application" styleClass="project-data"/>
        <h:outputText value="Initiated by:"/>
        <h:outputText value="Rip Van Wrinkle" styleClass="project-data"/>
        <h:outputText value="Requirements contact:"/>
        <h:outputText value="Joan TooBusy" styleClass="project-data"/>
        <h:outputText value="Requirements contact e-mail:"/>
        <h:outputText value="[email removido]" styleClass="project-data"/>
        <h:outputText value="Initial comments:"/>
        <h:outputText value="The first version is horrible and completel
                      y unusable. It's time to rewrite it."
                      styleClass="project-data"/>
        <h:outputLabel for="artifactSelect">
            <h:outputText value="Completed artifacts:"/>
        </h:outputLabel>
        <h:selectManyCheckbox id="artifactSelect" layout="pageDirection"
                              styleClass="project-input">
            <f:selectItem itemValue="0" itemLabel="Proposal Document"/>
            <f:selectItem itemValue="1" itemLabel="Requirements Document"/>
            <f:selectItem itemValue="2" itemLabel="Architecture Specification"/>
            <f:selectItem itemValue="3" itemLabel="Test Plan"/>
            <f:selectItem itemValue="4" itemLabel="Deployment Guidelines"/>
            <f:selectItem itemValue="5" itemLabel="Maintenance Documentation"/>
            <f:selectItem itemValue="6" itemLabel="User Documentation"/>
        </h:selectManyCheckbox>
    </h:body>
</html>

Se eu fizesse via JSP's essa inclusão funcionaria corretamente, pois não precisaria das tags como ou , e a inclusão seria feita via

Alguém sabe como resolver isso? Agradeço desde já.

3 Respostas

A

oi,

para fazer o que você precisa eu coloquei tudo dentro de um DIV, não sei se é a melhor alterantiva mas funcionou, algo assim

&lt;div id="topo"&gt; &lt;ui:include src="topo.jsp"&gt; &lt;/div&gt; &lt;div id="conteudo"&gt; &lt;ui:include src="conteudo.jsp"&gt; &lt;/div&gt;

e por ai vai, alem disso todas as paginas tem que pertencer a um <f:view>

W

Ainda não consegui alinhar no panelGrid esses componentes incluídos, é como se fossem tratados toda a página em um mesmo

em uma table, o que não era pra acontecer.
A página gerada pelo NetBeans não possui a tag <f:view>, achei que não fosse necessário ela.
R

Crie seu project_info.xhtml da seguinte forma:

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

  <!-- your page -->

</ui:composition>
Criado 20 de março de 2010
Ultima resposta 3 de mai. de 2010
Respostas 3
Participantes 3