-
1. Re: 2 identical portlets in the same page
tinico Mar 22, 2007 7:32 AM (in response to portal_man)With the management portlet of the admin page, I've create a new window with the weatherportlet (new instance).
And, in the news page, I'v add this window...
It work, I've two différents city !!! I'm on the 2.4. -
2. Re: 2 identical portlets in the same page
portal_man Mar 22, 2007 9:16 AM (in response to portal_man)I've try differents portlets in differents portals.
JBoss Portal works (as the JSR168 said) like every other portlets.
All the variables are shared between the instance of the portlets.
And I don't understand how the weather works.
I'll continue my investigation on this way.
Thank's. -
3. Re: 2 identical portlets in the same page
portal_man Mar 22, 2007 9:37 AM (in response to portal_man)Here, you got the code of the processAction of the weather portlet.
public void processAction(ActionRequest request, ActionResponse response) throws PortletException { String newZip = request.getParameter("newzip"); if(null != newZip) { PortletPreferences prefs = request.getPreferences(); try { prefs.setValue("RssXml", RSS_URL_PREFIX + newZip); prefs.store(); } catch(Exception e) { e.printStackTrace(); } } response.setRenderParameter("newzip", RSS_URL_PREFIX + newZip); response.setPortletMode(PortletMode.VIEW); }
Here, you got the code of the processAction of my portlet.public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException, UnavailableException { PortletMode portletmode = request.getPortletMode(); if(PortletMode.EDIT.equals(portletmode)) { // récupération du nombre sélectionné dans la listbox // mise en session, pour l'édition // mise en variable locale pour l'affichage String tempNamespace = request.getParameter("namespace"); if (tempNamespace.equals(namespace)) { nbFlux = request.getParameter("nbFlux"); request.getPortletSession().setAttribute(namespace+"nbFlux",nbFlux); if (request.getParameter("details") == null) { details = "false"; request.getPortletSession().setAttribute(namespace+"details","false"); } else { details = "true"; request.getPortletSession().setAttribute(namespace+"details","true"); } response.setPortletMode(PortletMode.VIEW); } } }
The purpose of nbFlux is to fix the numbers of lines we take in the rss feeds. The problem is, when we got two instance of the portlet, setting this nbFlux in one portlet set the variables in the two.
That the reason of the use of namespace (to knew in which portlet we are). But, because of ActionResponse can give access to the value of the namespace we are obliged to use a global variable.
The problem is this variable is share between the two portlets. Its value is given by the last portlet which accessed it.
There is no solution.
(I can easily show two different xml feeds, but it's impossible to show the first one with 12 lines and the second with 9). -
4. Re: 2 identical portlets in the same page
peterj Mar 22, 2007 12:07 PM (in response to portal_man)You should not be storing any data in fields in the portlet class (instances of that class are created as needed, and possibly pooled, by the portlet container), you should be storing the data you are gathering into the preferences instead. Your doView method can then access the data from the preferences. Preferences have the added benefit that they are persistent so if the portal is restarted they are still there.
-
5. Re: 2 identical portlets in the same page
claprun Mar 23, 2007 8:19 AM (in response to portal_man)PeterJ is correct. portal_man, maybe reading the JSR-168 specification would be benefitial...
-
6. Re: 2 identical portlets in the same page
arkhilis Mar 26, 2007 7:45 AM (in response to portal_man)Hi,
I am also facing the problem of displaying two different RSS feeds with same portlet on same page
i have used
following code in my processAction()
request.getPortletSession(false).setAttribute("count", new Integer(NumberofItems));
this.objRssParser = new RssParser();
this.objRssParser.parseRSS(new URL(RssURL), NumberofItems);
request.getPortletSession(false).setAttribute("result", this.objRssParser);
and try to access count & result variable from view.jsp as
Number of Items : <%=request.getSession(false).getAttribute("count")%>
.
.
.
<%
RssParser objRssParser = (RssParser) request.getSession(false).getAttribute("result");
%>
is the correct way, i am using JBoss 2.6