JSF 2 - Action executa apenas na segunda vez

1 resposta
marcosvidolin

Olá galera,

Alguém poderia me ajudar numa duvida que me persegue e que não consigo entender.
É o seguinte... Tenho a seguinte estrutura de layout e em alguns momentos quanto tento acessar os links para alterar de pagina, é preciso clicar mais de uma vez para a action seja executada e seja renderizada.
Este problema geralmente ocorre quando acesso alguma pagina através do menu e em seguida tento acessar alguma outra através dos links exibidos no conteúdo.
O que parece é que a primeira vez que clico no link a pagina apenas realiza um refresh, e a segunda vez é que realmente a ection é executada.

mainLayout.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:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">

<h:head>
	<title>Plain Project</title>
</h:head>

<h:body>
	<table width="100%" cellpadding="0" cellspacing="5">
		<tr style="height: 100%; vertical-align: top">
			<td colspan="2">
				<ui:insert name="header">Main Layout Header (from mainLayout.xhtml)</ui:insert>
			</td>
		</tr>
		<tr style="height: 100%; vertical-align: top">
			<td id="menu" width="200px">
				<ui:insert name="menu">
					<ui:include src="/pages/commun/menu.xhtml" />
				</ui:insert></td>
			<td id="workArea">
				<ui:insert name="workArea">Main Layout Content (from mainLayout.xhtml)</ui:insert>
			</td>
		</tr>
	</table>
</h:body>
</html>
workLayout.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:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich">

<ui:composition template="/WEB-INF/templates/mainLayout.xhtml">

	<ui:define name="workArea">
		<rich:panel>
			<f:facet name="header">
				<ui:insert name="title">Work Area Title (from workLayout)</ui:insert>
			</f:facet>
			<ui:insert name="content">Work Area Content (from workLayout)</ui:insert>
		</rich:panel>
	</ui:define>

</ui:composition>
</html>
menu.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:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich">

<ui:composition>
	<h:form>
		<rich:panelMenu groupExpandedLeftIcon="triangleUp"
			groupCollapsedLeftIcon="triangleDown"
			topGroupExpandedRightIcon="chevronUp"
			topGroupCollapsedRightIcon="chevronDown" itemLeftIcon="disc"
			expandSingle="false">
			<rich:panelMenuGroup label="Menu" expanded="true">
				<rich:panelMenuGroup label="Paginas">
					<rich:panelMenuItem label="Pagina 1" action="pagina1" />
					<rich:panelMenuItem label="Pagina 2" action="pagina2" />
				</rich:panelMenuGroup>
			</rich:panelMenuGroup>
		</rich:panelMenu>
	</h:form>
</ui:composition>
</html>
pagina1.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:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich">

<ui:composition template="/WEB-INF/templates/workLayout.xhtml">

	<ui:define name="title">
		Pagina 1
	</ui:define>
	<ui:define name="content">
		<h:form>
			<h:commandLink action="pagina2" value="Link para pagina 2" />
		</h:form>
	</ui:define>

</ui:composition>
</html>
pagina2.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:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich">

<ui:composition template="/WEB-INF/templates/workLayout.xhtml">

	<ui:define name="title">
		Pagina 2
	</ui:define>
	<ui:define name="content">
		<h:form>
			<h:commandLink action="pagina1" value="Link para pagina 1" />
		</h:form>
	</ui:define>

</ui:composition>
</html>

Obs.: O mesmo ocorre utilizando apenas JSF 2 (sem RichFaces).

Fico muito grato com a ajuda.
[]'s

1 Resposta

marcosvidolin

Olá pessoal,

Aparentemente descobri o que é o problema. =]
Reparem que com esse template que configurei, as paginas possuíam 2 forms (menu e conteudo).
Reformulei o template para que as paginas passassem a ter apenas um form e foi o fim do refresh.

[]'s

Criado 21 de novembro de 2011
Ultima resposta 22 de nov. de 2011
Respostas 1
Participantes 1