Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pass bean from one action to another in strust2

 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a form wherein i fill in the details and click on Save button.
I do the validation of one of the fields in my action class.
If my validation returns true i redirect it to another action class to save the form data into database.
If my validation fails i redirect it to the jsp page.

My jsp:


actions.xml:


Action class:
1) CustomerAction


2)AuthenticateCIDAction:


3)Dao:



What am i doing wrong?

Thanks
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't say what the problem is.
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:You don't say what the problem is.

I want to retrieve the form information in my CustomerAction class.

I am getting null pointer exception as shown above.

Thanks
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"As shown above"? Really? I'm supposed to spot the line that looks the same as all the other lines with a comment in it?!

If you redirect anything in the action will be lost: actions are created per-request.
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:"As shown above"? Really? I'm supposed to spot the line that looks the same as all the other lines with a comment in it?!

If you redirect anything in the action will be lost: actions are created per-request.

Hey..
I am sorry for that "as shown above thing".


If not redirect, how else can i call my action class such that the bean info remains intact?
Currently i am putting my bean in the session. But by doing this i am going anti-struts.

Thanks

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing "anti-Struts" about using the session; that's what the session is there for.

Why do you redirect to the form page on a validation error? If you forwarded there wouldn't be an issue.
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:There's nothing "anti-Struts" about using the session; that's what the session is there for.

Why do you redirect to the form page on a validation error? If you forwarded there wouldn't be an issue.


I tried <result type="forward">, but i get an error saying "forward" is not recognised..

Thanks
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deeps Mistry wrote:
David Newton wrote:There's nothing "anti-Struts" about using the session; that's what the session is there for.

Why do you redirect to the form page on a validation error? If you forwarded there wouldn't be an issue.


I tried <result type="forward">, but i get an error saying "forward" is not recognised..

Thanks


I also tried <result="dispatcher">, but i get an error message saying "The Requested resource is not available". Is it it that i can only dispatch it to a jsp and not an action?

Any help would be highly appreciated.

Thanks
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deeps Mistry wrote:
Deeps Mistry wrote:
David Newton wrote:There's nothing "anti-Struts" about using the session; that's what the session is there for.

Why do you redirect to the form page on a validation error? If you forwarded there wouldn't be an issue.


I tried <result type="forward">, but i get an error saying "forward" is not recognised..

Thanks


I also tried <result="dispatcher">, but i get an error message saying "The Requested resource is not available". Is it it that i can only dispatch it to a jsp and not an action?

Any help would be highly appreciated.

Thanks


Hi,



Here is the code:


I validate the form fields using AuthenticateCIDAction. If success, then i add the information to the db. So i forward it to my next action class CustomerAction.
I want the form data intact, so i cannot use "redirect " as my result type.
Hence i used "chain" result type.

I tried using chain result type. But getting an error saying "The requested resource (There is no Action mapped for namespace /customer and action name SaveCustomer.action.) is not available.

Is there a problem with the syntax? or am i missing something?

Thanks.

 
Jayaraj Jaganathan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too have the same issue. i am looking for a answer :(

I hope that we have done mistake in interceptors

http://www.coderanch.com/t/475156/Struts/Application-Frameworks/Struts-Chain-Result-Type
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic