File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes NullPointerException @ validation interceptor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "NullPointerException @ validation interceptor" Watch "NullPointerException @ validation interceptor" New topic
Author

NullPointerException @ validation interceptor

tyte kyat
Ranch Hand

Joined: May 17, 2011
Posts: 40
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

Joined: Nov 09, 2011
Posts: 1020
    
    5

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

Joined: May 17, 2011
Posts: 40
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

Joined: Nov 09, 2011
Posts: 1020
    
    5



Where is the interceptor called validation defined?
tyte kyat
Ranch Hand

Joined: May 17, 2011
Posts: 40
I am using predefine interceptor .
tyte kyat
Ranch Hand

Joined: May 17, 2011
Posts: 40
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException @ validation interceptor