You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Kevin Irmscher <ke...@gmail.com> on 2007/05/04 13:46:55 UTC

Access portal user information in JSF Portlet application

Hi,

I have a JSF application in a Liferay Portal rendered as portlet using
MyFacesGenericPortlet class. I want to access user information that is
provided by the portal.

In a normal portlet application they can be accessed using
javax.portlet.RenderRequest.getAttribute(PortletRequest.USER_INFO);
in the render phase.

I tried it like that:
FacesContext fc = FacesContext.getCurrentInstance();
PortletRequest request = (PortletRequest) fc.getExternalContext().getRequest();
Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
String name = (String) userInfo.get("user.name.given");

The map does not contain a user.name.given key so name is null.

Has anyone an idea how to solve that?

Regards, Kevin

AW: Access portal user information in JSF Portlet application

Posted by "Pfau, Oliver" <ol...@siemens.com>.
I have mapped the user info in portlet.xml too....but found the login name only under the key "liferay.user.id"....try  

String name = (String) userInfo.get("liferay.user.id");

But it hurts JSR 168


-----Ursprüngliche Nachricht-----
Von: Kevin Irmscher [mailto:kevin.irmscher@gmail.com] 
Gesendet: Freitag, 4. Mai 2007 13:47
An: users@myfaces.apache.org
Betreff: Access portal user information in JSF Portlet application

Hi,

I have a JSF application in a Liferay Portal rendered as portlet using
MyFacesGenericPortlet class. I want to access user information that is
provided by the portal.

In a normal portlet application they can be accessed using
javax.portlet.RenderRequest.getAttribute(PortletRequest.USER_INFO);
in the render phase.

I tried it like that:
FacesContext fc = FacesContext.getCurrentInstance();
PortletRequest request = (PortletRequest) fc.getExternalContext().getRequest();
Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
String name = (String) userInfo.get("user.name.given");

The map does not contain a user.name.given key so name is null.

Has anyone an idea how to solve that?

Regards, Kevin

Re: Access portal user information in JSF Portlet application

Posted by Scott O'Bryan <da...@gmail.com>.
I'm sortof split on this.  Since it's an attribute, he should just use 
the EC, it's cheaper and more robust then the cast.  If he needed 
something ELSE on the native object that the EC didn't provide, casting 
is the only option.

That said, Kevin, are you sure you have a RenderRequest?  Bridges will 
serve you a render request on the first complete lifecycle and then a 
combination of action/render requests for additional lifecycles.  I 
noticed that you were casting to the PortletRequest which is the common 
ancestor for both yet that parameter is only available on the render 
request.

If you change you cast to RenderRequest and get a ClassCastException 
then you'll know your in the wrong class.  In general you can only count 
that you have a render request during the render phase of the JSF 
lifecycle.  Every other phase may have either/or...

Hope this helps,
Scott

Ryan Wynn wrote:
> On 5/4/07, Nebinger, David <dn...@tbbgl.com> wrote:
>> > First of all, it's easier to get the request map from the
>> > ExternalContext:
>> >
>> > Map requestMap = externalContext.getRequestMap();
>>
>> For the http request parameters, sure you're correct.  But he's got a
>> portlet and he's looking for a portlet request parameter, so he's going
>> about things the correct way.
>
> MyFacesGenericPortlet creates a special derivation of ExternalContext
> for you that wraps the portlet request (and portletSession, etc).  So
> getRequestMap() is going to give you a map backed by the
> portletRequest parameters.  In essence alot of stuff works no matter
> what container you are in, as long as you don't cast to container
> specific classes.  So I would agree with Kito on the first point and
> not cast specifically to PortletRequest.
>


Re: Access portal user information in JSF Portlet application

Posted by Scott O'Bryan <da...@gmail.com>.
Actually, it's an attribute, you were right the first time... :)

BTW- Is there any reason you can't use PortletRequest.getRemoteUser()?  
I think that's available in all PortletRequest's provided a user has 
been authenticated.  I mean if you're casting, you may as well use the 
real method right?

Scott

Ryan Wynn wrote:
> On 5/4/07, Ryan Wynn <bi...@gmail.com> wrote:
>> On 5/4/07, Nebinger, David <dn...@tbbgl.com> wrote:
>> > > First of all, it's easier to get the request map from the
>> > > ExternalContext:
>> > >
>> > > Map requestMap = externalContext.getRequestMap();
>> >
>> > For the http request parameters, sure you're correct.  But he's got a
>> > portlet and he's looking for a portlet request parameter, so he's 
>> going
>> > about things the correct way.
>>
>> MyFacesGenericPortlet creates a special derivation of ExternalContext
>> for you that wraps the portlet request (and portletSession, etc).  So
>> getRequestMap() is going to give you a map backed by the
>> portletRequest parameters.  In essence alot of stuff works no matter
>> what container you are in, as long as you don't cast to container
>> specific classes.  So I would agree with Kito on the first point and
>> not cast specifically to PortletRequest.
>>
>
> Sorry I meant getRequestParameterMap() instead of getRequestMap() in
> my previous post.
>


Re: Access portal user information in JSF Portlet application

Posted by Ryan Wynn <bi...@gmail.com>.
On 5/4/07, Ryan Wynn <bi...@gmail.com> wrote:
> On 5/4/07, Nebinger, David <dn...@tbbgl.com> wrote:
> > > First of all, it's easier to get the request map from the
> > > ExternalContext:
> > >
> > > Map requestMap = externalContext.getRequestMap();
> >
> > For the http request parameters, sure you're correct.  But he's got a
> > portlet and he's looking for a portlet request parameter, so he's going
> > about things the correct way.
>
> MyFacesGenericPortlet creates a special derivation of ExternalContext
> for you that wraps the portlet request (and portletSession, etc).  So
> getRequestMap() is going to give you a map backed by the
> portletRequest parameters.  In essence alot of stuff works no matter
> what container you are in, as long as you don't cast to container
> specific classes.  So I would agree with Kito on the first point and
> not cast specifically to PortletRequest.
>

Sorry I meant getRequestParameterMap() instead of getRequestMap() in
my previous post.

Re: Access portal user information in JSF Portlet application

Posted by Ryan Wynn <bi...@gmail.com>.
On 5/4/07, Nebinger, David <dn...@tbbgl.com> wrote:
> > First of all, it's easier to get the request map from the
> > ExternalContext:
> >
> > Map requestMap = externalContext.getRequestMap();
>
> For the http request parameters, sure you're correct.  But he's got a
> portlet and he's looking for a portlet request parameter, so he's going
> about things the correct way.

MyFacesGenericPortlet creates a special derivation of ExternalContext
for you that wraps the portlet request (and portletSession, etc).  So
getRequestMap() is going to give you a map backed by the
portletRequest parameters.  In essence alot of stuff works no matter
what container you are in, as long as you don't cast to container
specific classes.  So I would agree with Kito on the first point and
not cast specifically to PortletRequest.

RE: Access portal user information in JSF Portlet application

Posted by "Nebinger, David" <dn...@tbbgl.com>.
> First of all, it's easier to get the request map from the 
> ExternalContext:
> 
> Map requestMap = externalContext.getRequestMap();

For the http request parameters, sure you're correct.  But he's got a
portlet and he's looking for a portlet request parameter, so he's going
about things the correct way.
 
> However, if you still can't find the key, it may be an issue 
> with the Liferay portlet bridge. I would suggest asking about 
> it in their forums to make sure they're propogating those 
> keys to the ExternalContext properly.

Umm, again he said he was creating a portlet and not using the portlet
bridge, so the external context setting does not apply.

RE: Access portal user information in JSF Portlet application

Posted by "Kito D. Mann" <km...@virtua.com>.
Hello Kevin,

First of all, it's easier to get the request map from the ExternalContext:

Map requestMap = externalContext.getRequestMap();

However, if you still can't find the key, it may be an issue with the
Liferay portlet bridge. I would suggest asking about it in their forums to
make sure they're propogating those keys to the ExternalContext properly.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Kito D. Mann (kmann@virtua.com)
Author, JavaServer Faces in Action
http://www.virtua.com - JSF/Java EE consulting, training, and mentoring
http://www.JSFCentral.com - JavaServer Faces FAQ, news, and info

> -----Original Message-----
> From: Kevin Irmscher [mailto:kevin.irmscher@gmail.com]
> Sent: Friday, May 04, 2007 7:47 AM
> To: users@myfaces.apache.org
> Subject: Access portal user information in JSF Portlet application
> 
> Hi,
> 
> I have a JSF application in a Liferay Portal rendered as portlet using
> MyFacesGenericPortlet class. I want to access user information that is
> provided by the portal.
> 
> In a normal portlet application they can be accessed using
> javax.portlet.RenderRequest.getAttribute(PortletRequest.USER_INFO);
> in the render phase.
> 
> I tried it like that:
> FacesContext fc = FacesContext.getCurrentInstance();
> PortletRequest request = (PortletRequest)
> fc.getExternalContext().getRequest();
> Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
> String name = (String) userInfo.get("user.name.given");
> 
> The map does not contain a user.name.given key so name is null.
> 
> Has anyone an idea how to solve that?
> 
> Regards, Kevin