Dúvida JSF 1.2 + RICHFACES 3.3.3-FINAL

tenho esse trecho de xhtml

[code]<h:form prependId=“false”>
a4j:region

Estado:

<h:selectOneMenu value="#{simpleSearch.uf}" style=“width:230px;” id=“uf”>
<f:selectItem itemValue="" itemLabel="-- Selecione --" />
<f:selectItems value="#{simpleSearch.ufs}" />
<a4j:support event=“onchange” reRender=“comboCidade” immediate=“true” ajaxSingle=“true” />
</h:selectOneMenu>
				<div style="font-size:12px;">Cidade:</div>
				<h:selectOneMenu value="#{simpleSearch.cidade}" style="width:230px;" id="comboCidade">
		      		<f:selectItem itemValue="" itemLabel="-- Selecione --" />
		      		<f:selectItems value="#{simpleSearch.cidades}" />
		      	</h:selectOneMenu>
			</a4j:region>
	</h:form>[/code]

ele carrega corretamente os estados (ufs) porém ao selecionar um deles o combo abaixo não está sendo refeito, nem sequer é chamada a função getCidades()…descrita abaixo

[code]public List getCidades() {
cidades = new ArrayList();
if(uf != null){
Set cs = new HashSet();

		for(Convenio con : conveniosByNome){
			cidades.add(new SelectItem(con.getCidade(), c.getCidade()));
		}
					
	}
	return cidades;
}[/code]

esse método está na classe:

@Component("simpleSearch") @Scope("request") @KeepAlive(ajaxOnly=true) public class SimpleSearchMB {...

Será que tem algo a ver com o @KeepAlive
Onde estou errando? alguma luz.

O keepAlive guarda apenas o estado dos campos ajax …

tente colocar assim:

<h:selectOneMenu value="#{simpleSearch.cidade}" style="width:230px;" id="comboCidade"> <f:selectItem itemValue="" itemLabel="-- Selecione --" /> <f:selectItems value="#{simpleSearch.cidades}" /> </h:selectOneMenu> <a4j:support event="onchange" reRender="comboCidade" immediate="true" ajaxSingle="true" />

Não me recordo se é isto, faça um teste …

Não entendi o que você quiz, Aleksandro, porém fiz alguns testes e debugs…o que acontece é o seguinte:

ao mudar o combo de estado a variavel #{simpleSearch.uf} não está sendo setada, e o mais curioso que a função q é chamada é a getCidade e não getCidades q monta o combo2…
tentei montar o combo1 assim:

<h:selectOneMenu value="#{simpleSearch.uf}" style="width:230px;" id="uf"> <f:selectItem itemValue="" itemLabel="-- Selecione --" /> <f:selectItems value="#{simpleSearch.ufs}" /> <a4j:support event="onchange" reRender="uf,comboCidade" immediate="true" ajaxSingle="true" > <a4j:actionparam name="uf" value="document.getElementById('uf').value" assignTo="#{simpleSearch.uf}" noEscape="true" /> </a4j:support> </h:selectOneMenu>

usando o a4j:actionparam…mas tbm não funcionou

Alguem se candidata a tentar me ajudar?

Olá desenhotorix.

Tente adicionar a instrução “action” em a4j:suport, segue exemplo:

&lt;a4j:support event="onchange" reRender="comboCidade" action="#{simpleSearch.getCidades}"/&gt;   

Att,
Leonardo K. Masuda

Olá leonardo.m4a…também ja fiz isso e não funcionou.

Testei fazendo

<a4j:support event="onchange" reRender="comboCidade" action="#{simpleSearch.cidades}"/>

Isso é tão trivial, inclusive há algo similar no meu projeto e funciona, porém esse caso especifico ta emperrado. E sinceramente não sei mais o que fazer.

Mas valeu pela dica…Se alguem mais souber de um “truque”…estou todos ouvidos

O meu esta assim e funciona na boa …inclusive quando eu fiz peguei o exemplo do http://serjaum.wordpress.com/2009/08/28/jsf-tutorial-combos-aninhados-estadoscidades/ da uma olhada …


<body>
<f:view>
	<h:form>
		<h:panelGrid columns="2">
			<h:outputLabel for="estado" value="Estado " />
			<h:selectOneMenu id="estado" value="#{regiaoMB.estado.id}">
				<f:selectItem itemValue="" itemLabel="Selecione..." />
				<f:selectItems value="#{regiaoMB.estados}" />
				<a4j:support event="onchange" ajaxSingle="true"
					action="#{regiaoMB.actionCarregaCidades}" reRender="estado,cidade" />
			</h:selectOneMenu>

			<h:outputLabel for="cidade" value="Cidade " />
			<h:selectOneMenu id="cidade" value="#{regiaoMB.cidade.id}">
				<f:selectItem itemValue="" itemLabel="Selecione..." />
				<f:selectItems value="#{regiaoMB.cidades}" />
			</h:selectOneMenu>
		</h:panelGrid>
	</h:form>
</f:view>
</body>

Também utilizei da mesma forma que o Aleksandro citou e funciona perfeitamente.

Segue exemplo de como utilizei:

<h:selectOneMenu id="categoria" value="#{vndProdHANDLER.id_categoria_sel}">  
	<f:selectItem itemLabel="" itemValue="0"/>	
	<f:selectItems value="#{vndProdHANDLER.selectItemCategoria}"/>
	<a4j:support event="onchange" reRender="subcategoria" action="#{vndProdHANDLER.carregaSubcategoria}"/>   
</h:selectOneMenu>
<h:selectOneMenu id="subcategoria" value="#{vndProdHANDLER.id_subcategoria_sel}">  
	<f:selectItem itemLabel="" itemValue="0"/>	
	<f:selectItems value="#{vndProdHANDLER.selectItemSubcategoria}"/>
</h:selectOneMenu>

Bean:

	public void carregaSubcategoria(){
		selectItemSubcategoria = new ArrayList<SelectItem>();
		SubcategoriaDAO  subcategoriaDAO = SubcategoriaDAO.getInstance();
		listaSubcategoriaENTITY = subcategoriaDAO.getListaSubcategoriaByCategoria(this.getId_categoria_sel());
		for( SubcategoriaENTITY subcategoriaENTITY : listaSubcategoriaENTITY ){
			selectItemSubcategoria.add( new SelectItem(subcategoriaENTITY.getId_subcategoria(), subcategoriaENTITY.getNome() ) );
		}
	}

Valeu a todos que me ajudaram…mas resolvi o problema, porem não entendi porque não funcionava.

Antes desses meu comboboxes havia uma verificação

<h:outputText rendered="#{requestScope['msg'] == 'NO_COOKIE'}">

ou seja, exibe o combo se tiver como retorno essa string…a verificação funcionava, porem ela travava os combos.

retirei-a…e funcionou perfeitamente.

Mas fica a dúvida, por quê ? Será que tem alguma coisa a ver com o “requestScope”