Missing dataTable data after navigating back

UI Components for JSF
geekosphere
Posts: 37
Joined: 27 Feb 2012, 03:44

18 Dec 2014, 16:55

PrimeFaces 5.1.6
MyFaces 2.2.6
IBM WebSphere ND 7.0.0.23, ARIESJPA 1.0.0.7
Java version = JRE 1.6.0 IBM J9 2.4
Linux amd64-64

TL;DR: view a LazyDataTable, filter the data, use a contextMenu to navigate to a different view, click the back button, the LazyDataTable loads backup showing all rows but no detail data is displayed.

I was able to reproduce this issue using the Showcase and 5.1.6. I am not sure if this is an issue with PF, JSF/MyFaces or me (the latter is very plausible if not probable.) I pulled down the code for the Lazy Data model showcase (http://www.primefaces.org/showcase/ui/d ... lazy.xhtml) from SVN (https://code.google.com/p/primefaces/so ... yView.java) and then made some changes:
* Adding debugging System.out.println statements
* Added a contextMenu for the dataTable with an action
* Added a filteredValue attribute to the dataTable
* Added an action that does a faces-redirect to a different view

The steps to reproduce the error are:
* Load the default index.xhtml page (Chrome 39.0.2171.95 m)
* filter any row by any value
* click on any row, verify that the car details are displayed
* right-click on the contextMenu and click on "View Detals"
* hellowWorld.xhtml is displayed
* hit the back button
* verify that the index.xhtml is displayed (with the LazyCarDataModel.load() being called)
* click on any row, verify that the car details are now BLANK (expected value would be the car details.)

Here is the SystemOut.log file (with my comments to add clarity)

Code: Select all

==>Load the default index.xhtml page
[12/18/14 9:28:43:812 EST] 00000057 SystemOut     O   Loading the Lazy Data Model
[12/18/14 9:28:43:814 EST] 00000057 SystemOut     O   getting selectedCar
[12/18/14 9:28:43:819 EST] 00000057 SystemOut     O   getting selectedCar
==> Filter by "a" in the Id
[12/18/14 9:29:25:542 EST] 0000005e SystemOut     O   getting filtered values
[12/18/14 9:29:25:545 EST] 0000005e SystemOut     O   setting selectedCar
[12/18/14 9:29:25:546 EST] 0000005e SystemOut     O   setting filtered values
[12/18/14 9:29:25:546 EST] 0000005e SystemOut     O   Loading the Lazy Data Model
[12/18/14 9:29:25:547 EST] 0000005e SystemOut     O   getting selectedCar
==>Click on any row to view car details (which are correctly shown)
[12/18/14 9:29:52:729 EST] 0000005b SystemOut     O   getting filtered values
[12/18/14 9:29:52:732 EST] 0000005b SystemOut     O   setting selectedCar
[12/18/14 9:29:52:733 EST] 0000005b SystemOut     O   getting selectedCar
[12/18/14 9:29:52:733 EST] 0000005b SystemOut     O   getting selectedCar
[12/18/14 9:29:52:733 EST] 0000005b SystemOut     O   getting selectedCar
[12/18/14 9:29:52:733 EST] 0000005b SystemOut     O   getting selectedCar
[12/18/14 9:29:52:733 EST] 0000005b SystemOut     O   getting selectedCar
[12/18/14 9:29:52:735 EST] 0000005b SystemOut     O   getting selectedCar
[12/18/14 9:29:52:735 EST] 0000005b SystemOut     O   getting selectedCar
[12/18/14 9:29:52:735 EST] 0000005b SystemOut     O   getting selectedCar
[12/18/14 9:29:52:736 EST] 0000005b SystemOut     O   getting selectedCar
[12/18/14 9:29:52:736 EST] 0000005b SystemOut     O   getting selectedCar
==>Right-click on any row and select View Detials
[12/18/14 9:30:34:361 EST] 0000005b SystemOut     O   getting filtered values
[12/18/14 9:30:34:361 EST] 0000005b SystemOut     O   getting selectedCar
[12/18/14 9:30:34:364 EST] 0000005b SystemOut     O   getting selectedCar
[12/18/14 9:30:34:365 EST] 0000005b SystemOut     O   setting selectedCar
[12/18/14 9:30:34:365 EST] 0000005b SystemOut     O   getting selectedCar
[12/18/14 9:30:34:366 EST] 0000005b SystemOut     O   faces-redirect
==>Click the back button
[12/18/14 9:31:08:858 EST] 0000005c SystemOut     O   Loading the Lazy Data Model
[12/18/14 9:31:08:862 EST] 0000005c SystemOut     O   getting selectedCar
[12/18/14 9:31:08:868 EST] 0000005c SystemOut     O   getting selectedCar
==>Click on any row to view details, which are BLANK
[12/18/14 9:31:23:978 EST] 00000057 SystemOut     O   getting filtered values
[12/18/14 9:31:23:980 EST] 00000057 SystemOut     O   setting selectedCar
Here is my code (ok most of it is not mine it is the showcase but you know what I mean)
index.xhtml

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:fn="http://java.sun.com/jsp/jstl/functions"
	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:pe="http://primefaces.org/ui/extensions"
	xmlns:c="http://java.sun.com/jstl/core">

<h:head>
	<title>PF_BUG_TEST_20141217</title>
</h:head>

<f:view contentType="text/html" locale="en"  >

<h:body>
	<h:form id="form">
		<p:contextMenu for="carTable" id="contextMenuId" widgetVar="contextMenuWidget">
			<p:menuitem value="View Details" update="@all" icon="ui-icon-extlink" action="#{dtLazyView.viewDetails}" />
		</p:contextMenu>
	    <p:dataTable var="car" value="#{dtLazyView.lazyModel}" paginator="true" rows="10"
	                 paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
	                 rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{dtLazyView.selectedCar}" id="carTable" lazy="true" filteredValue="#{dtLazyView.filteredValue }">
	        <p:ajax event="rowSelect" listener="#{dtLazyView.onRowSelect}" update=":form:carDetail" oncomplete="PF('carDialog').show()" />
	        <p:column headerText="Id" sortBy="#{car.id}" filterBy="#{car.id}">
	            <h:outputText value="#{car.id}" />
	        </p:column>
	        <p:column headerText="Year" sortBy="#{car.year}" filterBy="#{car.year}">
	            <h:outputText value="#{car.year}" />
	        </p:column>
	        <p:column headerText="Brand" sortBy="#{car.brand}" filterBy="#{car.brand}">
	            <h:outputText value="#{car.brand}" />
	        </p:column>
	        <p:column headerText="Color" sortBy="#{car.color}" filterBy="#{car.color}">
	            <h:outputText value="#{car.color}" />
	        </p:column>
	    </p:dataTable>
	 
	    <p:dialog header="Car Detail" widgetVar="carDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
	        <p:outputPanel id="carDetail" style="text-align:center;">
	            <p:panelGrid  columns="2" rendered="#{not empty dtLazyView.selectedCar}" columnClasses="label,value">
	                <f:facet name="header">
	                    <p:graphicImage name="demo/images/car/#{dtLazyView.selectedCar.brand}-big.gif"/> 
	                </f:facet>
	 
	                <h:outputText value="Id:" />
	                <h:outputText value="#{dtLazyView.selectedCar.id}" />
	 
	                <h:outputText value="Year" />
	                <h:outputText value="#{dtLazyView.selectedCar.year}" />
	 
	                <h:outputText value="Color:" />
	                <h:outputText value="#{dtLazyView.selectedCar.color}" style="color:#{dtLazyView.selectedCar.color}"/>
	 
	                <h:outputText value="Price:" />
	                <h:outputText value="#{dtLazyView.selectedCar.price}">
	                    <f:convertNumber type="currency" currencySymbol="$" />
	                </h:outputText>
	            </p:panelGrid>
	        </p:outputPanel>
	    </p:dialog>
	</h:form>
</h:body>
</f:view>
</html>

LazyView.java

Code: Select all

package org.primefaces.showcase.view.data.datatable;
 
import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.SelectEvent;
import org.primefaces.model.LazyDataModel;
import org.primefaces.showcase.domain.Car;
import org.primefaces.showcase.service.CarService;
 
@ManagedBean(name="dtLazyView")
@ViewScoped
public class LazyView implements Serializable {
     
    private static final long serialVersionUID = 1L;

	private LazyDataModel<Car> lazyModel;
	private LazyDataModel<Car> filteredValue;
     
    private Car selectedCar;
     
    @ManagedProperty("#{carService}")
    private CarService service;
     
    @PostConstruct
    public void init() {
        lazyModel = new LazyCarDataModel(service.createCars(200));
    }
 
    public LazyDataModel<Car> getLazyModel() {
        return lazyModel;
    }
 
    public Car getSelectedCar() {
		System.out.println("getting selectedCar");
        return selectedCar;
    }
 
    public void setSelectedCar(Car selectedCar) {
		System.out.println("setting selectedCar");
        this.selectedCar = selectedCar;
    }
     
    public void setService(CarService service) {
        this.service = service;
    }
     
    public void onRowSelect(SelectEvent event) {
        FacesMessage msg = new FacesMessage("Car Selected", ((Car) event.getObject()).getId());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    
    public String viewDetails() {
    	System.out.println("faces-redirect");
    	return "helloWorld?faces-redirect=true";
    }

	public LazyDataModel<Car> getFilteredValue() {
		System.out.println("getting filtered values");
		return filteredValue;
	}

	public void setFilteredValue(LazyDataModel<Car> filteredValue) {
		System.out.println("setting filtered values");
		this.filteredValue = filteredValue;
	}
}
The following files are used, but not modified from SVN:
LazySorter.java
LazyCarDataModel.java (ok I added a System.out.println but other then that not changed)
CarService.java
Car.java

hellowWorld.xhtml is basic XHTML file that just displays "Hello World"

and in case you want it here is the web.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	<display-name>PF_BUG_TEST_20141217</display-name>

	<context-param>
		<param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
		<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
	</context-param>
	<context-param> 
		<param-name>org.apache.myfaces.SUPPORT_JSP_AND_FACES_EL</param-name> 
		<param-value>false</param-value> 
	</context-param> 
	
	<listener>
		<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
	</listener>

	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.jsf</url-pattern>
		<url-pattern>/faces/*</url-pattern>
		<url-pattern>*.xhtml</url-pattern>
		<url-pattern>*.faces</url-pattern>
	</servlet-mapping>
	
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.xhtml</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>


My question/issue is why is the detail blank when the datatable is displayed in the browser and I can see that the load() method being called to populate the data?
Please let me know if there are any additional details that would help/assist.

Thanks in advance!!

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

18 Dec 2014, 22:43

geekosphere wrote:The steps to reproduce the error are:
* Load the default index.xhtml page (Chrome 39.0.2171.95 m)
* filter any row by any value
* click on any row, verify that the car details are displayed
* right-click on the contextMenu and click on "View Detals"
* hellowWorld.xhtml is displayed
* hit the back button
* verify that the index.xhtml is displayed (with the LazyCarDataModel.load() being called)
* click on any row, verify that the car details are now BLANK (expected value would be the car details.)
geekosphere wrote:LazyView.java

Code: Select all

@ManagedBean(name="dtLazyView")
@ViewScoped
public class LazyView implements Serializable {

...

}
searched google for

balusc jsf back button

and found

Is JSF 2.0 View Scope back-button safe? (read BalusC's answer)
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

geekosphere
Posts: 37
Joined: 27 Feb 2012, 03:44

18 Dec 2014, 23:02

In my application I make sure to use a no-cache-filter (which is where we first saw the error) which is not put on this test application, but I did put the no-cache directives in the XHTML. I will apply that no-cache-filter to this test code to make sure it is not being cached and retest.

I believe that this test app does follow the P-r-G pattern BlausC mentions and when I look at the logs after hitting the back button a new request/call to the LazyCarDataModel.load() method is fired, which to me means that the browser is indeed sending a new GET. When looking at the data displayed, it is different then in the initial request which shows that the new request generated a new call as the LazyView @ViewScopped bean creates a new random list on @PostConstruct. This is why I would think that clicking on a row now would be no different then on the initial page view.

geekosphere
Posts: 37
Joined: 27 Feb 2012, 03:44

19 Dec 2014, 23:19

While performing additional testing I have found that this issue (the missing car details) can be reproduced by using the Reload page button as well.

1. Load the page
2. click on any car to view details
3. click on reload
4. verify new cars are listed
5. click on any car, the details are now blank

now if you change that to a shift-reload then it works, what could cause this?

Firebug shows:
<partial-response><error><error-name>java.lang.NullPointerException</error-name><error-message><![CDATA[]]></error-message></error></partial-response>

geekosphere
Posts: 37
Joined: 27 Feb 2012, 03:44

23 Dec 2014, 00:03

Further debugging shows that the NPE above was due to this code:

Code: Select all

FacesMessage msg = new FacesMessage("Car Selected", ((Car) event.getObject()).getId());
this is due to the event.getObject() being null. I also see that just before this call there is a call to setSelectedCar(Car) where the car passed in is null.

So is PF not setting/sending the selected row back? I have verified that the LazyModel exists and has the 200 entries. Here is the AJAX Post when I click the row:

Code: Select all

javax.faces.partial.ajax=true&javax.faces.source=form%3AcarTable&javax.faces.partial.execute=form%3AcarTable&javax.faces.partial.render=form%3AcarDetail&javax.faces.behavior.event=rowSelect&javax.faces.partial.event=rowSelect&form%3AcarTable_instantSelectedRowKey=1c94f5fc&form%3AcarTable%3Aj_id_d%3Afilter=&form%3AcarTable%3Aj_id_f%3Afilter=&form%3AcarTable%3Aj_id_h%3Afilter=&form%3AcarTable%3Aj_id_j%3Afilter=&form%3AcarTable_selection=1c94f5fc&form_SUBMIT=1&javax.faces.ViewState=ATEq29mjWGkKR8hE2UHacTO8SD%2FgiOqxXtByQQllwqreWAo1

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

24 Dec 2014, 00:58

Can you try without the filterValue?

geekosphere
Posts: 37
Joined: 27 Feb 2012, 03:44

24 Dec 2014, 16:18

I removed both sort and filter including the filteredValue attribute and was still able to reproduce.

An interesting development is that I can reproduce the issue by simply reloading the page, I do not need to navigate to a new view, just simply reload.

Here is my updated log from running the following test:

1. Load the application to a new FF browser
2. Select a car and click to view details (this is successful)
3. Click the reload button
4. Select a car and click to view details (this is still not working)

Code: Select all

[12/24/14 9:04:59:981 EST] 00000060 webapp        I com.ibm.ws.webcontainer.webapp.WebGroupImpl WebGroup SRVE0169I: Loading Web Module: PF_BUG_TEST_20141217.
[12/24/14 9:05:00:005 EST] 00000060 WASSessionCor I SessionContextRegistry getSessionContext SESN0176I: Will create a new session context for application key default_host/PF_BUG_TEST_20141217
[12/24/14 9:05:00:039 EST] 00000060 DefaultFacesC I   Reading standard config META-INF/standard-faces-config.xml
[12/24/14 9:05:00:143 EST] 00000060 DefaultFacesC I   Reading config /WEB-INF/faces-config.xml
[12/24/14 9:05:01:364 EST] 00000060 DefaultFacesC I   Reading config : wsjar:file:/opt/ibm/BPM/v7.5/optionalLibraries/PrimeFaces/extensions/1.2.1/primefaces-extensions-1.2.1.jar!/META-INF/faces-config.xml
[12/24/14 9:05:01:370 EST] 00000060 DefaultFacesC I   Reading config : wsjar:file:/opt/ibm/BPM/v7.5/optionalLibraries/PrimeFaces/5.1.6/primefaces-5.1.6.jar!/META-INF/faces-config.xml
[12/24/14 9:05:01:742 EST] 00000060 LogMetaInfUti I   Artifact 'myfaces-bundle' was found in version '2.2.6' from path 'file:/opt/ibm/BPM/v7.5/optionalLibraries/MyFaces/2.2.6/lib/myfaces-bundle-2.2.6.jar'
[12/24/14 9:05:01:746 EST] 00000060 DefaultInject I   Using InjectionProvider org.apache.myfaces.spi.impl.AllAnnotationInjectionProvider
[12/24/14 9:05:01:929 EST] 00000060 FacesConfigur I   Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory
[12/24/14 9:05:01:935 EST] 00000060 PostConstruct I   Running on PrimeFaces 5.1.6
[12/24/14 9:05:01:937 EST] 00000060 PostConstruct I   Running on PrimeFaces Extensions 1.2.1
[12/24/14 9:05:01:938 EST] 00000060 AbstractFaces I   ServletContext initialized.
[12/24/14 9:05:01:938 EST] 00000060 AbstractFaces W

*******************************************************************
*** WARNING: Apache MyFaces-2 is running in DEVELOPMENT mode.   ***
***                                         ^^^^^^^^^^^         ***
*** Do NOT deploy to your live server(s) without changing this. ***
*** See Application#getProjectStage() for more information.     ***
*******************************************************************

[12/24/14 9:05:01:954 EST] 00000060 servlet       I com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0242I: [PF_BUG_TEST] [/PF_BUG_TEST_20141217] [Faces Servlet]: Initialization successful.
[12/24/14 9:05:01:956 EST] 00000060 webcontainer  I com.ibm.ws.wswebcontainer.VirtualHost addWebApplication SRVE0250I: Web Module PF_BUG_TEST_20141217 has been bound to default_host[*:9080,*:80,*:9443,*:5060,*:5061,*:443].
[12/24/14 9:05:01:965 EST] 00000060 ApplicationMg A   WSVR0221I: Application started: PF_BUG_TEST
[12/24/14 9:05:01:969 EST] 00000060 CompositionUn A   WSVR0191I: Composition unit WebSphere:cuname=PF_BUG_TEST in BLA WebSphere:blaname=PF_BUG_TEST started.
[12/24/14 9:05:02:017 EST] 00000060 AppBinaryProc I   ADMA7021I: Distribution of application PF_BUG_TEST completed successfully.
[12/24/14 9:05:02:064 EST] 00000060 FileRepositor A   ADMR0015I: User defaultWIMFileBasedRealm/admin created document cells/testvm14Node01Cell/applications/PF_BUG_TEST.ear/deltas/PF_BUG_TEST/delta-1419429897376.
[12/24/14 9:05:02:065 EST] 00000060 FileRepositor A   ADMR0016I: User defaultWIMFileBasedRealm/admin modified document cells/testvm14Node01Cell/applications/PF_BUG_TEST.ear/deployments/PF_BUG_TEST/META-INF/ibm-application-runtime.props.
[12/24/14 9:05:02:066 EST] 00000060 FileRepositor A   ADMR0016I: User defaultWIMFileBasedRealm/admin modified document cells/testvm14Node01Cell/applications/PF_BUG_TEST.ear/deployments/PF_BUG_TEST/deployment.xml.
[12/24/14 9:05:02:068 EST] 00000060 FileRepositor A   ADMR0016I: User defaultWIMFileBasedRealm/admin modified document cells/testvm14Node01Cell/applications/PF_BUG_TEST.ear/PF_BUG_TEST.ear.
[12/24/14 9:05:02:070 EST] 00000060 FileRepositor A   ADMR0016I: User defaultWIMFileBasedRealm/admin modified document cells/testvm14Node01Cell/cell-core.xml.


1. LOAD APPLICATION:
[12/24/14 9:05:21:888 EST] 00000065 SystemOut     O   setting CarService Bean
[12/24/14 9:05:21:888 EST] 00000065 SystemOut     O   false
[12/24/14 9:05:21:891 EST] 00000065 SystemOut     O   LazyView @PostConstruct!!!!!!!!!!!!!!!!!!!S
[12/24/14 9:05:21:895 EST] 00000065 SystemOut     O   getting selectedCar[null]
[12/24/14 9:05:21:897 EST] 00000065 SystemOut     O   getting selectedCar[null]
[12/24/14 9:05:21:910 EST] 00000065 SystemOut     O   Loading the Lazy Data Model
[12/24/14 9:05:21:920 EST] 00000065 SystemOut     O   getting selectedCar[null]
[12/24/14 9:05:21:953 EST] 00000065 SystemOut     O   getting selectedCar[null]
[12/24/14 9:05:21:954 EST] 00000065 webapp        I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [PF_BUG_TEST#PF_BUG_TEST_20141217.war]:.No state saving method defined, assuming default server state saving


2. SELECT CAR #1
[12/24/14 9:05:33:033 EST] 00000065 SystemOut     O   setting selectedCar[d7e9bae0]
[12/24/14 9:05:33:033 EST] 00000065 SystemOut     O   size of list: 200
[12/24/14 9:05:33:033 EST] 00000065 AjaxBehaviorL 1   Try to invoke listener: #{dtLazyView.onRowSelect}
[12/24/14 9:05:33:034 EST] 00000065 AjaxBehaviorL 1   Try to invoke listenerWithArg: #{dtLazyView.onRowSelect}
[12/24/14 9:05:33:034 EST] 00000065 AjaxBehaviorL 1   Try to invoke customListener: #{dtLazyView.onRowSelect}
[12/24/14 9:05:33:034 EST] 00000065 SystemOut     O   onRowSelect clicked [d7e9bae0
[12/24/14 9:05:33:039 EST] 00000065 SystemOut     O   getting selectedCar[org.primefaces.showcase.domain.Car@a116fb0e]
[12/24/14 9:05:33:039 EST] 00000065 SystemOut     O   getting selectedCar[org.primefaces.showcase.domain.Car@a116fb0e]
[12/24/14 9:05:33:039 EST] 00000065 SystemOut     O   getting selectedCar[org.primefaces.showcase.domain.Car@a116fb0e]
[12/24/14 9:05:33:040 EST] 00000065 SystemOut     O   getting selectedCar[org.primefaces.showcase.domain.Car@a116fb0e]
[12/24/14 9:05:33:040 EST] 00000065 SystemOut     O   getting selectedCar[org.primefaces.showcase.domain.Car@a116fb0e]
[12/24/14 9:05:33:046 EST] 00000065 SystemOut     O   getting selectedCar[org.primefaces.showcase.domain.Car@a116fb0e]
[12/24/14 9:05:33:052 EST] 00000065 SystemOut     O   getting selectedCar[org.primefaces.showcase.domain.Car@a116fb0e]
[12/24/14 9:05:33:053 EST] 00000065 SystemOut     O   getting selectedCar[org.primefaces.showcase.domain.Car@a116fb0e]
[12/24/14 9:05:33:053 EST] 00000065 SystemOut     O   getting selectedCar[org.primefaces.showcase.domain.Car@a116fb0e]
[12/24/14 9:05:33:055 EST] 00000065 SystemOut     O   getting selectedCar[org.primefaces.showcase.domain.Car@a116fb0e]


3. RELOAD PAGE:
[12/24/14 9:05:42:600 EST] 00000065 SystemOut     O   setting CarService Bean
[12/24/14 9:05:42:600 EST] 00000065 SystemOut     O   false
[12/24/14 9:05:42:602 EST] 00000065 SystemOut     O   LazyView @PostConstruct!!!!!!!!!!!!!!!!!!!S
[12/24/14 9:05:42:604 EST] 00000065 SystemOut     O   getting selectedCar[null]
[12/24/14 9:05:42:605 EST] 00000065 SystemOut     O   getting selectedCar[null]
[12/24/14 9:05:42:610 EST] 00000065 SystemOut     O   Loading the Lazy Data Model
[12/24/14 9:05:42:616 EST] 00000065 SystemOut     O   getting selectedCar[null]
[12/24/14 9:05:42:636 EST] 00000065 SystemOut     O   getting selectedCar[null]


4. SELECT CAR #2
[12/24/14 9:05:53:620 EST] 00000063 SystemOut     O   setting selectedCar TO NULL
[12/24/14 9:05:53:620 EST] 00000063 SystemOut     O   size of list: 200
[12/24/14 9:05:53:621 EST] 00000063 AjaxBehaviorL 1   Try to invoke listener: #{dtLazyView.onRowSelect}
[12/24/14 9:05:53:621 EST] 00000063 AjaxBehaviorL 1   Try to invoke listenerWithArg: #{dtLazyView.onRowSelect}
[12/24/14 9:05:53:621 EST] 00000063 AjaxBehaviorL 1   Try to invoke customListener: #{dtLazyView.onRowSelect}
[12/24/14 9:05:53:621 EST] 00000063 SystemErr     R   event is null: org.primefaces.event.SelectEvent[source=org.primefaces.component.datatable.DataTable@6efb6efb]
[12/24/14 9:05:53:624 EST] 00000063 SystemOut     O   getting selectedCar[null]


Here is my updated/annotated ListView.java

Code: Select all

package org.primefaces.showcase.view.data.datatable;
 
import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.SelectEvent;
import org.primefaces.model.LazyDataModel;
import org.primefaces.showcase.domain.Car;
import org.primefaces.showcase.service.CarService;
 
@ManagedBean(name="dtLazyView")
@ViewScoped
public class LazyView implements Serializable {
     
    private static final long serialVersionUID = 1L;

   private LazyDataModel<Car> lazyModel;
     
    private Car selectedCar;
     
    @ManagedProperty("#{carService}")
    private CarService service;
     
    @PostConstruct
    public void init() {
        lazyModel = new LazyCarDataModel(service.createCars(200));
        System.out.println("LazyView @PostConstruct!!!!!!!!!!!!!!!!!!!S");
    }
 
    public LazyDataModel<Car> getLazyModel() {
        return lazyModel;
    }
 
    public Car getSelectedCar() {
		System.out.println("getting selectedCar[" + selectedCar + "]");
        return selectedCar;
    }
 
    public void setSelectedCar(Car selectedCar) {
    	if(selectedCar != null){
    		System.out.println("setting selectedCar[" + selectedCar.getId() + "]");    		
    	}
    	else{
    		System.out.println("setting selectedCar TO NULL");    		
    	}
		System.out.println("size of list: " + lazyModel.getRowCount() );
        this.selectedCar = selectedCar;
    }
     
    public void setService(CarService service) {
    	System.out.println("setting CarService Bean");
    	System.out.println("lazyModel null? " + lazyModel == null);
        this.service = service;
    }
     
    public void onRowSelect(SelectEvent event) {
    	FacesMessage msg = null;
    	if(event.getObject() != null){
    		System.out.println("onRowSelect clicked [" + ((Car)event.getObject()).getId());
    		msg = new FacesMessage("Car Selected", ((Car) event.getObject()).getId());
    	}
    	else{
    		msg = new FacesMessage("Car Selected IS NULL");
    		System.err.println("event is null: " + event.toString());
    	}
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    
    public String viewDetails() {
    	System.out.println("faces-redirect");
    	return "helloWorld?faces-redirect=true";
    }

}

Here is the updated index.xhtml

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:fn="http://java.sun.com/jsp/jstl/functions"
	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:pe="http://primefaces.org/ui/extensions"
	xmlns:c="http://java.sun.com/jstl/core">

<h:head>
	<title>PF_BUG_TEST_20141217</title>
</h:head>

<f:view contentType="text/html" locale="en"  >

<h:body>
	<p:growl id="growl" autoUpdate="true" life="800" />
	<ui:debug hotkey="x" rendered="#{facesContext.application.projectStage == 'Development'}" />
	<h:form id="form">
	    <p:dataTable var="car" value="#{dtLazyView.lazyModel}" paginator="true" rows="10"
	                 paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
	                 rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{dtLazyView.selectedCar}" id="carTable" lazy="true" >
	        <p:ajax event="rowSelect" listener="#{dtLazyView.onRowSelect}" update=":form:carDetail" oncomplete="PF('carDialog').show()"  />
	        <p:column headerText="Id" >
	            <h:outputText value="#{car.id}" />
	        </p:column>
	        <p:column headerText="Year" >
	            <h:outputText value="#{car.year}" />
	        </p:column>
	        <p:column headerText="Brand" >
	            <h:outputText value="#{car.brand}" />
	        </p:column>
	        <p:column headerText="Color" >
	            <h:outputText value="#{car.color}" />
	        </p:column>
	    </p:dataTable>
	 
	    <p:dialog header="Car Detail" widgetVar="carDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
	        <p:outputPanel id="carDetail" style="text-align:center;">
	            <p:panelGrid  columns="2" rendered="#{not empty dtLazyView.selectedCar}" columnClasses="label,value">
	                <f:facet name="header">
	                    <p:graphicImage name="demo/images/car/#{dtLazyView.selectedCar.brand}-big.gif"/> 
	                </f:facet>
	 
	                <h:outputText value="Id:" />
	                <h:outputText value="#{dtLazyView.selectedCar.id}" />
	 
	                <h:outputText value="Year" />
	                <h:outputText value="#{dtLazyView.selectedCar.year}" />
	 
	                <h:outputText value="Color:" />
	                <h:outputText value="#{dtLazyView.selectedCar.color}" style="color:#{dtLazyView.selectedCar.color}"/>
	 
	                <h:outputText value="Price:" />
	                <h:outputText value="#{dtLazyView.selectedCar.price}">
	                    <f:convertNumber type="currency" currencySymbol="$" />
	                </h:outputText>
	            </p:panelGrid>
	        </p:outputPanel>
	    </p:dialog>
	</h:form>
</h:body>
</f:view>
</html>

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

30 Dec 2014, 18:24

I personally never set anything in the setter when using ajax and the rowselect event. I set it in the actionlistener because I've seen strange behaviour in the past.

Can you also check if the client sends a selection to the server? And also check if the key tgat is send,still is in your lazy model

geekosphere
Posts: 37
Joined: 27 Feb 2012, 03:44

30 Dec 2014, 19:11

Yes, in FireBug I can see the client sending the correct carId in the ajax partial request.

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

30 Dec 2014, 21:34

And is that carId still in the model at that moment? If not, PF does not set it as a safety measure, so users cannot mess with it in the html source

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 29 guests