Problem passing bean to JSP

Hi everyone,

I am having issues with passing a Java Bean to a JSP for a Portlet for Liferay.
I have attached the JSP, the Java class that is supposed to represent the controller and my sad attempt at creating a bean to transfer the data I need.

Here is what I attempted to do:
To have as little Java Code in the JSP as possible I try to get the values I want (all the communities and the selected communitys’ users, which is commented out) and put them in the FuksMsvTransferObject, which is then passed to the JSP with request.setAttribute(“FuksMsvTransferBean”, fmto)

In the JSP I pull the Object with
<jsp:useBean id=“transferObjekt” scope=“request” class=“org.fuks.itwm.msv.FuksMsvTransferBean” />

The problem is that I get a NullPointerException later on in the JSP where I try to get the stored Object from within the Bean.

What am I doing wrong?

DodoFXP

That is the right question. Damn.

Here goes my explanation attempt:
The Liferay folks extenden the GenericPortlet form the API to take care of some of the page management. In the portlet.xml I can set a default view for my portlet, which right now points to my view.jsp.
I thought that it would call my doView(…,…) Method, which it doesn’t do.
(Checked the logs, it only shows that the bean was created, not that the method was called)
Therefor it is absolutely right that it throws a NullPointerException.
I think I have to check with the Liferay folk how I can have my method called first.

Thanks for your help, I’ll post any results from that discussion.
DodoFXP

Can you post the error and stack trace please?

Okay…how does one get to the view.jsp?
Does the “_log.info(“doView() was called”);” from FuksMSV show up in the log?

In the files I uploaded in my previous post that mistake is already fixed…
It has to be something else.

Felipe

In FuksMSV.java you have:
request.setAttribute(“ressortList”, fmtb);

but in view.jsp you have
<jsp:useBean id=“transferObjekt” scope=“request” class=“org.fuks.itwm.msv.FuksMsvTransferBean” />

Because transferObjekt refers to a different Object than ressortList, transferObjekt will be created ‘on-the-fly’ and will contain no data, as such, it’s getRessorts returns null, which should be plain enough if you read your log - if you take the time to write to the log, take the time to read the results :wink:

I have dumped a couple of irrelevant lines from the stacktrace, as it was huge.



06:49:47,237 ERROR [PortletRequestDispatcherImpl:107] org.apache.jasper.JasperException: An exception occurred processing JSP page /html/fuksmsv/view.jsp at line 23

20: 
21: <aui:form action="<%= doViewURL %>" name="fm">
22: 	<aui:select label="Reesortauswahl" name="ressortAuswahl"> 
23: 		<% for( Group u : ressortList.getRessorts() ) {%>
24: 			<aui:option value="<%= u.getName() %>" ><liferay-ui:message key="<%= u.getName() %>" /> </aui:option>
25: 		<% } %>
26: 	</aui:select>


Stacktrace:
org.apache.jasper.JasperException: An exception occurred processing JSP page /html/fuksmsv/view.jsp at line 23

20: 
21: <aui:form action="<%= doViewURL %>" name="fm">
22: 	<aui:select label="Reesortauswahl" name="ressortAuswahl"> 
23: 		<% for( Group u : ressortList.getRessorts() ) {%>
24: 			<aui:option value="<%= u.getName() %>" ><liferay-ui:message key="<%= u.getName() %>" /> </aui:option>
25: 		<% } %>
26: 	</aui:select>


Stacktrace:
	at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
	(...)
	... 207 more
06:49:47,240 ERROR [PortletServlet:96] javax.portlet.PortletException: org.apache.jasper.JasperException: An exception occurred processing JSP page /html/fuksmsv/view.jsp at line 23

20: 
21: <aui:form action="<%= doViewURL %>" name="fm">
22: 	<aui:select label="Reesortauswahl" name="ressortAuswahl"> 
23: 		<% for( Group u : ressortList.getRessorts() ) {%>
24: 			<aui:option value="<%= u.getName() %>" ><liferay-ui:message key="<%= u.getName() %>" /> </aui:option>
25: 		<% } %>
26: 	</aui:select>


Stacktrace:
javax.portlet.PortletException: org.apache.jasper.JasperException: An exception occurred processing JSP page /html/fuksmsv/view.jsp at line 23

20: 
21: <aui:form action="<%= doViewURL %>" name="fm">
22: 	<aui:select label="Reesortauswahl" name="ressortAuswahl"> 
23: 		<% for( Group u : ressortList.getRessorts() ) {%>
24: 			<aui:option value="<%= u.getName() %>" ><liferay-ui:message key="<%= u.getName() %>" /> </aui:option>
25: 		<% } %>
26: 	</aui:select>


Stacktrace:
	at com.liferay.portlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:109)
	at com.liferay.util.bridges.mvc.MVCPortlet.include(MVCPortlet.java:324)
	at com.liferay.util.bridges.mvc.MVCPortlet.include(MVCPortlet.java:339)
	at com.liferay.util.bridges.mvc.MVCPortlet.doView(MVCPortlet.java:127)
	at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:202)
	at com.liferay.util.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:290)
	at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
	at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:101)
	(...)
	at java.lang.Thread.run(Thread.java:637)
Caused by: org.apache.jasper.JasperException: An exception occurred processing JSP page /html/fuksmsv/view.jsp at line 23

20: 
21: <aui:form action="<%= doViewURL %>" name="fm">
22: 	<aui:select label="Reesortauswahl" name="ressortAuswahl"> 
23: 		<% for( Group u : ressortList.getRessorts() ) {%>
24: 			<aui:option value="<%= u.getName() %>" ><liferay-ui:message key="<%= u.getName() %>" /> </aui:option>
25: 		<% } %>
26: 	</aui:select>


Stacktrace:
	at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	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.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:315)
	at com.liferay.portlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:104)
	... 197 more
Caused by: java.lang.NullPointerException
	at org.apache.jsp.html.fuksmsv.view_jsp._jspService(view_jsp.java:299)
	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)
	... 207 more
06:49:47,243 ERROR [jsp:154] java.lang.NullPointerException
	at org.apache.jsp.html.fuksmsv.view_jsp._jspService(view_jsp.java:299)
	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)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	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.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:315)
	at com.liferay.portlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:104)
	at com.liferay.util.bridges.mvc.MVCPortlet.include(MVCPortlet.java:324)
	at com.liferay.util.bridges.mvc.MVCPortlet.include(MVCPortlet.java:339)
	at com.liferay.util.bridges.mvc.MVCPortlet.doView(MVCPortlet.java:127)
	at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:202)
	at com.liferay.util.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:290)
	at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)

I have reattached the code as it has changed a bit. ( I am starting to code with a buddy, so I had to add some comments, which I have removed for the upload)
One more info: I am writing a Portlet for Liferay 6.0 and using their MVCPortlet which extends the GenericPortlet class.

Thanks!