Solved

Update a table on checkbox event

Posted on 2014-01-21
10
541 Views
Last Modified: 2014-02-16
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

0
Comment
Question by:Rafael_Moreira
  • 5
  • 4
10 Comments
 
LVL 6

Expert Comment

by:Mahesh Bhutkar
ID: 39799250
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()
0
 

Author Comment

by:Rafael_Moreira
ID: 39838159
I've requested that this question be deleted for the following reason:

i solved it
0
 

Author Comment

by:Rafael_Moreira
ID: 39837708
ok.
0
 
LVL 6

Expert Comment

by:Mahesh Bhutkar
ID: 39838153
Is my comment helpless?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Expert Comment

by:Mahesh Bhutkar
ID: 39838160
Is my comment helpless?
0
 

Accepted Solution

by:
Rafael_Moreira earned 0 total points
ID: 39838821
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);

	}

Open in new window

0
 

Author Comment

by:Rafael_Moreira
ID: 39838830
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);

      }
0
 
LVL 6

Expert Comment

by:Mahesh Bhutkar
ID: 39838928
:), Where this metod comes for?

How it helps to resolve your problem?
0
 

Author Closing Comment

by:Rafael_Moreira
ID: 39849633
i could  find out that the problem was that i was returnind na object . Putting void and only saving solve the problem.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now