Ajuda com JSF

8 respostas
luiscesarinfo

Pessoal, estou estudando JSF pelo livro Core JSF. Estou tentando implementar um exemplo sobre TILES do livro e está dando um erro que é o seguinte :

se alguém puder me ajudar...

[]'s Luis César

exception 

org.apache.jasper.JasperException: An exception occurred processing JSP page /ch08/book-viewer-tiles/book.jsp at line 24

21: 			<body>
22: 				<f:subview id="book">
23: 					<h:form>
24: 						<tiles:insert definition="book" flush="false"/>
25: 					</h:form>
26: 				</f:subview>
27: 			</body>
root cause 

javax.servlet.ServletException: javax.servlet.jsp.JspException: Can't get definitions factory from context.
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
	org.apache.jsp.ch08.book_002dviewer_002dtiles.book_jsp._jspService(book_jsp.java:81)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:415)
	com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:475)
	com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:143)
	com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
	com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
	com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)

8 Respostas

L

cara posta seu codigo pra gente dar uma olhada

luiscesarinfo

o arquivo book.jsp segue abaixo :

<?xml version="1.0" ?>
<jsp:root version="2.0"
		xmlns:jsp="http://java.sun.com/JSP/Page"
		xmlns:f="http://java.sun.com/jsf/core"
		xmlns:h="http://java.sun.com/jsf/html"
		xmlns:c="http://java.sun.com/jsp/jstl/core"
		xmlns:tiles="http://jakarta.apache.org/tiles">
	<jsp:directive.page contentType="text/html"/>
	<jsp:output omit-xml-declaration="no"
			doctype-root-element="html"
			doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
			doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
	<f:view>
		<html xmlns="http://www.w3.org/1999/xhtml">
			<f:loadBundle basename="com.corejsf.ch08.ex02.messages" var="msgs"/>
			<head>
				<link href="css/styles.css" rel="stylesheet" type="text/css"/>
				<title><h:outputText value="#{msgs.bookWindowTitle}"/></title>
			</head>
			
			<body>
				<f:subview id="book">
					<h:form>
						<tiles:insert definition="book" flush="false"/>
					</h:form>
				</f:subview>
			</body>
		</html>
	</f:view>
</jsp:root>
luiscesarinfo

o arquivo headerMenuContentLayout.jsp segue abaixo:

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://jakarta.apache.org/tiles" prefix="tiles" %>

<tiles:importAttribute scope="request"/>

<h:panelGrid columns="2" styleClass="#{gridClass}" headerClass="#{headerClass}" 
	columnClasses="#{menuColumnClass}, #{contentColumnClass}">
	<f:facet name="header">
		<f:subview id="header">
			<tiles:insert attribute="header" flush="false"/>
		</f:subview>
	</f:facet>
	
	<f:subview id="menu">
		<tiles:insert attribute="menu" flush="false"/>
	</f:subview>
	
	<f:subview id="content">
		<tiles:insert attribute="content" flush="false"/>
	</f:subview>
</h:panelGrid>
luiscesarinfo

Alguém tem alguma idéia ?

M

Fazer essa integracao entre jSF e Tiles eh um porre. Mas segue um exemplo.

Lembro-me que obrigatoriamente no tiles-defs.xml tem que ter o name da definition terminada com .tiles, senao o tomahawk nao funciona. Esse código deve ter +- 1 ano e usa o tomahawk para fazer a ponte entre jsf e tiles. Talvez com o tiles 2 essa integracao seja mais facil. Acho que eh mais negocio dar uma olhada no facelets ([url]http://facelets.dev.java.net/[/url].

tiles-defs.xml:
<definition extends="template" name="/loja/paginas/produto/detalheProduto.tiles">
  <put name="corpo" value="/loja/paginas/produto/detalheProduto.jsp"/>
  <put name="menuLateral" value="/loja/paginas/template/menuLateralCategorias.jsp"/>
 </definition>
faces-config.xml:
<navigation-rule>
  <navigation-case>
   <from-outcome>mostrarDetalheProduto</from-outcome>
   <to-view-id>/loja/paginas/produto/detalheProduto.jsf</to-view-id>
   <redirect/>
  </navigation-case>
 </navigation-rule>

 <application>
  <view-handler>org.apache.myfaces.tomahawk.application.jsp.JspTilesViewHandlerImpl</view-handler>
 </application>
template.jsp
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>


<html xmlns:fo="http://www.w3.org/1999/XSL/Format">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:getAsString name="titulo"/></title> 
<link href="styles.css" rel="stylesheet" type="text/css">
<link href="home.css" rel="stylesheet" type="text/css">
<link href="topnav.css" rel="stylesheet" type="text/css">
</head>
<f:view>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0" TOPMARGIN="0" RIGHTMARGIN="0" BOTTOMMARGIN="0" LEFTMARGIN="0">
	<TABLE WIDTH="780" HEIGHT="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0">
		<TR>
			<div id="cabecalho">
			<f:subview id="cabecalho">
				<tiles:insert name="cabecalho" flush="false"/>
			</f:subview>
			</div>
		</TR>
		<TR>
			<div id="menuCabecalho">
			<f:subview id="menuCabecalho">
					<tiles:insert name="menuCabecalho" flush="false"/>
			</f:subview>
			</div>
		</TR>
		<TR>
			<TD colspan="3" height="6" bgcolor="#E6E7E9"></TD>
		</TR>
		<TR>
			<TD colspan="3" height="6"></TD>
		</TR>
		<TR>
			<f:subview id="menuLateral">
					<tiles:insert name="menuLateral" flush="false"/>
			</f:subview>
			<f:subview id="corpo">
					<tiles:insert name="corpo" flush="false"/>
			</f:subview>
			
					
			<TD width="108" height="26" valign="top">
			</TD>
		</TR>
		<TR>
			<TD height="26"></TD>
			<TD></TD>
			<TD height="26"></TD>
		</TR>
		<TR>
			<TD colspan="3" width="780" height="30">

			</TD>
		</TR>
		<TR>
			<tiles:insert name="rodape" flush="false"/>
		</TR>
	</TABLE>
</BODY>
</f:view>
</html>

Marco.

luiscesarinfo

Obrigado pela resposta… Tenho mais uma pergunta: tiles é muito utilizado ? ou está em desuso ?

[]'s Luis Cesar

M

Tiles eh mais utilizado com Struts, pois era um subprojeto desse. Porem, agora virou um projeto separado e a tendencia eh que facilite a integracao com outros frameworks. O problema eh que os releases novos estao muito demorados.

Marco

luiscesarinfo

Muito Obrigado pela atenção…

[]'s Luis Cesar

Criado 13 de março de 2008
Ultima resposta 13 de mar. de 2008
Respostas 8
Participantes 3