Solved

Update a table on checkbox event

Posted on 2014-01-21
10
548 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 6

Expert Comment

by:Mahesh Bhutkar
ID: 39838153
Is my comment helpless?
0
 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JavaScript parse form with colon separated values 2 77
login jsp example 24 49
servlet web applications   metadata-complete="true" or false 3 40
null output 3 25
Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

770 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