Trabalhando com Table

0 respostas
J

tenho a criaçao de um table dinamicamente, onde crio as colunas e as linhas…e depois faço a concatençao disso tudo, adicionando duas colunas que sao botoes, Alterar e Excluir
O problema esta na execuçao, cria o table normal, cada linha com os dois botoes, mas quando clico em um dos botoes, ele executa os dois e quantos registros tive, ou seja, se tiver 16 registros, vai executar 16 vezes os dois botoes.

aqui vai o codigo:

private HtmlPanelGrid dynamicDataTableGroup; // Placeholder.
private void populateDynamicDataTable() {
		// Create <h:dataTable value="#{myBean.dynamicList}" var="dynamicItem">.
		HtmlDataTable dynamicDataTable = new HtmlDataTable();

		ValueExpression ve = FacesContext
				.getCurrentInstance()
				.getApplication()
				.getExpressionFactory()
				.createValueExpression(
						FacesContext.getCurrentInstance().getELContext(),
						"#{criaGrid.dynamicList}", List.class);

		dynamicDataTable.setValueExpression("value", ve);
		dynamicDataTable.setVar("dynamicItem");
		// Iterate over columns.
		for (int i = 0; i < dynamicList.get(0).size(); i++) {
			// Create <h:column>.
			HtmlColumn column = new HtmlColumn();
			dynamicDataTable.getChildren().add(column);

			// Create <h:outputText value="dynamicHeaders[i]"> for <f:facet
			// name="header"> of column.
			HtmlOutputText header = new HtmlOutputText();
			header.setValue(dynamicHeaders[i]);
			column.setHeader(header);

			// Create <h:outputText value="#{dynamicItem[" + i + "]}"> for the
			// body of column.
			HtmlOutputText output = new HtmlOutputText();
			ValueExpression ve2 = FacesContext
					.getCurrentInstance()
					.getApplication()
					.getExpressionFactory()
					.createValueExpression(
							FacesContext.getCurrentInstance().getELContext(),
							"#{dynamicItem[" + i + "]}", String.class);

			output.setValueExpression("value", ve2);
			column.getChildren().add(output);
			
			//***Aqui cria os botoes*******
			if (i + 2 == dynamicList.get(0).size()) {
				FacesContext fctx = FacesContext.getCurrentInstance();
				ELContext elctx = fctx.getELContext();
				Application app = fctx.getApplication();
				ExpressionFactory exprFactory = app.getExpressionFactory();
				HtmlCommandButton edit = (HtmlCommandButton) app
						.createComponent(HtmlCommandButton.COMPONENT_TYPE);
				edit.setId("edit");
				edit.setValueExpression("value", exprFactory
						.createValueExpression(elctx,
								"#{transacaoLinhas.gridEdit}", String.class));
				column.getChildren().add(edit);
			} else if (i + 1 == dynamicList.get(0).size()) {
				FacesContext fctx = FacesContext.getCurrentInstance();
				ELContext elctx = fctx.getELContext();
				Application app = fctx.getApplication();
				ExpressionFactory exprFactory = app.getExpressionFactory();
				HtmlCommandButton delete = (HtmlCommandButton) app
						.createComponent(HtmlCommandButton.COMPONENT_TYPE);
				delete.setId("delete");
				delete.setValueExpression("value", exprFactory
						.createValueExpression(elctx,
								"#{transacaoLinhas.gridDelete}", String.class));
				column.getChildren().add(delete);
			}
		}

		// Add the datatable to <h:panelGroup
		// binding="#{myBean.dynamicDataTableGroup}">.
		dynamicDataTableGroup = new HtmlPanelGrid();
		dynamicDataTableGroup.getChildren().add(dynamicDataTable);
	}

Isso está sendo criado em JSF.

Criado 1 de outubro de 2010
Respostas 0
Participantes 1