Solved

Update a table on checkbox event

Posted on 2014-01-21
10
576 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

623 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