DispatchedHttpServletRequest and related jstl fmt problem
l.forni Feb 7, 2006 6:25 PMHi all,
I found this topics:
1) http://www.jboss.com/index.html?module=bb&op=viewtopic&t=76350 (previous post of mine)
2) http://www.jboss.com/index.html?module=bb&op=viewtopic&t=70971
Finally i found where is the problem...
The following methods of org.jboss.portal.portlet.impl.DispatchedHttpServletRequest return null values.
Looking at the code, i saw a comment that said what they have to do.
Modified methods:
// Must be based on properties provided by the getProperties method of the PortletRequest interface
public String getHeader(String s)
{
return rreq.getProperty(s);
}
public Enumeration getHeaders(String s)
{
return rreq.getProperties(s);
}
public Enumeration getHeaderNames()
{
return rreq.getPropertyNames();
}
With this modification, jstl fmt doesn't throw NullPointerException anymore, but now locale is choosen by language's browser settings.
So now i have to use language preferences of the user logged in (if set it).
The first solution that i found is to modify org.jboss.portal.portlet.impl.PortletRequestImpl .
I'm not satisfied with this, it seems to be a workaround!! But it works!
If user logged in has a preferred language, will be used it, otherwise will be used default language.
Modified methods:
// PLT.11.1.4
public String getProperty(String name)
{
if (name.equalsIgnoreCase("accept-language")){
return getLocale().toString();
}
return requestContext.getPropertyValue(name);
}
public Enumeration getProperties(String name)
{
if (name.equalsIgnoreCase("accept-language")){
Vector v = new Vector();
v.add(userContext.getLocale().toString());
return v.elements();
}
return requestContext.getPropertyValues(name);
}
public Enumeration getPropertyNames()
{
Set names = requestContext.getPropertyNames();
return Collections.enumeration(names);
}
and
public Enumeration getLocales()
{
Vector v = new Vector();
v.add(userContext.getLocale());
return v.elements();
}
One question: if i would like to let an anonymous user to choose a language different from that is shown... how can i do this? any idea?
Unfortunately i haven't much time to understand well the build process of jboss portal, so i can't write a Unit Test for this. (if someone has some documentation to point me, i'm very interested to contribute to this project!)
PS: I have setup an enviroment of JBP 2.2.1RC2 + eclipse to develop and debug portlet. May i write a tutorial? (if someone is interested)
Hope this helps!!
Great works! Thanx to all!!
Luca Forni