掲示板
[Solved] How to get the Id of the current user with IceFaces?
15年前 に Christopher Olbertz によって更新されました。
[Solved] How to get the Id of the current user with IceFaces?
Regular Member 投稿: 107 参加年月日: 07/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:
And how can I finally get the desired information?
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:
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<web-app>
<display-name>Interkulturelles Portal</display-name>
<description>Die Portlets fuer das Interkulturelle Portal</description>
<context-param>
<param-name>javax.faces.application.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.compressResources</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.synchronousUpdate</param-name>
<param-value>false</param-value>
</context-param>
<!-- Specifies to the ICEfaces framework whether to support multiple views of a
single application from the same browser. When running in a Portlet
environment, this parameter must be set to true. -->
<context-param>
<param-name>com.icesoft.faces.concurrentDOMViews</param-name>
<param-value>true</param-value>
</context-param>
<!-- Specifies the amount of time in milliseconds that the bridge will wait for
a response from the server for a user-initiated request before declaring
the connection lost. Un-comment and change the default value, if necessary.
<context-param>
<param-name>com.icesoft.faces.connectionTimeout</param-name>
<param-value>60000</param-value>
</context-param>
-->
<!-- Specifies the amount of time in milliseconds that an idle asynchronous
blocking connection should be held open before being released. Normally,
the blocking connection is closed and re-opened with every communication to
the browser, such as user interaction or a heartbeat ping. The purpose of
this setting is to remove the possibility of threads being held blocked for
a long duration on a dead or completely inactive client connection. This
value should be longer than the heartbeat interval to avoid unnecessary
network traffic. Un-comment and change the default value, if necessary.
<context-param>
<param-name>com.icesoft.faces.blockingConnectionTimeout</param-name>
<param-value>90000</param-value>
</context-param>
-->
<!-- Specifies the amount of time in milliseconds between heartbeat messages.
Un-comment and change the default value, if necessary.
<context-param>
<param-name>com.icesoft.faces.heartbeatInterval</param-name>
<param-value>50000</param-value>
</context-param>
-->
<!-- Specifies how many consecutive heartbeat connection attempts may fail
before the connection is considered lost. Un-comment and change the
default value, if necessary.
<context-param>
<param-name>com.icesoft.faces.heartbeatRetries</param-name>
<param-value>3</param-value>
</context-param>
-->
<!-- Specifies the number of milliseconds that a heartbeat request waits for a
successful response before it is considered timed out. Un-comment and
change the default value, if necessary.
<context-param>
<param-name>com.icesoft.faces.heartbeatTimeout</param-name>
<param-value>30000</param-value>
</context-param>
-->
<!-- Specifies a page URI to redirect the client to when an asynchronous
connection is lost. The parameter value must be surrounded by single
quotes. Un-comment and change the default value, if necessary.
<context-param>
<param-name>com.icesoft.faces.connectionLostRedirectURI</param-name>
<param-value></param-value>
</context-param>
-->
<!-- ConfigureListener is not generally required. Due to an apparent bug in
Tomcat users have reported seeing the following error "SEVERE: ICEfaces
could not initialize JavaServer Faces. Please check that the JSF .jar files
are installed correctly.". Specifying the ConfigureListener resolves the
issue.
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
-->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Blocking Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.BlockingServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Persistent Faces Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Blocking Servlet</servlet-name>
<url-pattern>/block/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>*.iface</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
And how can I finally get the desired information?
15年前 に Helmi Mahara によって更新されました。
RE: How to get the Id of the current user with IceFaces?
New Member 投稿: 13 参加年月日: 08/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,
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,
15年前 に Christopher Olbertz によって更新されました。
RE: How to get the Id of the current user with IceFaces?
Regular Member 投稿: 107 参加年月日: 07/11/21 最新の投稿
Hi Helmi,
thank you very much for your answer.
But it does not work. I get a null pointer exception.
And this is my method:
Do you have any idea what's wrong?
thank you very much for your answer.
But it does not work. I get a null pointer exception.
java.lang.NullPointerException
de.interkulturellesPortal.pages.training.TrainerRegistrationPage.callPage2(TrainerRegistrationPage.java:472)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.el.parser.AstValue.invoke(AstValue.java:152)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
com.sun.faces.application.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:387)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:17)
com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCycle(ReceiveSendUpdates.java:94)
com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(ReceiveSendUpdates.java:54)
com.icesoft.faces.webapp.http.core.RequestVerifier.service(RequestVerifier.java:26)
com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:24)
com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet.service(MainSessionBoundServlet.java:160)
com.icesoft.faces.webapp.http.servlet.SessionDispatcher$1.service(SessionDispatcher.java:38)
com.icesoft.faces.webapp.http.servlet.ThreadBlockingAdaptingServlet.service(ThreadBlockingAdaptingServlet.java:19)
com.icesoft.faces.webapp.http.servlet.EnvironmentAdaptingServlet.service(EnvironmentAdaptingServlet.java:63)
com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:55)
com.icesoft.faces.webapp.http.servlet.SessionVerifier.service(SessionVerifier.java:19)
com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:91)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:56)
And this is my method:
public String callPage2() {
if (conditionsAgreed == true) {
FacesContext context = FacesContext.getCurrentInstance();
ThemeDisplay themeDisplay = (ThemeDisplay)context.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
System.out.println("UserId: " + themeDisplay.getUserId());
return "trainerRegistrationStep2";
} else {
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage errorMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR,
Constants.CONDITIONS_NOT_AGREED,
Constants.CONDITIONS_NOT_AGREED);
context.addMessage(null, errorMessage);
return "trainerRegistrationStep1";
}
}
Do you have any idea what's wrong?
15年前 に Tobias Amon によって更新されました。
RE: How to get the Id of the current user with IceFaces?
Liferay Master 投稿: 546 参加年月日: 07/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
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
15年前 に Christopher Olbertz によって更新されました。
RE: How to get the Id of the current user with IceFaces?
Regular Member 投稿: 107 参加年月日: 07/11/21 最新の投稿
Hi,
thank you for your answers.
Finally, I found a solution. I used this code and it worked:
thank you for your answers.
Finally, I found a solution. I used this code and it worked:
FacesContext context = FacesContext.getCurrentInstance();
PortletRequest portletRequest = (PortletRequest)context.getExternalContext().getRequest();
ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
System.out.println("User: " + themeDisplay.getUser().getUserId());