Foren

Liferay stores data even when the browser is closed

Ravi Polepeddi, geändert vor 12 Jahren.

Liferay stores data even when the browser is closed

New Member Beiträge: 21 Beitrittsdatum: 02.11.11 Neueste Beiträge
Hi,

There are two pages :
1 . Search Results Page.
2. View Result page.

The problem is if I click on two different results and view them both have the same data filled in.
Or, if I open the link in any other device, the results page still has the same data as seen on the first device.
Can someone suggest as to what needs to be done ?

Thanks
Ravi
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
Can you share the screenshot to let us understand it better? Also is this your custom portlet??
Ravi Polepeddi, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

New Member Beiträge: 21 Beitrittsdatum: 02.11.11 Neueste Beiträge
Hi Ravi Kumar,

Yes...I use custom portlets.

In Result1.PNG(first image), you will see two portlets. One portlet includes the Search Criteria.
Second Portlet includes the results.
Similar is the case with the third image.

In View Result1.PNG,(second image) you will see the third portlet with the dates.

The problem is- once I have view result pages open in the browser:
In this case, ViewResult1.PNG(second image) and ViewResult2.PNG(fourth image) are the two pages.
Now reloading the ViewResult1.PNG loads it with the values of ViewResult2.PNG which you can see in FinalResult.PNG.(fifth image).
I know that values are being set globally. But I do not know how to eliminate this feature.

Thanks
Ravi Kiran
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
So you know the problem.. this might help. Check in your portlet if you are setting some values with instance variables. After each view are you resetting those variables. Not sure about your code.. but one situation can be like this..

class AbcPortlet extends GenericPortlet{
String _keyword = "";
processAction(..){
String keyword = request.getParam... ;
this._keyword = keyword;
}
doview(..) //or it can be render()
{
if(_keyword.length()>0){
//do search with _keyword
}
// this you forgot to reset so the next time when render is called it searches again and shows the results
// _keyword = "";
}

}


If this helps fine.. otherwise if possible share the code so that someone here can help.. emoticon
Ravi Polepeddi, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

New Member Beiträge: 21 Beitrittsdatum: 02.11.11 Neueste Beiträge
Hi,

Thanks for the information provided.
My problem is pretty similar to that.
I did know that I have to reset the object.
But did not understand where should I do that ?

@Controller
@RequestMapping(value = "VIEW")
@SessionAttributes()
public class PropertyDetailController {
	
	/************************ Service Set Up ******************************************************************************************/
	
	private Event_Object eventObjectFinal	=	null;
	private Property propertyFinal	=	null;
	private String action	=	null;
	@Autowired
	@Qualifier("propertyService")
	private PropertyService propertyService;
	public void setSearchService(PropertyService propertyService){
		this.propertyService=propertyService;
	}
	
	/************************************* Default Home Page*************************************************************/	
	@RenderMapping
	public String showHome(RenderRequest request,ModelMap map) throws Exception{		
		List<img> images = Collections.synchronizedList(new ArrayList<img>());
		HttpServletRequest httprequest	= PortalUtil.getHttpServletRequest(request);			
		String propertyApartmentTypeId 	= PortalUtil.getOriginalServletRequest(httprequest).getParameter("propertyApartmentTypeId");		
		String referrer = PortalUtil.getOriginalServletRequest(httprequest).getParameter("referrer");	
		Event_Object eventObject=new Event_Object();	
		
		if(referrer!= null &amp;&amp; referrer.equals("search") &amp;&amp; eventObjectFinal!=null){					
				String region	=	"";				
				images = propertyService.getImages(Integer.valueOf(propertyApartmentTypeId),request);
				propertyService.setProperty(propertyFinal);
				propertyService.setEventObject(eventObjectFinal);			
				String startDate=eventObjectFinal.getStartDate();
				String endDate=eventObjectFinal.getEndDate();
				SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd");			
				try	{
					Date date1 = sdfSource.parse(startDate);
					SimpleDateFormat sdfDestination = new SimpleDateFormat("dd/MM/yyyy");
					startDate= sdfDestination.format(date1);
					Date date2 = sdfSource.parse(endDate);
					endDate = sdfDestination.format(date2);
				}
				catch(Exception e){		
				}
				eventObject.setStartDate(startDate);
				eventObject.setEndDate(endDate);
				eventObject.setNumberOfRoom(eventObjectFinal.getNumberOfRoom());
				if(eventObjectFinal.getRegion().equalsIgnoreCase("")){
					region="All Locations";
				}else{
					region=eventObjectFinal.getRegion();
				}
				eventObject.setRegion(region);				
				request.setAttribute("apartmentName", propertyFinal.getApartment().getName());
			}		
	
		else {			
			try	{
				if(propertyApartmentTypeId != "" )	{		
					eventObject	= null;
					images = propertyService.getImages(Integer.valueOf(propertyApartmentTypeId),request);
					propertyFinal = propertyService.getProperties(request,Integer.valueOf(propertyApartmentTypeId));						
					request.setAttribute("apartmentName", propertyFinal.getApartment().getName());
				}
				else	{
					eventObject	= null;
					propertyFinal =	null;
					images = null;
					//return "displayPropertyForm";
				}					
			}				
			catch(Exception e){
				eventObject	= null;
				propertyFinal =	null;
				images = null;
			//	return "displayPropertyForm";
			}		
		}
		map.addAttribute("eventObject", eventObject);
		map.addAttribute("property", propertyFinal);
		map.addAttribute("images",images);
		
		if(this.action!=null){
			if(this.action.equalsIgnoreCase("displayProperty")){	
				return "displayPropertyForm";
			}
		}else{			
			eventObject	=	null;
			map.addAttribute("eventObject", eventObject);
			return "displayPropertyForm";
		}
		return "displayPropertyForm";
	}


In the code, the eventObjectFinal variable needs to be reset.
The showHome method is invoked after clicking on one of the searchResults.
But as soon as I open another result it with different set of search parameters and refresh the first result page, it is loaded with the second set of search results.
So, can you tell me where should I reset the variable ?
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
Try this.. set eventObjectFinal = null; at the end of showHome() method.. See if that works.. Can you share the complete portlet here..
Ravi Polepeddi, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

New Member Beiträge: 21 Beitrittsdatum: 02.11.11 Neueste Beiträge
Hi,

Once the eventObjectFinal is set to null, if you refresh the page the data doesn't exist anymore right.
The StartDate and EndDate fields do not seem to be populated once the page is refreshed.


/************************************* Default Home Page*************************************************************/	
	@RenderMapping
	public String showHome(RenderRequest request,ModelMap map) throws Exception{	
		List<img> images = Collections.synchronizedList(new ArrayList<img>());
		HttpServletRequest httprequest	= PortalUtil.getHttpServletRequest(request);			
		String propertyApartmentTypeId 	= PortalUtil.getOriginalServletRequest(httprequest).getParameter("propertyApartmentTypeId");		
		String referrer = PortalUtil.getOriginalServletRequest(httprequest).getParameter("referrer");	
		Event_Object eventObject=new Event_Object();	
		
		if(referrer!= null &amp;&amp; referrer.equals("search") &amp;&amp; eventObjectFinal!=null){	
				System.out.println(eventObjectFinal + " eventObjectFinal");
				String region	=	"";
				
				images = propertyService.getImages(Integer.valueOf(propertyApartmentTypeId),request);
				propertyService.setProperty(propertyFinal);
				propertyService.setEventObject(eventObjectFinal);			
				String startDate=eventObjectFinal.getStartDate();
				String endDate=eventObjectFinal.getEndDate();
				SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd");			
				try	{
					Date date1 = sdfSource.parse(startDate);
					SimpleDateFormat sdfDestination = new SimpleDateFormat("dd/MM/yyyy");
					startDate= sdfDestination.format(date1);
					Date date2 = sdfSource.parse(endDate);
					endDate = sdfDestination.format(date2);
				}
				catch(Exception e){		
				}
				eventObject.setStartDate(startDate);
				eventObject.setEndDate(endDate);
				eventObject.setNumberOfRoom(eventObjectFinal.getNumberOfRoom());
				if(eventObjectFinal.getRegion().equalsIgnoreCase("")){
					region="All Locations";
				}else{
					region=eventObjectFinal.getRegion();
				}
				eventObject.setRegion(region);				
				request.setAttribute("apartmentName", propertyFinal.getApartment().getName());
			}		
	
		else {
			
			try	{
				/*if(propertyApartmentTypeId != "" )	{	*/	
					//eventObject	= null;
					images = propertyService.getImages(Integer.valueOf(propertyApartmentTypeId),request);
					propertyFinal = propertyService.getProperties(request,Integer.valueOf(propertyApartmentTypeId));						
					request.setAttribute("apartmentName", propertyFinal.getApartment().getName());
			/*	}
				else	{
					eventObject	= null;
					propertyFinal =	null;
					images = null;
					//return "displayPropertyForm";
				}	*/				
			}				
			catch(Exception e){
			//	eventObject	= null;
			//	propertyFinal =	null;
			//	images = null;
			//	return "displayPropertyForm";
			}		
		}
		map.addAttribute("eventObject", eventObject);
		map.addAttribute("property", propertyFinal);
		map.addAttribute("images",images);
		
		/*if(this.action!=null){
			if(this.action.equalsIgnoreCase("displayProperty")){	
				return "displayPropertyForm";
			}else{
				System.out.println("booking");
				return "booking";
			}
		}else{
			System.out.println("Else");
			eventObject	=	null;
			map.addAttribute("eventObject", eventObject);
			return "displayPropertyForm";
		}*/
		eventObjectFinal	=	null;
		propertyFinal	=	null;
		return "displayPropertyForm";
	}
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
If by making eventObjectFinal as null you cant see anything then check your logic again..
See like this..
1. By default when you view the page, it returns correctly on browser.
2. You make a search.. set some variables.. do the operation in portlet and display results in browser.
3. Now if you go to that page again it should show as it was in point 1. So the variables you did set in point 2, modify then accordingly show that it shows the default behavior.

Just think and look deep in the code.. you will get it for sure..
Ravi Polepeddi, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

New Member Beiträge: 21 Beitrittsdatum: 02.11.11 Neueste Beiträge
Hi Ravi,

All of the points you mentioned above do happen correctly.
What I did is to set the eventObjectFinal to null.
Now, when I navigate to the page (either from the previous page or open the link in the browser directly), it shows the results correctly.
The only problem is when you reload the page that the fields are not populated because I have set it to null and it is not global anymore.

The eventObjectFinal.getStartDate() etc... methods as shown in the code won't work once it is set to NULL.
So, how would I know that if the page is being refreshed or not ?
Is there a redirectURL setting that can be done in the .jsp on reload.

Thanks
Ravi
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
Check this section "Redirection in MVCPortlet" in this blog http://www.mpowerglobal.com/web/gavin/home/-/blogs/mvcportlet-of-liferay

HTH
Ravi Polepeddi, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

New Member Beiträge: 21 Beitrittsdatum: 02.11.11 Neueste Beiträge
Ravi Kumar,

Case I : Opening the link "http://localhost:8080/web/guest/apartment?referrer=search&propertyApartmentTypeId=1" directly in the browser does not show the date fields as eventObjectFinal is null. This is correct.

Case II : On the page with the link "http://localhost:8080/web/guest/results" when any result is clicked,
the page "http://localhost:8080/web/guest/apartment?referrer=search&propertyApartmentTypeId=1" is opened with the date fields populated which is as desired.

Case III: Once the page has loaded,eventObjectFinal is set to null (at the end of the method) . Refreshing the page now does not fill in the date fields anymore. How do I prevent this from occurring ?

Below is the complete code.

package com.portal.controller;

import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.portlet.Event;
import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.RenderRequest;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.portlet.bind.annotation.EventMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;

import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.util.PortalUtil;
import com.portal.domain.Event_Object;
import com.portal.domain.Property;
import com.portal.domain.Image;
import com.portal.events.PropertyDetailsEvent;
import com.portal.service.PropertyService;



/*********************** Controller ***************************************************************************************/

@Controller
@RequestMapping(value = "VIEW")
@SessionAttributes()
public class PropertyDetailController {
	
	/************************ Service Set Up ******************************************************************************************/
	
	private Event_Object eventObjectFinal;
	private Property propertyFinal;
	private String action;
	@Autowired
	@Qualifier("propertyService")
	private PropertyService propertyService;
	public void setSearchService(PropertyService propertyService){
		this.propertyService=propertyService;
	}
	
	/************************************* Default Home Page*************************************************************/	
	@RenderMapping
	public String showHome(RenderRequest request,ModelMap map) throws Exception{	
		System.out.println(action + "action");
		List<img> images = Collections.synchronizedList(new ArrayList<img>());
		HttpServletRequest httprequest	= PortalUtil.getHttpServletRequest(request);			
		String propertyApartmentTypeId 	= PortalUtil.getOriginalServletRequest(httprequest).getParameter("propertyApartmentTypeId");		
		String referrer = PortalUtil.getOriginalServletRequest(httprequest).getParameter("referrer");				
		Event_Object eventObject=new Event_Object();
		
		if(eventObjectFinal!=null){					
				System.out.println(eventObjectFinal + " eventObjectFinal");
				String region	=	"";
				//images = propertyService.getImages(propertyFinal.getPropertyApartmentTypeId(),request); Bug as mentioned in Ravi_Work doc.
				images = propertyService.getImages(Integer.valueOf(propertyApartmentTypeId),request);
				propertyService.setProperty(propertyFinal);
				propertyService.setEventObject(eventObjectFinal);				
				String startDate=eventObjectFinal.getStartDate();				
				String endDate=eventObjectFinal.getEndDate();
				SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd");			
				try	{
					Date date1 = sdfSource.parse(startDate);
					SimpleDateFormat sdfDestination = new SimpleDateFormat("dd/MM/yyyy");
					startDate= sdfDestination.format(date1);
					Date date2 = sdfSource.parse(endDate);
					endDate = sdfDestination.format(date2);
				}
				catch(Exception e){		
				}
				eventObject.setStartDate(startDate);
				eventObject.setEndDate(endDate);
				eventObject.setNumberOfRoom(eventObjectFinal.getNumberOfRoom());
				if(eventObjectFinal.getRegion().equalsIgnoreCase("")){
					region="All Locations";
				}else{
					region=eventObjectFinal.getRegion();
				}
				eventObject.setRegion(region);				
				request.setAttribute("apartmentName", propertyFinal.getApartment().getName());
				map.addAttribute("eventObject", eventObject);
				map.addAttribute("property", propertyFinal);
				map.addAttribute("images",images);
				System.out.println(request.getParameter("startDate"));
				
				request.setAttribute("region",eventObjectFinal.getRegion());
				request.setAttribute("startDate",eventObjectFinal.getStartDate());
				request.setAttribute("endDate",eventObjectFinal.getEndDate());
				request.setAttribute("rooms",eventObjectFinal.getNumberOfRoom());
//			}		
	
	/*	else {
			System.out.println("propertyApartmentTypeId " + propertyApartmentTypeId);
			try	{*/
				/*if(propertyApartmentTypeId != "" )	{	*/				
				/*	images = propertyService.getImages(Integer.valueOf(propertyApartmentTypeId),request);
					propertyFinal = propertyService.getProperties(request,Integer.valueOf(propertyApartmentTypeId));						
					request.setAttribute("apartmentName", propertyFinal.getApartment().getName());*/
			/*	}
				else	{
					eventObject	= null;
					propertyFinal =	null;
					images = null;
					//return "displayPropertyForm";
				}	*/				
			}				
		/*	catch(Exception e){
				eventObject	= null;
				propertyFinal =	null;
				images = null;
				//return "displayPropertyForm";
			}		
		}*/
		
		
		/*if(this.action!=null){
			if(this.action.equalsIgnoreCase("displayProperty")){	
				return "displayPropertyForm";
			}else{
				System.out.println("booking");
				return "booking";
			}
		}else{
			System.out.println("Else");
			eventObject	=	null;
			map.addAttribute("eventObject", eventObject);
			return "displayPropertyForm";
		}*/
	
		//eventObjectFinal	=	null;
		//propertyFinal	=	null;
		
		return "displayPropertyForm";
	}
	/************************************* Event Handler******************************************************************/	
	@EventMapping(value="{http://www.mynamespaceproperty.com}propertyDetailsEvent")
	public void receiveEvent(EventRequest request, EventResponse response,ModelMap map)
	{
		Event event = request.getEvent();
		PropertyDetailsEvent propertyDetailsEvent=(PropertyDetailsEvent)event.getValue();
		this.eventObjectFinal=(Event_Object)propertyDetailsEvent.getEvent_Object();
		this.propertyFinal=(Property)propertyDetailsEvent.getProperty();
		this.action=(String)propertyDetailsEvent.getAction();
	}
	
	
	/********************************* Resource Mapping to display images **********************************************************/
	
	
	
	@ResourceMapping
	public synchronized  void serveResource(@RequestParam String name,ResourceRequest request, ResourceResponse response)throws Exception {			
		String fileSeparator=File.separator;
		try {
			response.setContentType("image/jpg");
			String resourceID = request.getResourceID();			
			byte[] buf = new byte[9000000];
			String filePath = "";
			FileInputStream fileInputStream =null;
			if (resourceID.equals("floorPlanImage")){
				filePath = request.getPortletSession().getPortletContext().getRealPath(fileSeparator+"images"+fileSeparator+"FloorPlanImages"+fileSeparator+name+"_scaled.jpg");
				fileInputStream = new FileInputStream(new File(filePath));
			}
			/*if (resourceID.equals("floorPlanImageThumbnail")){
				filePath = request.getPortletSession().getPortletContext().getRealPath(fileSeparator+"images"+fileSeparator+"FloorPlanImages"+fileSeparator+name+"_t.jpg");
				fileInputStream = new FileInputStream(new File(filePath));
			}*/
			if(resourceID.equals("apartmentImage")){
				
				if(!(name.equalsIgnoreCase(""))){
					filePath = request.getPortletSession().getPortletContext().getRealPath(fileSeparator+"images"+fileSeparator+"ApartmentGallery"+fileSeparator +name+".jpg");
				}
				else{
					filePath = request.getPortletSession().getPortletContext().getRealPath(fileSeparator+"images"+fileSeparator+"ApartmentGallery"+fileSeparator+"default.jpg");
				}
				fileInputStream = new FileInputStream(new File(filePath));
			}
			else if(resourceID.equals("moreApartmentImageThumbnail")){
				filePath= request.getPortletSession().getPortletContext().getRealPath(fileSeparator+"images"+fileSeparator+"ApartmentGallery"+fileSeparator+name+"_t.jpg");
				fileInputStream = new FileInputStream(new File(filePath));
			}
			else if(resourceID.equals("moreApartmentImage")){				
				filePath= request.getPortletSession().getPortletContext().getRealPath(fileSeparator+"images"+fileSeparator+"ApartmentGallery"+fileSeparator +name+"_scaled.jpg");
				fileInputStream = new FileInputStream(new File(filePath));
			}
			
			int length = fileInputStream.read(buf);
			response.getPortletOutputStream().write(buf, 0, length);
			response.getPortletOutputStream().flush();
			response.getPortletOutputStream().close();
			fileInputStream.close();
						
			
		} catch (Exception exception) {
			System.out.println("Error has occured" + exception.getMessage());
		}
		
		
	}
}


Thanks,
Ravi
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
You can try storing date values just like you were doing for eventObjectFinal.. I am sorry that I am not familiar with this kind of portlet.. You are working on spring portlet, I guess.. ?? Correct me if I am wrong..
The way I provided is not a correct way for sure.. but just a workaround..
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
Check if eventObjectFinal is null then use the stored date values just to fill date fields.. otherwise get date values from eventObjectFinal as you were getting before..
Ravi Polepeddi, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

New Member Beiträge: 21 Beitrittsdatum: 02.11.11 Neueste Beiträge
Yes... I use Spring Portlet.
Even if I store the dates in local variables, once the page is reloaded, the method is invoked again and the local variables will be reset to null as eventObjectFinal is null. Isn't it ?

I'm sure many people must have encountered such a problem.
It is just that the same data is being used for all the portlets in the application because of a global variable declaration or something.
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
How eventObjectFinal was not null before.. ??
Ravi Polepeddi, geändert vor 12 Jahren.

RE: Liferay stores data even when the browser is closed

New Member Beiträge: 21 Beitrittsdatum: 02.11.11 Neueste Beiträge
eventObjectFinal was not set to null before.
When two results were opened in two separate tabs with different dates, and if the first tab was refreshed, it pulled data from eventObjectFinal which was set when second tab was opened.

Basically, the portlet in the first tab was populated with the data from the second portlet.
So, eventObjectFinal has been set to null.
And as a result, once the page has been loaded as eventObjectFinal is null, the dates are not being filled.