| Author |
Problems with jsp:useBean
|
Rafael Afonso
Ranch Hand
Joined: Jul 16, 2002
Posts: 63
|
|
Hello: I am using a System with JBoss + Tomcat. In my JSP Page I have created a bean (a ArrayList) in this form: When I open the page, it appears "broken". In JBoss Prompt I obtained these messages:
09:59:51,796 INFO [_jspService] [] 09:59:51,796 INFO [_jspService] empty? true 09:59:51,836 ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception ... 09:59:51,906 ERROR [Engine] ----- Root Cause ----- java.lang.NullPointerException at java.util.ArrayList.addAll(ArrayList.java:433) at org.apache.jsp.cadast_endereco_jsp._jspService(cadast_endereco_jsp.ja va:564)
Who will be the NullPointer? If it was listAddresses, the logging messages will not be printed. Furthermore, when I comment <jsp:useBean> block, there is no errors. This indicates that bean.getAddress() does not return null. In other regions of code I did same thing: I created a ArrayList bean and I full it with a addAll() and there is no problems. So, What am I doing wrong? Thanks,
|
=================================<br /> Rafael U. C. Afonso<br /> <a href="http://www.javafree.com.br" target="_blank" rel="nofollow">www.javafree.com.br</a><br />=================================<br /><i>Where is debug?<br />debug is on the table</i>
|
 |
Mike Curwen
Ranch Hand
Joined: Feb 20, 2001
Posts: 3695
|
|
Can you do this? Use the instance of your bean before you close the :useBean tag? Ok, now that I've looked closer, you are using the instance *before* the NPE, so obviously you can; but it makes me uneasy anyways. It must be the bean.getAddress() that is throwing the NPE. I always find it helpful to actually look at the generated java code of a JSP. You might find that 'bean' is not being scoped properly. [ February 25, 2003: Message edited by: Mike Curwen ]
|
 |
Rafael Afonso
Ranch Hand
Joined: Jul 16, 2002
Posts: 63
|
|
Mike: I'm sorry, but your suggestion does not work. I obtained same error. Thanks anyway,
|
 |
Rafael Afonso
Ranch Hand
Joined: Jul 16, 2002
Posts: 63
|
|
Mike: You are right. bean.getAddress() was returning null. According AbstractCollection specification (from what ArrayList derives) it is thrown a NullPointerException when it receives a null Collection. So it was my fault. [ February 25, 2003: Message edited by: Rafael Afonso ]
|
 |
Mike Curwen
Ranch Hand
Joined: Feb 20, 2001
Posts: 3695
|
|
From the definition of ArrayList - Resizable-array implementation of the List interface. Implements all optional list operations, and permits all elements, including null It's not that it doesn't permit nulls. It's that what you sent the method was a null object. [ February 25, 2003: Message edited by: Mike Curwen ]
|
 |
 |
|
|
subject: Problems with jsp:useBean
|
|
|