Hello:
I opted to use the APIs to develop portlets in Vaadin Liferay.
I have the need to access user data such as your name, role, id, etc …
I searched different ways to get data from the portlet Liferay:
I use this code:
Window mainWindow = new Window("Login Application");
//Name of logged User
Label label = new Label(userx);
mainWindow.addComponent(label);
setMainWindow(mainWindow);
}
}
I well I can access the user class methods using eclipse.
If I deploy the portlet I get in liferay: login is temporarily unavailable.
Catalina.out:
16:14:48,475 INFO [PortletHotDeployListener:371]
1 portlet for login is available for use
16:15:24,121 ERROR [PortletServlet:96]
javax.portlet.PortletException: java.lang.NullPointerException
javax.portlet.PortletException: java.lang.NullPointerException
at com.vaadin.terminal.gwt.server.AbstractApplicationPortlet.handleServiceException(AbstractApplicationPortlet.java:1334)
at com.vaadin.terminal.gwt.server.AbstractApplicationPortlet.handleRequest(AbstractApplicationPortlet.java:487)
at com.vaadin.terminal.gwt.server.AbstractApplicationPortlet.doDispatch(AbstractApplicationPortlet.java:715)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:101)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:628)
at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:713)
at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:424)
at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(Unknown Source)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377
[u]
[/u]
etc …
Caused by: java.lang.NullPointerException
at com.example.login.LoginApplication.init(LoginApplication.java:22)
at com.vaadin.Application.start(Application.java:549)
at com.vaadin.terminal.gwt.server.AbstractApplicationPortlet.startApplication(AbstractApplicationPortlet.java:752)
at com.vaadin.terminal.gwt.server.AbstractApplicationPortlet.handleRequest(AbstractApplicationPortlet.java:400)
… 191 more
at least one way to access the user data would be to implement the
com.vaadin.terminal.gwt.server.PortletRequestListener interface and use the
PortletRequest instance given as the parameter of the
onRequestStart method to retrieve the current user.
In the code you provided, you don’t have an actual request instance and therefore you get the
NullPointerException .
Hope this helps. I’ll be happy to provide more detailed instructions if needed.
I created a simple example application for you. I also tested it to work properly on Liferay Portal 5.2.3.
The
Application class implements the
PortletRequestListener and sets the Vaadin application user to the Liferay
User instance inside the
onRequestStart method. In order to get hold of the Liferay
User instance, we use the
PortalUtil.getUser static method.
In the
init method of the application we add a
Label which greets the current user or displays
“Hello anonymous Vaadin user” if there is no Liferay user logged in.
Please note that you must have the
portlet.jar ,
portal-service.jar and
portal-kernel.jar libraries in your build path in order to compile the code.
package com.example.login;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import com.liferay.portal.PortalException;
import com.liferay.portal.SystemException;
import com.liferay.portal.model.User;
import com.liferay.portal.util.PortalUtil;
import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.PortletRequestListener;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;
public class LoginApplication extends Application implements
PortletRequestListener {
@Override
public void init() {
Window mainWindow = new Window("LoginApplication");
Label label = new Label("Hello anonymous Vaadin user");
if (getUser() != null) {
// user has logged in
label = new Label("Hello " + ((User) getUser()).getFullName());
}
mainWindow.addComponent(label);
setMainWindow(mainWindow);
}
@Override
public void onRequestStart(PortletRequest request, PortletResponse response) {
if (getUser() == null) {
try {
User user = PortalUtil.getUser(request);
setUser(user);
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
}
}
@Override
public void onRequestEnd(PortletRequest request, PortletResponse response) {
// Nothing to do here currently, exists only to implement the
// PortletRequestListener interface.
}
}
hi there I am trying to make Vaadin Portlet where I am supposed to fetch current login user’s ID,Company Id and GroupId as I am supposed to created event in the Calendar any suggestion plz its urgent thanks in advance.
What is happening is that I am able to add event in the database but event is not shown in the Calendar