This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can I extend 2 forms in struts  RSS feed

 
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
Sheriff
Posts: 24217
38
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!