Problema com ViewScoped JSF2 e render do Richfaces 4

0 respostas
R

Bom dia Pessoal,

tenho o seguinte código:

teste.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">
<h:head>
  <title>Teste</title>
</h:head>
<h:body>	
	
	<rich:panel id="teste_panel"> 
	
	<a4j:outputPanel rendered="#{teste.testeStr == 'teste2' or teste.testeStr == null}"> 
	 	<h:form>
			<a4j:commandButton value="Teste1" action="#{teste.teste1}" render="teste_panel"/>
		</h:form>
	</a4j:outputPanel>
	
	<a4j:outputPanel rendered="#{teste.testeStr == 'teste1' or teste.testeStr == null}">
		<h:form>
			<a4j:commandButton value="Teste2" action="#{teste.teste2}" render="teste_panel"/>
		</h:form>
	</a4j:outputPanel>
	 
	 <a4j:outputPanel rendered="#{teste.testeStr == null}">
	  	oi
	 </a4j:outputPanel>
	 <h:outputText value="#{teste.testeStr}"/>

	</rich:panel>
</h:body>
</html>

e TesteManagedBean:

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean(name = "teste")
@ViewScoped
public class TesteManagedBean {

	private String testeStr;
	
	public String getTesteStr() {
		return testeStr;
	}

	public void setTesteStr(String testeStr) {
		this.testeStr = testeStr;
	}

	@PostConstruct
	public void postConstruct(){
		System.out.println("Construct");
	}
	
	public void teste1(){
		testeStr = "teste1";
		System.out.println("Teste1");
	}
	
	public void teste2(){
		testeStr = "teste2";
		System.out.println("Teste2");
	}
}

Ao clicar nos botões Teste1 e Teste2 o conteúdo escrito no console deveria ser:
Construct
Teste1
Teste2

mais não é isso que acontece, escreve o seguinte:

Construct
Teste1
Construct

ou seja, ao clicar no botão Teste2 ele chama o construtor novamente.

Alguém sabe como posso estar resolvendo?

Criado 22 de março de 2012
Respostas 0
Participantes 1