aspose file tools*
The moose likes Struts and the fly likes Pass bean from one action to another in strust2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Pass bean from one action to another in strust2" Watch "Pass bean from one action to another in strust2" New topic
Author

Pass bean from one action to another in strust2

Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
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

Joined: Sep 29, 2008
Posts: 12617

You don't say what the problem is.
Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
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

Joined: Sep 29, 2008
Posts: 12617

"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

Joined: Jan 31, 2009
Posts: 189
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jan 31, 2009
Posts: 189
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

Joined: Jan 31, 2009
Posts: 189
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

Joined: Jan 31, 2009
Posts: 189
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

Joined: Jun 29, 2009
Posts: 70
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
 
wood burning stoves
 
subject: Pass bean from one action to another in strust2