update a single row in a datatable

UI Components for JSF
Post Reply
tomik
Posts: 32
Joined: 21 Jan 2011, 06:50

20 Jun 2011, 06:37

Hi,

I have a lazily-loaded datatable with records, each of which contains a list of tags (keywords). I want to be able to remove/add a tag to any of the records, and update only the single record (the list of tags -- "refTagsList" below) as opposed to reloading the entire datatable page. Is this possible?

This is what I have so far (which doesn't work):

Code: Select all

       <h:form id="refs">       		               
			   <p:outputPanel id="referencesAll">
			     <p:dataTable id="referenceList" var="reference" value="#{referencesAllBean.references}" 
			     		paginator="true" rows="5" paginatorTemplate="{CurrentPageReport}  
			     		{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} 
			     		{LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15"
			     		paginatorPosition="bottom" lazy="true">			     		
			     	<p:column>			     		
				     	<h:outputText value="#{reference.title}" style="font-weight:bold;"/>
				     	<br/>
				     	<ui:repeat value="#{reference.authors}" var="author" varStatus="status">
				     		<h:outputText value="#{author.authorLName}"/> 			  	                
				     		<h:outputText value="#{author.authorFName}"/>
						 	<h:outputText value="#{author.authorMName}"/>
						    <h:outputText value=", " rendered="#{!status.last}" />
						</ui:repeat>  
						<br/>
				     	<h:outputText value="#{reference.journal.journalName}" rendered="#{reference.type == 'JournalReference'}"/>,      	  
				     	<h:outputText value="#{reference.pubDate}"/> 
				     	<br/>
				     	
			            <h:outputLabel for="tags" value="Tags: " />  
			            <p:outputPanel id="refTagsList">
			            <ui:repeat value="#{reference.tags}" var="tag" varStatus="status">
				     		<h:outputText value="#{tag.tag}"/> 
				     		<p:spacer width="2px"/>
				     		<p:commandLink action="removeTag" actionListener="#{reference.removeTag}" update=":refs:refTagsList">
						  		<f:attribute name="index" value="#{status.index}" />
						  		<f:setPropertyActionListener value="#{reference}" target="#{referencesAllBean.selectedReference}" />
								<p:graphicImage url="/images/delete_BW.png" 
									style="width: 10px; height: 10px;" /> 
						    </p:commandLink> 			  	              
						    <p:spacer width="7px"/>  
						</ui:repeat>   
			                       <p:commandLink title="Edit tags" update="refTags" oncomplete="tagsDialog.show()" value="Add Tag">  
				     	 	      <f:setPropertyActionListener value="#{reference}" target="#{referencesAllBean.selectedReference}" />
				              </p:commandLink> 				        				    						     		
	                              </p:outputPanel>			     				         
			     	</p:column>			     	
			     </p:dataTable>  
			   </p:outputPanel>
     	   	      </h:form> 
Thank you!

T.

tomik
Posts: 32
Joined: 21 Jan 2011, 06:50

21 Jun 2011, 23:25

Any ideas?

MilenaMMay
Posts: 13
Joined: 31 May 2011, 17:15

22 Jun 2011, 15:40

I notice you define a for="tags" in <h:outputLabel for="tags" value="Tags: " /> but no component with id="tags". This is no crucial error but you should remove the for property or pass id="tags" to one of your components.

tomik
Posts: 32
Joined: 21 Jan 2011, 06:50

22 Jun 2011, 16:26

You're right; it's a left-over piece of code from a previous version, it'll be removed.

I don't think that will have an effect on what I'm trying to do though.

MilenaMMay
Posts: 13
Joined: 31 May 2011, 17:15

23 Jun 2011, 08:12

I haven't understood yet what problem exactly you're facing. You say your code is not working - what does that mean? Is there a parsing error, an exception or does it not do what it's supposed to?

tomik
Posts: 32
Joined: 21 Jan 2011, 06:50

23 Jun 2011, 18:38

Sorry for not being more clear.

What is not working is the ajax partial update of the "refTagsList" panel when a tag is added or removed to a given record in the datatable. I have to refresh the whole datatable to see the change to the row.

T.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Bogdanbgr and 42 guests