Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems with jsp:useBean  RSS feed

 
Rafael Afonso
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike:
I'm sorry, but your suggestion does not work. I obtained same error.
Thanks anyway,
 
Rafael Afonso
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!