my dog learned polymorphism*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "can I extend 2 forms in struts" Watch "can I extend 2 forms in struts" New topic
Author

can I extend 2 forms in struts

gino jersey
Greenhorn

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
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


Merrill
Consultant, Sima Solutions
 
 
subject: can I extend 2 forms in struts
 
Similar Threads
Get result page from remote struts action call
PRoblem in displaying ActionForm
ActionForm: Is it a View or Model component
How can I get 2 error message sections on a page?
Different Types of Form beans in struts