aspose file tools*
The moose likes Portals and Portlets and the fly likes How to clear portlet cache? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "How to clear portlet cache?" Watch "How to clear portlet cache?" New topic
Author

How to clear portlet cache?

Vadim Vararu
Ranch Hand

Joined: Jan 03, 2009
Posts: 147
I load portlets with a menu. When i push on a menu item one portlet loads. When i push on other menu item, other portlet loads.

The problem is the next one:
I load a portlet and navigate through it, so i load diferent pages inside that portlet. When i push on the menu (the same item) the portlet keeps in cache last url loaded, but i need the initial page. How is it possible to implement that?


If you think you've done too much, usually it means you've done too few.
jayabharatha reddy sadanagiri
Greenhorn

Joined: Feb 04, 2010
Posts: 10
Even I have facing the same problem.
In my jboss portal I have different Tabs like Home,Reports and apps. I clicked on Home tab first, all the portlets in Home tab got loaded and did some operations in all the portlets. So resultant portlets displayed in the Home page. After that I moved to reports tab and did some operations on all the report portlets. So resultant portlets displayed in the Reports page. I navigated between all the tabs but the last resultant portlets are still getting displayed.
So my question is: Is there any configuaration like Expiration-Cache tag to display the default pages when the tab is clicked?
jayabharatha reddy sadanagiri
Greenhorn

Joined: Feb 04, 2010
Posts: 10
bharath sadanagiri wrote:Even I am facing the same problem.
In my jboss portal I have different Tabs like Home,Reports and apps. I clicked on Home tab first, all the portlets in Home tab got loaded and did some operations in all the portlets. So resultant portlets displayed in the Home page. After that I moved to reports tab and did some operations on all the report portlets. So resultant portlets displayed in the Reports page. I navigated between all the tabs but the last resultant portlets are still getting displayed.
So my question is: Is there any configuaration like Expiration-Cache tag to display the default pages when the tab is clicked?
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

What do you have expiration-cache set to now?

in each portlet.xml should make them show initial state
jayabharatha reddy sadanagiri
Greenhorn

Joined: Feb 04, 2010
Posts: 10
Already, for all the portlets it is mentioned like
<expiration-cache>0</expiration-cache>

but still no use
jayabharatha reddy sadanagiri
Greenhorn

Joined: Feb 04, 2010
Posts: 10
Hi,
I got the answer from the following site.

Once ActionResponse.setRenderParameter () is called, parameter will be available between all sub sequent requests.
http://portals.apache.org/pluto/portlet-1.0-apidocs/javax/portlet/ActionResponse.html

This link https://www.ibm.com/developerworks/mydeveloperworks/blogs/Joey_Bernal/entry/refreshing_a_portlet_on_the?lang=en
provides a solution. It says instead of setting parameters in renderRequest object in processAction (), set it in session, once used in JSP, remove from session. In this way, you can solve this problem. Move all parameters to session and remove it as soon as you have used in page.

In my case, I moved the navagation key like actionCommand to session and removed in the doView method itself. Please find the piece of code.
in doView() method
============
PortletSession ps = req.getPortletSession();
String actionCommand= (String)ps.getAttribute("actionCommand");
if( ( actionCommand!=null && actionCommand.length()>0 )&& actionCommand.equals("displayCompanyUserReport")){
LOG.debug("Forwarding the request to DisplayCompanyUserReport.jsp for the default functionality");
prd = getPortletContext().getRequestDispatcher("/view/DisplayCompanyUserReport.jsp");
ps.removeAttribute("actionCommand");
LOG.debug("Removed actionCommand from the session");
}
in processAction() method
=================
String actionCommand= req.getParameter("actionCommand");
if( ( actionCommand!=null && actionCommand.length()>0 )&& actionCommand.equals("displayCompanyUserReport")){
res.setRenderParameter("companyId", req.getParameter("companyId"));
res.setRenderParameter("actionCommand", "dummy");
session.setAttribute("actionCommand", "displayCompanyUserReport");
}

Regards,
Jayabharath
Fabio Bernardo
Greenhorn

Joined: Sep 02, 2011
Posts: 5
bharath sadanagiri wrote:Hi,
I got the answer from the following site.

Once ActionResponse.setRenderParameter () is called, parameter will be available between all sub sequent requests.
http://portals.apache.org/pluto/portlet-1.0-apidocs/javax/portlet/ActionResponse.html

This link https://www.ibm.com/developerworks/mydeveloperworks/blogs/Joey_Bernal/entry/refreshing_a_portlet_on_the?lang=en
provides a solution. It says instead of setting parameters in renderRequest object in processAction (), set it in session, once used in JSP, remove from session. In this way, you can solve this problem. Move all parameters to session and remove it as soon as you have used in page.

In my case, I moved the navagation key like actionCommand to session and removed in the doView method itself. Please find the piece of code.
in doView() method
============
PortletSession ps = req.getPortletSession();
String actionCommand= (String)ps.getAttribute("actionCommand");
if( ( actionCommand!=null && actionCommand.length()>0 )&& actionCommand.equals("displayCompanyUserReport")){
LOG.debug("Forwarding the request to DisplayCompanyUserReport.jsp for the default functionality");
prd = getPortletContext().getRequestDispatcher("/view/DisplayCompanyUserReport.jsp");
ps.removeAttribute("actionCommand");
LOG.debug("Removed actionCommand from the session");
}
in processAction() method
=================
String actionCommand= req.getParameter("actionCommand");
if( ( actionCommand!=null && actionCommand.length()>0 )&& actionCommand.equals("displayCompanyUserReport")){
res.setRenderParameter("companyId", req.getParameter("companyId"));
res.setRenderParameter("actionCommand", "dummy");
session.setAttribute("actionCommand", "displayCompanyUserReport");
}

Regards,
Jayabharath


I have the same problem, I tried your solution but is not working.

I have some tabs into the portal page (manage.jspx) and for each tab I have a portlet (every portlet has some pages). When I change the tab I want to show the first portlet page for each portlet, but it shows the last page visited.

How can I fix this problem?

Thanks in advance.
jayabharatha reddy sadanagiri
Greenhorn

Joined: Feb 04, 2010
Posts: 10
Do like the following in the PortletAction class
Fabio Bernardo
Greenhorn

Joined: Sep 02, 2011
Posts: 5
bharath sadanagiri wrote:Do like the following in the PortletAction class


It seems like the removeAttribute is not working.

This is my processAction method:

PortletSession portletSession = request.getPortletSession();

String nextPage = request.getParameter("nextPageParam");
portletSession.setAttribute("nextPage", nextPage);

//For doView to get this parameter
try {
if (nextPage != null && nextPage.equals("second")) {
String codicericarica = request.getParameter("codicericarica");
//Store in Session
portletSession.setAttribute("codicericarica", codicericarica);
} else if (nextPage != null && nextPage.equals("third")) {
String smartcard = request.getParameter("smartcard");
//Store in Session
portletSession.setAttribute("smartcard", smartcard);
} else if(nextPage != null && nextPage.equals("stampa")){
}
} catch (Exception e) {
portletSession.setAttribute("error", "Y");
}


and this is my doView method:

response.setContentType("text/html");
PortletSession portletSession = request.getPortletSession();

String nextPage = (String)portletSession.getAttribute("nextPage");
//To conditionally display the view and modify pages.
PortletRequestDispatcher dispatcher = null;
String error = (String)portletSession.getAttribute("error");
if (error != null && error.equals("Y")) {
dispatcher = getPortletContext().getRequestDispatcher("/Attiva_Ricarica_Portlet/html/viewError.jsp");
portletSession.removeAttribute("error");
} else {
if ((nextPage != null && nextPage.equals("second"))) {
String codicericarica = (String)portletSession.getAttribute("codicericarica");
request.setAttribute("codicericarica", codicericarica);
dispatcher = getPortletContext().getRequestDispatcher("/Attiva_Ricarica_Portlet/html/viewSmartCard.jsp");
portletSession.removeAttribute("nextPage");
} else if ((nextPage != null && nextPage.equals("third")) || (nextPage!=null && nextPage.equals("stampa"))) {
String codicericarica = (String)portletSession.getAttribute("codicericarica");
String smartcard = (String)portletSession.getAttribute("smartcard");
//It is not possible to retrieve Portletsession in jsp, so set the values in request attribute
request.setAttribute("codicericarica", codicericarica);
request.setAttribute("smartcard", smartcard);
portletSession.setAttribute("firstpage", "Y");
dispatcher = getPortletContext().getRequestDispatcher("/Attiva_Ricarica_Portlet/html/viewConferma.jsp");
portletSession.removeAttribute("nextPage");
} else if ((nextPage == null)){
dispatcher =
getPortletContext().getRequestDispatcher("/Attiva_Ricarica_Portlet/html/view.jsp");
}
}
dispatcher.include(request, response);
}
jayabharatha reddy sadanagiri
Greenhorn

Joined: Feb 04, 2010
Posts: 10
If removeAttribute is not working then over write the attribute value to any dummy/NULL value.



in doView method, change the default view page condition like the following

Fabio Bernardo
Greenhorn

Joined: Sep 02, 2011
Posts: 5
bharath sadanagiri wrote:If removeAttribute is not working then over write the attribute value to any dummy/NULL value.



in doView method, change the default view page condition like the following



Yeah, but the navigation should be:

I'm in Tab1: page1->click->page2->click->final page ... into this page i have a print button and the portlet should show this page if i click, as many times as I want, on the button. Then I change tab going to tab2

When I come back to tab1 the portlet should show the first page.

How can I do this?
jayabharatha reddy sadanagiri
Greenhorn

Joined: Feb 04, 2010
Posts: 10
Navigation process is same for every thing. To PRINT web page data, you can use the following javascript fuction in JSP



following is the CSS method
@media print {
body {visibility:hidden;}
.print { visibility:visible;
}
}
Fabio Bernardo
Greenhorn

Joined: Sep 02, 2011
Posts: 5
bharath sadanagiri wrote:Navigation process is same for every thing. To PRINT web page data, you can use the following javascript fuction in JSP



following is the CSS method
@media print {
body {visibility:hidden;}
.print { visibility:visible;
}
}


Thanks for the code but my problem isn't to print something...the problem is how can I refresh the portlet and showing the first page when I click on the different tabs and than come back?
(the tabs are into the portal jspx page not into the portlet page)
Fabio Bernardo
Greenhorn

Joined: Sep 02, 2011
Posts: 5
???
 
wood burning stoves
 
subject: How to clear portlet cache?