ah, and i've forgot to mention that in the meantime i've written a little class
to emulate the PortletPreferences stuff;
with the help of a littlte wrapper (that check if PortletServlet.
isPortletRequest (request) ) i use the real preferences or the "emuleted" one
so my still remain compatible whenever i0m in a portlet or in a web
application;
attached you can find the class that i'm using to simulate the preferences.
----- Original Message -----
From: "Carlo Cavallieri" <[EMAIL PROTECTED]>
To: [email protected]
Sent: Monday, June 9, 2008 7:52:32 AM GMT +01:00 Amsterdam / Berlin / Bern /
Rome / Stockholm / Vienna
Subject: Re: PortletPreferences
ok, thanks
----- Original Message -----
From: "Ate Douma" <[EMAIL PROTECTED]>
To: [email protected]
Sent: Sunday, June 8, 2008 1:43:59 AM GMT +01:00 Amsterdam / Berlin / Bern /
Rome / Stockholm / Vienna
Subject: Re: PortletPreferences
Carlo Cavallieri wrote:
>
> Hi all,
>
>
>
> how can i access the PortletPreferences from an action with the bridge?
I guess you're talking about the Struts Bridge?
For the Struts Bridge, it currently provides only "transparent" Struts
features, meaning those that will work both
inside a standard web container and a portlet container.
Portlet specific features are easily accessible but will require to make use of
the portlet api itself as described in
Chapter PLT.16 of the Portlet API specification, see:
http://www.jcp.org/en/jsr/detail?id=168
Within an Struts Action, you can retrieve the PortletRequest as request
attribute with name: "javax.portlet.request"
And once you have the PortletRequest your can simple invoke
PortletRequest.getPreferences().
>
> Is there a standard way or an alternative solution to have something similar
> to the PortletPreferences?
Well, having a similar/parallel feature available (for Struts) in a standard
web container would be very interesting,
something I've been thinking of myself before providing (and thereby having a
transparent solution for the Struts
Bridge), but never found time (nor actual demand) doing so.
FYI: the same "issue" is coming up for the Wicket framework for which I wrote
the Portlet support as well.
Chances are, we'll add something like the PortletPreferences for Wicket soon,
and maybe that'll be transferable to the
Struts Bridge too. But so far nothing has been written yet so time will tell...
Regards,
Ate
>
>
>
> thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
package it.netsphere.struts.util;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.portlet.PortletPreferences;
import javax.portlet.ReadOnlyException;
import javax.portlet.ValidatorException;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
public class PortletPreferencesStrutsImpl implements PortletPreferences {
private PropertiesConfiguration configuration = null;
public PortletPreferencesStrutsImpl() throws ConfigurationException {
configuration = new
PropertiesConfiguration("struts-portlet-preferences.properties");
configuration.setReloadingStrategy(new
FileChangedReloadingStrategy());
}
@SuppressWarnings("unchecked")
public Map getMap() {
return null;
}
@SuppressWarnings("unchecked")
public Enumeration getNames() {
List names = new ArrayList<Object>();
for (Iterator iterator = configuration.getKeys();
iterator.hasNext();) {
names.add(iterator.next());
}
return Collections.enumeration(names);
}
public String getValue(String key, String defaulIfNotFound) {
String value;
value = configuration.getString(key);
if(value == null) value = defaulIfNotFound;
return value;
}
public String[] getValues(String key, String[] defaulIfNotFound) {
String[] values;
values = configuration.getStringArray(key);
if(values == null) values = defaulIfNotFound;
return values;
}
public boolean isReadOnly(String arg0) {
// TODO non implementato
return false;
}
public void reset(String key) throws ReadOnlyException {
configuration.clearProperty(key);
}
public void setValue(String key, String value) throws ReadOnlyException
{
configuration.setProperty(key, value);
}
public void setValues(String key, String[] values) throws
ReadOnlyException {
configuration.clearProperty(key);
if(values != null){
for (int i = 0; i < values.length; i++) {
configuration.addProperty(key, values[i]);
}
}
}
public void store() throws IOException, ValidatorException {
try {
configuration.save();
} catch (ConfigurationException e) {
e.printStackTrace();
throw new IOException(e.getMessage());
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]