DataTable selection does not work as expected

UI Components for JSF
Post Reply
huof
Posts: 18
Joined: 22 Dec 2010, 17:57

02 Jun 2011, 19:41

Hi all

I have the following page:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<f:view xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui">

	<h:head />

	<h:form>

		<p:dataTable var="organization"
			value="#{organizationBean.lazyOrganizations}" paginator="true"
			rows="10" lazy="true"
			paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
			rowsPerPageTemplate="5,10,15"
			selection="#{organizationBean.selectedOrganization}"
			selectionMode="single" onRowSelectUpdate="display"
			onRowSelectComplete="orgDialog.show()">

			<f:facet name="header">
			</f:facet>

			<p:column headerText="Name">
				<h:outputText value="#{organization.organisationName}" />
			</p:column>

			<p:column headerText="VAT Nr">
				<h:outputText value="#{organization.vatNr}" />
			</p:column>
		</p:dataTable>

	</h:form>

	<p:dialog header="Organization Detail" widgetVar="orgDialog"
		resizable="false" width="200" showEffect="explode"
		hideEffect="explode">

		<h:panelGrid id="display">
			<h:outputText value="Name:" />
			<h:outputText value="#{organizationBean.selectedOrganization.organisationName}" />

			<h:outputText value="VAT Nr:" />
			<h:outputText value="#{organizationBean.selectedOrganization.vatNr}" />
		</h:panelGrid>
	</p:dialog>

</f:view>
My OrganizationBean looks like:

Code: Select all

package my.service.web;

import java.util.List;
import java.util.Map;

import org.primefaces.model.LazyDataModel;
import org.springframework.beans.factory.InitializingBean;

import my.entities.Organization;
import my.service.OrganizationService;

public class OrganizationBean implements InitializingBean {
	private OrganizationService organizationService;
	private Organization selectedOrganization;
	private LazyDataModel<Organization> lazyOrganizations;

	public Organization getSelectedOrganization() {
		return selectedOrganization;
	}

	public void setSelectedOrganization(Organization selectedOrganization) {
		this.selectedOrganization = selectedOrganization;
	}

	public void setOrganizationService(OrganizationService organizationService) {
		this.organizationService = organizationService;
	}
	
	public LazyDataModel<Organization> getLazyOrganizations() {
		return lazyOrganizations;
	}

	public List<Organization> getAllOrganizations(){
		List<Organization> result = organizationService.getAllOrganizations(); 
		return result;
	}

	public void afterPropertiesSet() throws Exception {
		lazyOrganizations = new LazyDataModel<Organization>() {
			private static final long serialVersionUID = 1L;

			@Override
			public List<Organization> load(int first, int pageSize, String sortField, boolean sortOrder, Map<String,String> filters) {
				return organizationService.getOrganizations(first, pageSize);
			}
		};
		
		//TODO should be set with help of projection to the real value.
		lazyOrganizations.setRowCount(3500);
	}
}
My environment is
[*] JSF 2 (sun)
[*] Primefaces 2.2.1
[*] Portlet 2.0 / Liferay 6
[*] PortletBridge 2.0.0

The problem that I am facing now is that the row selection does not work as expected.
When I load the page and select a row that the popup shows up but has no content.
Then I press F5 and reload the page. Afterwards when I select a row the popup has content, but it has only the content of the row selected directly before the F5-hit.
This means I can press what ever I want, the content is always the one of the row that was selected before F5.

Can anybody help me out?

Best regards,
Florian

huof
Posts: 18
Joined: 22 Dec 2010, 17:57

03 Jun 2011, 08:51

I found out that the bean is accessed correctly. This means the selectedItem is set and read correctly.
But it is not shown on the page.
After pressing F5 something on the page is updated and then it works.

Any ideas?

huof
Posts: 18
Joined: 22 Dec 2010, 17:57

03 Jun 2011, 13:12

Hi all,

I found the soltution.
Primefaces cannot handle portlet-namespace. The portlet bridge prefixes every id with the portlet namespace.

e.g. id="test" gets id="A73334:test" in the HTML.
when I have a button that has update="test" it does not work.

As workaround I made
<portlet:namespace var="pn" />
update="#{pn}:test

Is this a bug?

I tried also with the latest 3.0.M1 version.

User avatar
mediterran81
Posts: 29
Joined: 22 Mar 2011, 12:14
Location: France
Contact:

03 Jun 2011, 20:00

I have almost the same problem but in a different environment (Mysql, JPA, JSF 2)

In my index.xhtml page, the problem disappears if I use the datatable attribute :

Code: Select all

rowselectlistener=""
as you mentioned, it might be a client issue related to IDs. Not sure! Maybe an ajax request is fired and it blocks the update of the dialog!
I tried the same thing with a

Code: Select all

<p:outputPanel>
but in vain:!

here is my listener :

Code: Select all

public String prepareView() {
        current = (Hospital) getItems().getRowData(); //  the selected item row data
        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); // the selected item index in the table
        return "View"; // The outcome
    }
But in my other pages! This does not work for some unknown reason!
This is not really a bug, if you try the showcase example, the selection will work!

jendruch
Posts: 2
Joined: 04 Jun 2011, 11:08

04 Jun 2011, 11:38

Hi,

I'm using 3.0.M2-SNAPSHOT. "Basic Selection" (labs showcases: http://www.primefaces.org/showcase-labs ... Column.jsf) in dataTables stop working - propably after change in org.primefaces.component.datatable package. This was commited 02-06-2011 at 11:33 (the day before) with comment: "Implemented rowSelect/unSelect as ajax behaviors for datatable". I'm using PrimeFaces commandButton to select row - and now (since 02-06-2011) it doesn't work.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

04 Jun 2011, 14:06

Lab demos are fixed although not deployed online yet.


Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 41 guests