Problemas para renderizar lista dinâmica com JSF 2 e Ajax

0 respostas
H

Boa Tarde Pessoal estou tentando criar formulário com um selectItem com uma quantidade de componentes. Ao selecionar um valor deverá se exibido uma lista com 5 selectBox para cada item.
Consigo recuperar apenas os valores do meu checkBox quando crio uma lista estatica e quando coloco uma lista dinamica meu map onde armazeno o valor do checkbox retorna nulo.
Segue o trecho do meu código contendo apenas um checkbox.
Agradeço quem puder ajudar.

xhtml

<?xml version="1.0" encoding="UTF-8"?>

<ui:composition xmlns=“http://www.w3.org/1999/xhtml
xmlns:ui=“http://java.sun.com/jsf/facelets
xmlns:f=“http://java.sun.com/jsf/core
xmlns:h=“http://java.sun.com/jsf/html
template="/WEB-INF/templates/template.xhtml">
<ui:define name=“content”>
<h:form>
<h:selectOneMenu value="#{formBean.numero}">
<f:selectItems value="#{formBean.quantidadeLoja}" />
<f:ajax execute="@this" render=“painel” />
</h:selectOneMenu>

<h2>Selected Types</h2>
<h:panelGroup id=painel>

<ui:repeat var=item value="#{formBean.items}">

<h:outputText value="#{item}" style=width : 100px;float : left />

<h:selectBooleanCheckbox value="#{formBean.checkMap[item]}">
</h:selectBooleanCheckbox>
			<br />

		</ui:repeat>
		<h:commandButton value="Update" action="refresh" />
		<h:commandButton value="Enviar" action="#{formBean.enviar}" />

</h:panelGroup>
</h:form>

</ui:define>

</ui:composition>

Classe

public class FormBean {

private String numero;
private int intNumero;

public void setIntNumero(int intNumero) {
	this.intNumero = intNumero;
}

public String enviar() {

	getSelected();
	return "";
}

public List<SelectItem> quantidadeLoja;
public List<SelectItem> lista = new ArrayList<SelectItem>();

private List<String> items;

private Map<String, Boolean> checkMap;

public FormBean() {
	getQuantidadeLoja();

}

public void setItems(List<String> items) {
	this.items = items;
}

public List<String> getItems() {
	items = new ArrayList<String>();
	if (getIntNumero() != 0) {
		int max = getIntNumero();
		for (int i = 0; i < max; i++) {
			items.add(String.valueOf(i));
		}
		checkMap = new HashMap<String, Boolean>();
		for (String item : items) {
			checkMap.put(item, Boolean.FALSE);
		}

	}
	return items;
}

public String getSelected() {
	String result = "";
	for (Entry<String, Boolean> entry : checkMap.entrySet()) {
		if (entry.getValue()) {
			result = result + ", " + entry.getKey();
		}
	}
	if (result.length() == 0) {
		return "";
	} else {
		System.out.println(result.substring(2));
		return result.substring(2);
	}
}

public Map<String, Boolean> getCheckMap() {
	return checkMap;
}

public int getIntNumero() {
	try {
		return Integer.parseInt(numero);
	} catch (Exception e) {
		System.out.println("nulo");
		return 0;
	}

}

public String getNumero() {
	return numero;

}

public void setNumero(String numero) {

	this.numero = numero;
	try {
		this.intNumero = Integer.parseInt(numero);
	} catch (Exception e) {
		this.intNumero = 0;
		// TODO: handle exception
	}
}

public void setLista(List<SelectItem> lista) {
	this.lista = lista;
}

public List<SelectItem> getQuantidadeLoja() {
	System.out.println("Quantidade Loja");
	this.quantidadeLoja = new ArrayList<SelectItem>();
	for (int i = 1; i < 51; i++)
		this.quantidadeLoja.add(new SelectItem(String.valueOf(i)));

	return quantidadeLoja;
}
Criado 17 de abril de 2012
Respostas 0
Participantes 1