First row selection problem

UI Components for JSF
Post Reply
4l3x
Posts: 6
Joined: 22 Aug 2011, 11:35

30 Aug 2011, 10:18

Hi,

I'm using the Primefaces datatable component with the option to select a row.

I want to select a row and get it on the backingBean to process.

Here is the code for the table:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>Table Test</title>
</h:head>
<h:body>
	<h:form id="formulario">
		<p:dataTable value="#{detail_MB.resultList}" var="dataItem"
			id="tabla1"	rowSelectListener="#{detail_MB.processDataItem}"			
			selectionMode="single">			
			<p:column headerText="Producto" style="width:100px">
				<p:cellEditor>
					<f:facet name="output">
						<h:outputText value="#{dataItem.lista[0][1]}" />
					</f:facet>
					<f:facet name="input">
						<h:inputText value="#{dataItem.lista[0][1]}" style="width:100%" />
					</f:facet>
				</p:cellEditor>
			</p:column>

			<p:column headerText="Precio" style="width:150px">
				<p:cellEditor>
					<f:facet name="output">
						<h:outputText value="#{dataItem.lista[1]}" />
					</f:facet>
					<f:facet name="input">
						<h:inputText value="#{dataItem.lista[1]}" style="width:100%">
							<f:converter binding="#{detail_MB.floatC}" />
						</h:inputText>
					</f:facet>
				</p:cellEditor>
			</p:column>

			<p:column headerText="Cantidad" style="width:200px">
				<p:cellEditor>
					<f:facet name="output">
						<h:outputText value="#{dataItem.lista[2]}" />
					</f:facet>
					<f:facet name="input">
						<h:inputText value="#{dataItem.lista[2]}" style="width:100%">
							<f:converter binding="#{detail_MB.integerC}" />
						</h:inputText>
					</f:facet>
				</p:cellEditor>
			</p:column>

		</p:dataTable>
	</h:form>


</h:body>
</html>
Here is the code for the method in the backingBean:

Code: Select all

       public void processDataItem(SelectEvent ev){
	// Get selected MyData item to be edited.
        ObjGenerico dataItem = (ObjGenerico) ev.getObject();
        System.out.println("Fila seleccionada: "+dataItem.getLista());
	}
The problem is that when I select the first row in the table I get in the backingBean the data from the last row that is showing. If I select one of the other rows if works properly.

Why this behaviour happens? Is there a bug?

Somebody can help me?

I've read the Migration Guide to 3.0 (http://wiki.primefaces.org/display/Gene ... ide+to+3.0) but I don't know how to configure the rowSelectListener for the table with p:ajax.
Primefaces 2.2.1/ Migrating to 3.0M4
MyFaces 2.1.2
Tomcat 7.0.14

4l3x
Posts: 6
Joined: 22 Aug 2011, 11:35

06 Sep 2011, 16:31

Hi, again.

I've being doing tests and I chack that this issue happens when I use a version of myFaces library grater than 2.0.0. With myFaces version 2.0.0 all works ok.


Somebody knows why this happens?

I've trying to use mojarra but I0m generating the datatable from the backing bean and not get all the resources related and then the datatable doesn't work.

Somebody Knows what have I done to get the resources in this case?

Any help will be really preciated.
Primefaces 2.2.1/ Migrating to 3.0M4
MyFaces 2.1.2
Tomcat 7.0.14

Siebert76
Posts: 10
Joined: 11 Aug 2011, 20:31

06 Sep 2011, 16:40

hey there,

you really should post the bean-code, where you holding/getting the data from. Otherwise nobody will be able to pinpoint the problem.

Anyway I find it really funny (in a scary way), that it works okay with Myfaces - JSF but not with the Mojarra implementation, as both should
implement the same standard.

Regards,

Siebert

ElGringo
Posts: 13
Joined: 22 Oct 2010, 17:49

07 Sep 2011, 17:46

Hello,

I have the same bug using PrimeFaces 3.0M3 into Netbeans 6.9.1 (JSF 2.0)

I have a simple datatable defined like this :

Code: Select all

<p:dataTable
            id="caseList"
            emptyMessage="#{text.datatable_noResult}"
            value="#{caseView.casesList}"
            var="item"
            scrollable="true"
            selectionMode="single"
            selection="#{caseView.selectedCase}"
            rowKey="#{item.objectId}">

            <p:ajax event="rowSelect" listener="#{caseView.selectCase}" update=":form:caseGrid"/>
            <p:ajax event="rowUnselect" listener="#{caseView.unselectCase}" update=":form:caseGrid"/>
And every time I select a row, it's only the previous one which is rendered into the updated panel. (The first time, the selection is null)
I noticed that unselect can't be done on the list too (the row is always highlighted).

This was working with Primefaces 2.x, only the use of <p:ajax> and rowKey attribute has changed.

Is it a bug or am I missing something ?

Thanks for your help,

User avatar
lusaxxx
Posts: 6
Joined: 05 Aug 2011, 20:22
Location: Slovakia

08 Sep 2011, 07:37

Unselect is now with cltr + LCLICK
PF 3.0.2M , Tomcat 7.0.16, MyFaces 2.1.2

ElGringo
Posts: 13
Joined: 22 Oct 2010, 17:49

08 Sep 2011, 10:08

Thx lusaxxx for your answer, ctrl + click works fine for unselect.

Still have the problem for the first selection (and first reselection after unselect)

ElGringo
Posts: 13
Joined: 22 Oct 2010, 17:49

08 Sep 2011, 11:51

Okay,

I resolved my problem using event of listener method directly.

I removed the attribute selection from my datatable and set selected object manually :

Code: Select all

public void selectCase(SelectEvent event) {
    if(event.getObject()!=null){
        selectedCase = (Case)event.getObject();
    }
    ...
}
It works doing like this.

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

08 Sep 2011, 20:25

The selection attribute is only for reading the selected value, not setting it afaik.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests