my dog learned polymorphism
The moose likes Struts and the fly likes cannot find saveErrors method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "cannot find saveErrors method" Watch "cannot find saveErrors method" New topic
Author

cannot find saveErrors method

amit sharma
Ranch Hand

Joined: Jul 19, 2006
Posts: 129
In my action class i call userauthentiction function.In this function if username password not match then i want to saveErrors method but it gives error. How to solve this problem.
Thanks
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi dmay,
please be kind enough to post the code..so that we may a closer look.

regards,
Roshani


Regards,<br />Roshani
amit sharma
Ranch Hand

Joined: Jul 19, 2006
Posts: 129
Let i have action class which check userauthentication.I get username and password.I make another class for checking UserAuthentication .I pass username ,password to this class.I don't want to include that logic in my action class.
UserAuthentication class return a string value which is the link to forward.
In UserAuthentication if username and password do not match then i want to save errors using saveErrors method .Below is the code which may be clear my point
In Action class
UserAuthentication ua=new UserAuthentication(username,password);
link=ua.checkAuthentication();

In UserAuthentication class
When authentication fail then i want to saveerrors in UserAuthentication class something like it .
ActionErrors e=new ActionErrors();
e.add("errors.Authentication",new ActionError("errors.InvalidAuthentication","Invalid Username And Password"));
saveErrors(req,e);
link=failure;
...................................
Is it possible to save errors in a class which not extend Action
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The saveErrors method is a method on the org.apache.struts.action.Action class, which your Action class extends. So, if you call saveErrors from your action class, it's actually calling the method in your superclass. If you try to call this method from another class, it obviously isn't going to work because the other class does not extend Action.

There are a couple of ways to go here, but here's what I'd suggest:

Since your UserAuthentication class contains business logic, that makes it a Model object in the MVC framework. As such, it's best if this model object has no dependencies on Struts or any other view framework. I'd refactor this method so that it either returns a boolean false or throws an exception in the case of an invalid user name or password. Then add logic in your Action class to handle the Struts messages.

The advantage to doing this is that it makes your application more flexible. If tomorrow you decide to change directions and make this a JSF, WebWorks, Swing (..the list goes on) application, you can simply plug in your model objects into the new framework and you don't have any dependencies on the old framework to worry about.

P.S. If you're using Struts 1.2 or above, you should be using ActionMessages instead of ActionErrors, as the latter is deprecated.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: cannot find saveErrors method
 
Similar Threads
ActionErrors (Struts)
cannot find saveErrors method
saveErrors method in Action class
html:messages problem
ActionMessages in STRUTS 1.1 Please help !!!