Problem with ajax update ID format in PF datatable

UI Components for JSF
Post Reply
pavaros
Posts: 73
Joined: 22 Jun 2010, 17:45
Location: Netherlands
Contact:

13 Jan 2012, 10:48

When using an ajax update event in a datatable, I am aware that I need to specify the full ID of the container component that I need to update. For instance with the following simple example:
page:

Code: Select all

<f:view
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">
	
	<html xmlns="http://www.w3.org/1999/xhtml">
		<h:head>
		</h:head>
		<h:body>
			<h:form id="itemform">
				<p:dataTable value="#{tbean.table}" var="row" 
						selectionMode="single" selection="#{tbean.selectedItem}" style="width: 500px">
					<p:ajax event="rowSelect" update="itemform:rowdetails"/>
					<p:column headerText="column 1">
						<h:outputText value="#{row.text1}"/>
					</p:column>
					<p:column headerText="column 2">
						<h:outputText value="#{row.text2}"/>
					</p:column>
				</p:dataTable>
				<h:panelGrid id="rowdetails" columns="2">
					<h:outputLabel value="text1 of selected row:"/>
					<h:outputText value="#{tbean.selectedItem.text1}"/>
					<h:outputLabel value="text2 of selected row:"/>
					<h:outputText value="#{tbean.selectedItem.text2}"/>
				</h:panelGrid>
			</h:form>
		</h:body>
	</html>
</f:view>
bean:

Code: Select all

package nl.timeware.vrtsim.beans;

import java.io.Serializable;
import java.util.*;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

public class TableBean implements Serializable
{
	private Table table = null;
	
	private Item selectedItem = null;

	public TableBean()
	{	table = new Table();
	}
	
	public Table getTable()
	{	return table;
	}
	
	public Item getSelectedItem()
	{	return selectedItem;
	}
	
	public void setSelectedItem(Item it)
	{	selectedItem = it;
	}

	public class Table extends ListDataModel<Item> implements SelectableDataModel<Item>, Serializable
	{	
		private List<Item> itemList = new ArrayList<Item>(5);

		public Table()
		{	setWrappedData(itemList);
			for (short it = 0; it < 5; it++)
				itemList.add(new Item(it));
		}
		public Object getRowKey(Item it)
		{	return it.getID();
		}
		public Item getRowData(String key)
		{	for (Item it: itemList)
				if (Integer.toString(it.getID()).equals(key)) return it;
			return null;
		}
	}
	
	public class Item implements Serializable
	{	
		private int id;
		
		public Item(short it)
		{	id = it;
		}
		public int getID()
		{	return id;
		}
		public String getText1()
		{	return "Item " + id + ", first column";
		}
		public String getText2()
		{	return "Item " + id + ", second column";
		}
	}	
}
If I use <p:ajax event="rowSelect" update="rowdetails"/> in stead of <p:ajax event="rowSelect" update="itemform:rowdetails"/>, the details panel isn't updated. This seems to be a problem with PF. Now, my problem is that it isn't always possible to use the full ID ("itemform:rowdetails"). For instance when using this construct inside a dynamic tabform, I don't know the full ID path at all (contains an unpredictable tab index). Is there any solution or workaround to this problem?
JSF 2.2.3, Primefaces 4.0, Tomcat-7.0.40

Max_S
Posts: 42
Joined: 24 Oct 2011, 18:05

13 Jan 2012, 11:27

pavaros wrote:When using an ajax update event in a datatable, I am aware that I need to specify the full ID of the container component that I need to update.
Is there any solution or workaround to this problem?
It's Probably related to this (unsolved) issue:
viewtopic.php?f=3&t=17454


oleg posted a workaround that implies building pf from source.
I posted a dirty thing that may fit to your situation , maybe.

good luck.


EDIT: sorry, i had read datalist instead of datatable, don't know if the issue is related...(actually i think they both use the findClientIds method, so may be)
GlassFish Server Open Source Edition 3.1.1 (12) / Mojarra 2.1.3 (FCS b02) / PrimeFaces 3.0.1 / Eclipse Indigo

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 25 guests