フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Christopher Olbertz
[Solved] How to get the Id of the current user with IceFaces?
2008/12/11 3:33
答え

Christopher Olbertz

ランク: Regular Member

投稿: 102

参加年月日: 2007/11/21

最近の投稿

Hi,

I am using IceFaces and I need the userId and other information of the current User. I read several threads in the forum about this theme, but I did not understand everything. Maybe, you can help in my case.

I am using the liferay plugin sdk. Do I need some jars? Have I to extend my portlet? At the moment, I am not extending my portlet from another class or interface. I am not using any features of LIferay.

Have I to change my web.xml?

This is my web.xml at the moment:

  1
  2<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  3
  4<web-app>
  5    <display-name>Interkulturelles Portal</display-name>
  6
  7    <description>Die Portlets fuer das Interkulturelle Portal</description>
  8
  9    <context-param>
 10        <param-name>javax.faces.application.CONFIG_FILES</param-name>
 11        <param-value>/WEB-INF/faces-config.xml</param-value>
 12    </context-param>
 13    <context-param>
 14        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
 15        <param-value>server</param-value>
 16    </context-param>
 17    <context-param>
 18        <param-name>com.icesoft.faces.compressResources</param-name>
 19        <param-value>true</param-value>
 20    </context-param>
 21    <context-param>
 22        <param-name>com.icesoft.faces.synchronousUpdate</param-name>
 23        <param-value>false</param-value>
 24    </context-param>
 25<!-- Specifies to the ICEfaces framework whether to support multiple views of a
 26     single application from the same browser.  When running in a Portlet
 27     environment, this parameter must be set to true. -->
 28    <context-param>
 29        <param-name>com.icesoft.faces.concurrentDOMViews</param-name>
 30        <param-value>true</param-value>
 31    </context-param>
 32
 33<!-- Specifies the amount of time in milliseconds that the bridge will wait for
 34     a response from the server for a user-initiated request before declaring
 35     the connection lost.  Un-comment and change the default value, if necessary.
 36    <context-param>
 37        <param-name>com.icesoft.faces.connectionTimeout</param-name>
 38        <param-value>60000</param-value>
 39    </context-param>
 40-->
 41
 42<!-- Specifies the amount of time in milliseconds that an idle asynchronous
 43     blocking connection should be held open before being released. Normally,
 44     the blocking connection is closed and re-opened with every communication to
 45     the browser, such as user interaction or a heartbeat ping. The purpose of
 46     this setting is to remove the possibility of threads being held blocked for
 47     a long duration on a dead or completely inactive client connection. This
 48     value should be longer than the heartbeat interval to avoid unnecessary
 49     network traffic.  Un-comment and change the default value, if necessary.
 50    <context-param>
 51        <param-name>com.icesoft.faces.blockingConnectionTimeout</param-name>
 52        <param-value>90000</param-value>
 53    </context-param>
 54-->
 55
 56<!-- Specifies the amount of time in milliseconds between heartbeat messages.
 57     Un-comment and change the default value, if necessary.
 58    <context-param>
 59        <param-name>com.icesoft.faces.heartbeatInterval</param-name>
 60        <param-value>50000</param-value>
 61    </context-param>
 62-->
 63
 64<!-- Specifies how many consecutive heartbeat connection attempts may fail
 65     before the connection is considered lost.  Un-comment and change the
 66     default value, if necessary.
 67    <context-param>
 68        <param-name>com.icesoft.faces.heartbeatRetries</param-name>
 69        <param-value>3</param-value>
 70    </context-param>
 71-->
 72
 73<!-- Specifies the number of milliseconds that a heartbeat request waits for a
 74     successful response before it is considered timed out.  Un-comment and
 75     change the default value, if necessary.
 76    <context-param>
 77        <param-name>com.icesoft.faces.heartbeatTimeout</param-name>
 78        <param-value>30000</param-value>
 79    </context-param>
 80-->
 81
 82<!-- Specifies a page URI to redirect the client to when an asynchronous
 83     connection is lost. The parameter value must be surrounded by single
 84     quotes.  Un-comment and change the default value, if necessary.
 85    <context-param>
 86        <param-name>com.icesoft.faces.connectionLostRedirectURI</param-name>
 87        <param-value></param-value>
 88    </context-param>
 89-->
 90
 91<!-- ConfigureListener is not generally required. Due to an apparent bug in
 92     Tomcat users have reported seeing the following error "SEVERE: ICEfaces
 93     could not initialize JavaServer Faces. Please check that the JSF .jar files
 94     are installed correctly.". Specifying the ConfigureListener resolves the
 95     issue.
 96    <listener>
 97        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
 98    </listener>
 99-->
100    <servlet>
101        <servlet-name>Faces Servlet</servlet-name>
102        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
103        <load-on-startup>1</load-on-startup>
104    </servlet>
105    <servlet>
106        <servlet-name>Blocking Servlet</servlet-name>
107        <servlet-class>com.icesoft.faces.webapp.xmlhttp.BlockingServlet</servlet-class>
108        <load-on-startup>1</load-on-startup>
109    </servlet>
110    <servlet>
111        <servlet-name>Persistent Faces Servlet</servlet-name>
112        <servlet-class>com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet</servlet-class>
113        <load-on-startup>1</load-on-startup>
114    </servlet>
115    <servlet-mapping>
116        <servlet-name>Faces Servlet</servlet-name>
117        <url-pattern>*.faces</url-pattern>
118    </servlet-mapping>
119    <servlet-mapping>
120        <servlet-name>Blocking Servlet</servlet-name>
121        <url-pattern>/block/*</url-pattern>
122    </servlet-mapping>
123    <servlet-mapping>
124        <servlet-name>Persistent Faces Servlet</servlet-name>
125        <url-pattern>/xmlhttp/*</url-pattern>
126    </servlet-mapping>
127    <servlet-mapping>
128        <servlet-name>Persistent Faces Servlet</servlet-name>
129        <url-pattern>*.iface</url-pattern>
130    </servlet-mapping>
131    <welcome-file-list>
132        <welcome-file>index.jsp</welcome-file>
133    </welcome-file-list>
134</web-app>


And how can I finally get the desired information?
Helmi Mahara
RE: How to get the Id of the current user with IceFaces?
2008/12/08 5:16
答え

Helmi Mahara

ランク: New Member

投稿: 13

参加年月日: 2008/08/08

最近の投稿

Hi Christopher,
Are you developing a portlet using JSF-IceFaces? If so, please have a look the sample portlet in the plugins ( http://lportal.svn.sourceforge.net/viewvc/lportal/plugins/trunk/portlets/sample-icefaces-jsf-1.2-sun-facelets-portlet/ ) sample-icefaces-jsf-1.2-sun-facelets-portlet. You can see things there i.e jar files to be included, web..xml, faces-config.xml, portlet.xml, etc.

To get userId you can do like this:
FacesContext fc = FacesContext.getCurrentInstance();
ThemeDisplay themeDisplay = (ThemeDisplay)fc.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
System.out.println("userId:"+themeDisplay.getUserId());

Hope it helps.
Cheers,
Christopher Olbertz
RE: How to get the Id of the current user with IceFaces?
2008/12/10 3:07
答え

Christopher Olbertz

ランク: Regular Member

投稿: 102

参加年月日: 2007/11/21

最近の投稿

Hi Helmi,

thank you very much for your answer.

But it does not work. I get a null pointer exception.

 1
 2java.lang.NullPointerException
 3    de.interkulturellesPortal.pages.training.TrainerRegistrationPage.callPage2(TrainerRegistrationPage.java:472)
 4    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 5    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 6    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 7    java.lang.reflect.Method.invoke(Method.java:597)
 8    org.apache.el.parser.AstValue.invoke(AstValue.java:152)
 9    org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
10    com.sun.faces.application.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
11    com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
12    javax.faces.component.UICommand.broadcast(UICommand.java:387)
13    javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
14    javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
15    com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
16    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
17    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
18    com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:17)
19    com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCycle(ReceiveSendUpdates.java:94)
20    com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(ReceiveSendUpdates.java:54)
21    com.icesoft.faces.webapp.http.core.RequestVerifier.service(RequestVerifier.java:26)
22    com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:24)
23    com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet.service(MainSessionBoundServlet.java:160)
24    com.icesoft.faces.webapp.http.servlet.SessionDispatcher$1.service(SessionDispatcher.java:38)
25    com.icesoft.faces.webapp.http.servlet.ThreadBlockingAdaptingServlet.service(ThreadBlockingAdaptingServlet.java:19)
26    com.icesoft.faces.webapp.http.servlet.EnvironmentAdaptingServlet.service(EnvironmentAdaptingServlet.java:63)
27    com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:55)
28    com.icesoft.faces.webapp.http.servlet.SessionVerifier.service(SessionVerifier.java:19)
29    com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
30    com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:91)
31    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
32    com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:56)


And this is my method:

 1
 2    public String callPage2() {
 3        if (conditionsAgreed == true) {            
 4            FacesContext context = FacesContext.getCurrentInstance();
 5            ThemeDisplay themeDisplay = (ThemeDisplay)context.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
 6            System.out.println("UserId: " + themeDisplay.getUserId());
 7            return "trainerRegistrationStep2";
 8        } else {
 9            FacesContext context = FacesContext.getCurrentInstance();
10            FacesMessage errorMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR,
11                                                         Constants.CONDITIONS_NOT_AGREED,
12                                                         Constants.CONDITIONS_NOT_AGREED);
13            context.addMessage(null, errorMessage);
14            return "trainerRegistrationStep1";
15        }       
16    }


Do you have any idea what's wrong?
Tobias Amon
RE: How to get the Id of the current user with IceFaces?
2008/12/10 3:25
答え

Tobias Amon

ランク: Liferay Master

投稿: 549

参加年月日: 2007/08/08

最近の投稿

Hi,

there are several threads in the forum onthis topic... simply use the search (-> themedisplay) and you will get some guides on this.

kind regards
Tobias
Christopher Olbertz
RE: How to get the Id of the current user with IceFaces?
2008/12/11 3:32
答え

Christopher Olbertz

ランク: Regular Member

投稿: 102

参加年月日: 2007/11/21

最近の投稿

Hi,

thank you for your answers.

Finally, I found a solution. I used this code and it worked:

1
2        FacesContext context = FacesContext.getCurrentInstance();
3        PortletRequest portletRequest = (PortletRequest)context.getExternalContext().getRequest();       
4        ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
5        System.out.println("User: " + themeDisplay.getUser().getUserId());