• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using inheritance in struts

 
rangababu chakravarthula
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Is is possible to have a action form bean which will have common form elements and have separate action form beans for each kind of report that will inherit the base action form and use the form elements.

If yes, do I have to have the base action form entry in struts-config.xml

Same question with Action class. Can I have a base action class and have report specific action classes that inherit the base action class. because in my case for every report that the application needs to generate it has to check roles that will be available in request cookies. (jaas roles is not possible in this case. has to be request cookies) can I have that functionality in base action class and have report specific actions in their respective action classes. And also what configuration needs to be done in struts-config.xml

thanks
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it certainly is possible to use inheritance for both an ActionForm bean and an Action class.

For an action form, the process is:
  • Write your base class with the shared properties and their getters and setters. This class should extend ActionForm
  • Write your subclasses extending your base class with the added properties and getters and setters
  • Make an entry in struts-config.xml for each subclass. There is no need to put the base class anywhere in struts-config.xml


  • For an Action class, the process is:
  • Write your base class extending Action. Your execute method should contain logic that is performed for all actions. My suggestion is to make it return null if everything is OK, and have it return an ActionForward to an error page if it encounters an error.
  • Write your subclasses extending your base class. The execute method should start with:

  • ActionForward forwardFromBase = super.execute(<list all parms>);
    if (forwardFromBase != null) return forwardFromBase():
  • The rest of the execute() method should contain logic unique to each subclass
  • Make an entry in struts-config.xml for each action. There is no need to put the base class anywhere in struts-config.xml


  • Good luck!
    [ June 10, 2005: Message edited by: Merrill Higginson ]
     
    rangababu chakravarthula
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    great! thank you very much Merrill. Will try out a sample and test.
     
    amit gupta
    Greenhorn
    Posts: 23
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    rangababu chakravarthula wrote:great! thank you very much Merrill. Will try out a sample and test.


    I have tried to extend action form. But when I try to access the properties of base class in sub class. it gives me null.

     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic