• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can I extend 2 forms in struts

 
gino jersey
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts newbie here who needs your help.

I need to design a page with 2 sections.
Section A is is similar to an existing page, while section B is similar to another existing page.

Can I design this page such that the Form bean for it extends the Form beans for pages A and B.

Can I say something like:
public final class myNewForm
extends myFirstForm, mySecondForm

Thank you.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a Struts forum -- I'll move this thread there for you.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, Java does not allow multiple inheritance.

Using containment might help you (myNewForm would contain and instance variable of type myFirstForm and an instance variable of type mySecondForm with get and set methods to access the contained forms). Rather than containing objects that both extend ActionForm, it might be cleaner to contain objects that are simple Java Beans. It might be easier to just cut and paste the needed properties.

- Brent
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you can't do this. Java doesn't allow multiple inheritance.

Don't over-think ActionForm beans. They're just simple JavaBeans and they're not part of the model. The only important thing is that they match what's on the page. If I were you, I'd just cut and paste the properties I need from either of the two form beans into your new form bean.

While I'd normally frown on "design by cut and paste", in this case I think it's the best solution.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic