Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Update a table on checkbox event

Posted on 2014-01-21
10
Medium Priority
?
610 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
9 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Suggested Courses
Course of the Month6 days, 13 hours left to enroll

782 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