WebSphere Portal Server - Sharing configuration data between portlets.... PortletApplicationSettings?

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Portal Server > March 2004 > Sharing configuration data between portlets.... PortletApplicationSettings?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Sharing configuration data between portlets.... PortletApplicationSettings?
Lee Francis Wilhelmsen

2004-03-19, 9:37 am

Hi

I have two portlets in the same application on the same page. The first
portlet has code to save configuration settings in actionPerformed() which
works fine (see below). However, I'm having trouble getting the second
portlet to read the same configuration values. I thought
PortletApplicationSettings could be shared between portlets in the same
application?



The code basically looks like this:

First portlet:

public void actionPerformed(ActionEvent event) throws PortletException {
PortletApplicationSettings settings =
getPortletSettings().getApplicationSettings();

String var = request.getParameter("requestvariable");
settings.setAttribute("configvariable", var);
try {
settings.store();
} catch (IOException e) {
e.printStackTrace();
}
}



Both portlets:

public void doView(PortletRequest request, PortletResponse response) throws
PortletException, IOException {
PortletApplicationSettings settings =
getPortletSettings().getApplicationSettings();

String var = settings.getAttribute("configvariable");
System.out.println(var);
}



The same code executes fine when run in the doView() of the first portlet
(the same portlet that is storing the values), but not in the second
portlet. Does anyone know what may be wrong?


Also, I get the following error when storing the data to the
PorletApplicationSettings. However the data seems to be present i the
PortletApplicationSettings after storing.

java.io.IOException: com.ibm.wps.util.ConcurrentModificationException:
DSTO0030E: Database has been changed since creation of data object [ObjectID
= 2_0_5I5].


Regards
Lee Francis


Cho Kuk

2004-03-22, 5:33 am

Only when the portlet is in CONFIGURE mode, it has write access to the
PortletApplicationSettings data.


"Lee Francis Wilhelmsen" <leefw@start.no.n-o-s-p-a-m> wrote in message
news:c3egoa$6grq$1@news.boulder.ibm.com...
> Hi
>
> I have two portlets in the same application on the same page. The first
> portlet has code to save configuration settings in actionPerformed() which
> works fine (see below). However, I'm having trouble getting the second
> portlet to read the same configuration values. I thought
> PortletApplicationSettings could be shared between portlets in the same
> application?
>
>
>
> The code basically looks like this:
>
> First portlet:
>
> public void actionPerformed(ActionEvent event) throws PortletException {
> PortletApplicationSettings settings =
> getPortletSettings().getApplicationSettings();
>
> String var = request.getParameter("requestvariable");
> settings.setAttribute("configvariable", var);
> try {
> settings.store();
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
>
>
>
> Both portlets:
>
> public void doView(PortletRequest request, PortletResponse response)

throws
> PortletException, IOException {
> PortletApplicationSettings settings =
> getPortletSettings().getApplicationSettings();
>
> String var = settings.getAttribute("configvariable");
> System.out.println(var);
> }
>
>
>
> The same code executes fine when run in the doView() of the first portlet
> (the same portlet that is storing the values), but not in the second
> portlet. Does anyone know what may be wrong?
>
>
> Also, I get the following error when storing the data to the
> PorletApplicationSettings. However the data seems to be present i the
> PortletApplicationSettings after storing.
>
> java.io.IOException: com.ibm.wps.util.ConcurrentModificationException:
> DSTO0030E: Database has been changed since creation of data object

[ObjectID
> = 2_0_5I5].
>
>
> Regards
> Lee Francis
>
>



Lee Francis Wilhelmsen

2004-03-22, 7:33 am

I'm in configure mode. I don't think that's the cause of the problem.

"Cho Kuk" <kbleguy@netian.com> wrote in message
news:c3mck3$4qs2$1@news.boulder.ibm.com...
> Only when the portlet is in CONFIGURE mode, it has write access to the
> PortletApplicationSettings data.
>
>
> "Lee Francis Wilhelmsen" <leefw@start.no.n-o-s-p-a-m> wrote in message
> news:c3egoa$6grq$1@news.boulder.ibm.com...
which[color=darkred]
> throws
portlet[color=darkred]
com.ibm.wps.util. ConcurrentModificationException:[color=d
arkred]
> [ObjectID
>
>



dgc

2004-03-22, 11:34 am

Lee,
PortletApplicationSettings object can be modified only
in configure mode. Similarly PortletSettings object can
be modified in Edit mode. Here is what "IBM WebSphere Portal V5 A Guide for=
Portlet Application Development" says:
"...The context parameters defined in the concrete portlet application sect=
ion of the portlet.xml are available through
this object=92s getAttribute method. These parameters can be adjusted and n=
ew
ones added only while a portlet is in configure mode."
Cho Kuk

2004-03-22, 10:33 pm

Um..
I made a simple portlet application as you explained and tested it in my
portal
server(V5).
It works fine. Try to do with this application.
If it still doesn't works, I think you may have any other problems.

O my! can't attech a binary file. ;-(

//MyPortlet1.java
import java.io.IOException;
import org.apache.jetspeed.portlet.*;
import org.apache.jetspeed.portlet.event.*;
public class MyPortlet1 extends PortletAdapter {

public void doView(PortletRequest request, PortletResponse response) throws
PortletException, IOException {
PortletApplicationSettings settings =
getPortletSettings().getApplicationSettings();
String var = settings.getAttribute("configvariable");
response.getWriter().println(var);
}
}

//MyPortlet2.java
import java.io.IOException;
import org.apache.jetspeed.portlet.*;
import org.apache.jetspeed.portlet.event.*;
public class MyPortlet2 extends PortletAdapter implements ActionListener {

public void doView(PortletRequest request, PortletResponse response) throws
PortletException, IOException {
PortletApplicationSettings settings =
getPortletSettings().getApplicationSettings();
String var = settings.getAttribute("configvariable");
response.getWriter().println(var);
}

public void doConfigure(PortletRequest request, PortletResponse response)
throws PortletException, IOException {
PortletURI aActionURI = response.createURI();
aActionURI.addAction("aAction");
request.setAttribute("aActionURI", aActionURI.toString());
getPortletConfig().getContext().include("/jsp/Configure.jsp", request,
response);
}

public void actionPerformed(ActionEvent event) throws PortletException {
PortletApplicationSettings settings =
getPortletSettings().getApplicationSettings();
PortletRequest request = event.getRequest();
String var = request.getParameter("requestvariable");
settings.setAttribute("configvariable", var);
try {
settings.store();
} catch (IOException e) {
e.printStackTrace();
}
}
}

//Configure.jsp
<%@ page contentType="text/html"%>
<%@ taglib uri="/WEB-INF/tld/portlet.tld" prefix="portletAPI" %>
<portletAPI:init/>

<form name="<portletAPI:encodeNamespace value="_aForm"/>" method="post"
action="<%= request.getAttribute("aActionURI") %>">
<input type="text" name="requestvariable">
<input type="submit" value="Submit">
</form>

//web.xml
defines 2 servlets.

//portlet.xml
defines 2 portlets and 2 concrete portlets.


"Lee Francis Wilhelmsen" <leefw@start.no.n-o-s-p-a-m> wrote in message
news:c3mjmd$577c$1@news.boulder.ibm.com...
> I'm in configure mode. I don't think that's the cause of the problem.




Lee Francis Wilhelmsen

2004-03-23, 7:35 am

I got your code working!

And just by chance I found out what was wrong....

It seems my application's portlet.xml file was defining the portlets in two
concrete portlet applications name

so it looked like this

<concrete-portlet-app uid="search.SearchPortlet.508517110c.1">
<portlet-app-name>SearchPortlet application</portlet-app-name>
<concrete-portlet href="#search.SearchPortlet">
...
</concrete-portlet>
</concrete-portlet-app>
<concrete-portlet-app uid="show.ShowDocumentPortlet.30e9c49809.1">
<portlet-app-name>ShowDocument application</portlet-app-name>
<concrete-portlet href="#show.ShowDocumentPortlet">
...
</concrete-portlet>
</concrete-portlet-app>

when it should have looked like this:

<concrete-portlet-app uid="search.Portlets.508517110c.1">
<portlet-app-name>SearchPortlet application</portlet-app-name>
<concrete-portlet href="#search.SearchPortlet">
...
</concrete-portlet>
<concrete-portlet href="#show.ShowDocumentPortlet">
...
</concrete-portlet>
</concrete-portlet-app>

meaning that my portlets were not in the same portlet application as I
stated. They were indeed part of the same WAR file and EAR project, but not
the portlet application. I didn't know that the application name meant so
much. :-o

When I run your example I must have picked the same application name (pretty
random usually) for both portlets.

Sorry for the bother, but at least I learnt something here....

Lee Francis


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com