Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException @ validation interceptor

 
tyte kyat
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there I got a Null pointer Exception when trying to save an obj...
what actually happen is when I implemented validation interceptor while inserting customer obj into DB, I got the NPE .
if I remove that interceptor, it works fine.

But, I need validation implemented. so, how can i bypass?

thanks.



the following is my action class


and this is my struts.xml file



My dao class is as follow



my validation xml is as follow


 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is the member variable session set in your DAO? I suspect your @SessionTarget annotation is not working and session is null when the code tries to add a customer.
 
tyte kyat
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
James..

It turns out that it is not because of Session, it is somewhere @ value stack or at struts.xml file.

when I implement the following code in my struts.xml file (without validation interceptor)



and insert customer as named "p". I got the following at concole meaning that it is working perfectly.



and in my debug mode at my jsp page. I got the following information.


Now, what i believe is , due the implementation of "validation" interceptor, my value stack become empty or having null.
why is that so?
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Where is the interceptor called validation defined?
 
tyte kyat
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using predefine interceptor .
 
tyte kyat
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it working...
and I have to change my struts.xml file as follow



This is intend for those who are like me(newbie) in Struts and Hibernate...

You see no 1 and 5 is required as I am using full hibernate plugin. And according to the rule, there should be basic stack or default stack in your newly created stack.
without that you will get nullPointerException.

you see no 2 is required this is because ( you might need to go above of this page and look for "CustomerAction", which is implemented using modeldriven.)
for that reason you need it. again if you do not turn on ModelDriven Interceptor, you will get NullPointerException.

you see no 3 is required this is because somewhere in my application (which you can not have a reference here), username and password is required and that params interceptor is required for that reason.
without that again NPE.

and No 4 is the validation which is required to validate against user input.
that is all ...


(if i state something wrong here, I will happily take any suggestion and improvement.)
Thanks...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic