File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes can I extend 2 forms in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "can I extend 2 forms in struts" Watch "can I extend 2 forms in struts" New topic

can I extend 2 forms in struts

gino jersey

Joined: May 24, 2005
Posts: 21
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

Joined: Jul 08, 2003
Posts: 24199

We have a Struts forum -- I'll move this thread there for you.

[Jess in Action][AskingGoodQuestions]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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

Joined: Feb 15, 2005
Posts: 4864
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.

Consultant, Sima Solutions
I agree. Here's the link:
subject: can I extend 2 forms in struts
It's not a secret anymore!