Link to home
Start Free TrialLog in
Avatar of Rafael_Moreira
Rafael_Moreira

asked on

Update a table on checkbox event

i want to update the field naoAplicavel of  my table when i click in a ckeckbox of my datatable

but its not working i receive the message that success and only the first row is changed

<!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:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui">
<h:body>
	<ui:composition template="/templates/master.xhtml">

		<ui:define name="divMain">

			<script>
				function tratarAssociacao(args) {
					if (!args.validationFailed) {
						wassociaDlg.hide();
					}
				}
			</script>

			<f:metadata>
				<f:event listener="#{associaItemsBean.inicializar}"
					type="preRenderView" />
			</f:metadata>


			<h:form id="frmPesquisa">
				<h1>Tela de Associar Técnico ao Item</h1>
				<p:separator></p:separator>

				<p:dataTable id="itemsTable" value="#{associaItemsBean.lazyModel}"
					var="item" style="margin-top: 20px;font-size:18px;"
					emptyMessage="
				Nenhum Item encontrado."
					paginatorPosition="bottom" rows="5" paginator="true"
					paginatorTemplate="{RowsPerPageDropdown} {PreviousPageLink} {CurrentPageReport} {NextPageLink}"
					currentPageReportTemplate="(Página {currentPage} de {totalPages}) - (Registro {startRecord} a {endRecord}) - Total ({totalRecords} Registros)"
					styleClass="mystyle" paginatorAlwaysVisible="false"
					rowsPerPageTemplate="20, 50, 100" lazy="true">

					<f:facet id="header" name="header">
                    Lista de Items para associar aos Técnicos
                </f:facet>

					<p:column sortBy="#{item.codigoItem}" filterBy="#{item.codigoItem}"
						style="text-align: center; width: 100px">
						<h:outputText value="#{item.codigoItem}" />
						<f:facet name="header">
							<h:outputText value="Código do Item" />
						</f:facet>

					</p:column>

					<p:column headerText="Descricao" sortBy="#{item.descricao}"
						filterStyle="width: 300px;" filterBy="#{item.descricao}"
						filterMatchMode="startsWith"
						style="text-align: left; width: 140px;">
						<h:outputText value="#{item.descricao}">

						</h:outputText>
					</p:column>

					<p:column headerText="Data do Item"
						style="text-align: center; width: 140px">
						<h:outputText value="#{item.dataItem}">
							<f:convertDateTime pattern="dd/MM/yyyy" />
						</h:outputText>
					</p:column>


					<p:column headerText="Tecnicos / encarregado / Area"
						style="text-align: center; width: 140px">
						<p:dataList value="#{item.tecnicos}" var="tecnico"
							rendered="#{!empty item.tecnicos}">
							#{tecnico.nome}  -  #{tecnico.chefe.nome}  -#{tecnico.chefe.areaEncarregado.descricao}  
						</p:dataList>
					</p:column>

					<p:column headerText="Não Aplicável"
						style="text-align: center; width: 140px">

						<p:selectBooleanCheckbox value="#{item.naoAplicavel}">
							<p:ajax event="change" process="@this"
								update=":frmPesquisa:itemsTable"
								listener="#{associaItemsBean.naoAplicavel}">

								<f:setPropertyActionListener
									target="#{associaItemsBean.itemSelecionado}" value="#{item}" />
							</p:ajax>

						</p:selectBooleanCheckbox>
					</p:column>

					<p:column style="width: 100px; text-align: center">
						<p:commandButton value="Associar" disabled="#{item.naoAplicavel}"
							update=":frmPesquisa:idassociaDlg"
							oncomplete="wassociaDlg.show()" icon="ui-icon-transferthick-e-w"
							process="@this" title="Associar Item ao Técnico">
							<f:setPropertyActionListener
								target="#{associaItemsBean.itemSelecionado}" value="#{item}" />

						</p:commandButton>

					</p:column>

				</p:dataTable>

				<p:dialog widgetVar="wassociaDlg" id="idassociaDlg" height="200"
					width="700" modal="true" closable="true" draggable="false"
					resizable="false" header="--- Associar Técnico ao Item ---">


					<p:outputLabel value="---Técnicos para associar---" for="tecnico" />

					<p:selectManyMenu id="tecnico" styleClass="many-checkbox"
						showCheckbox="true" layout="pageDirection"
						converter="tecnicoConverter"
						value="#{associaItemsBean.itemSelecionado.tecnicos}">
						<f:attribute name="collectionType" value="java.util.ArrayList" />

						<f:selectItems value="#{associaItemsBean.tecnicosDaEmpresa}"
							var="tecnico" itemLabel="#{tecnico.nome}" itemValue="#{tecnico}" />
					</p:selectManyMenu>

					<p:separator />
					<p:commandButton value="Associar" icon="ui-icon-transferthick-e-w"
						action="#{associaItemsBean.associar}" update="@form">
					</p:commandButton>




				</p:dialog>


			</h:form>

		</ui:define>
	</ui:composition>
</h:body>
</html>code]


my method:

[code]@Transactional
	public Item naoAplicavel(Item item) {
		// item = this.items.porId(item.getCodigo());

		Usuario encarregado =new Usuario();
		encarregado.setCodigo(2L);
		System.out.println(encarregado.getNome());
		item.setAreaItem(encarregado.getAreaEncarregado());
		item.setNaoAplicavel(true);
		item.setStatus(StatusItem.ASSOCIADO);
		item = this.items.guardar(item);

		return item;

	}

Open in new window

Avatar of Mahesh Bhutkar
Mahesh Bhutkar

Check you are getting correct Item to process inside naoAplicavel() method.

You are initializing encarregado instance of Usuario.
Usuario encarregado =new Usuario();
Will it have default value for Nome &  AreaEncarregad?
As you are using these fields here directly to set attribute of Item.
encarregado.getNome()
encarregado.getAreaEncarregado()
Avatar of Rafael_Moreira

ASKER

I've requested that this question be deleted for the following reason:

i solved it
ok.
Is my comment helpless?
Is my comment helpless?
ASKER CERTIFIED SOLUTION
Avatar of Rafael_Moreira
Rafael_Moreira

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
put the return of method void was that worked.






public void selecionar(Item item) {
            
            System.out.println("Pedido " + item.getCodigoItem() + " - " +item.isAplicavel());

            
            cadastroItemService.naoAplicar(item);

      }
:), Where this metod comes for?

How it helps to resolve your problem?
i could  find out that the problem was that i was returnind na object . Putting void and only saving solve the problem.