• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

saveErrors method in Action class

 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following in my code:

ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.logon.connect"));

saveErrors(request,errors); // how am i able to call the saveErrors method without a object ?
return (new ActionForward(mapping.getInput()));
}
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean, without an object?
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
saveErrors() is a method of org.apache.struts.Action class. So when we call saveErrors() why are we not using object.methodname() ?

Can i say that the ActionServlet takes care of creating the instance of Actionform ?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jose chiramal wrote:saveErrors() is a method of org.apache.struts.Action class. So when we call saveErrors() why are we not using object.methodname() ?


Because you're in the action whose saveErrors() you're calling... you might want to brush up on some Java basics before proceeding much further--if you're getting lost with casting and Java programming fundamentals it's a lot more productive to get them nailed down before diving into applications.

Can i say that the ActionServlet takes care of creating the instance of Actionform ?


The request processor instantiates the action forms.
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David Newton,

In java any method has to be called using an object unless it is a static method which can be called directly or using class name. In this case saveErrors() is not static, how are we able to call saveErrors(request,errors) directly without using any object is my question.

Awaiting a reply...
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Supporting my previous post , for example to use the add method in ActionErrors i use :

ActionErrors errors = new ActionErrors();

errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.general");
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jose chiramal wrote:In java any method has to be called using an object unless it is a static method which can be called directly or using class name. In this case saveErrors() is not static, how are we able to call saveErrors(request,errors) directly without using any object is my question.



Java 101. Please, please go back to the basics before considering doing much else, otherwise almost all code is going to look very confusing to you.

See Foo.baz()? It calls bar().

bar() is an instance method of class Foo that can be called by "any" other (non-static) method of Foo.

A Struts 1 action is an instance of class Action. Your action is a subclass of Action. Your action methods can call other methods of your action--or methods contained in its superclass... which is Action.

There's an implicit this in front of instance method calls within an instance. saveErrors(...) is an instance method of an Action. Essentially every single non-trivial Java class will call instance methods like this--it's almost impossible you haven't seen this before.
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, i remember having seen this ..thanks David Newton for your reply.
 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic