2

I have this code to implement ModelDriven mechanism.

public class Input_newAction extends CommonAction implements ModelDriven<InputForm> {

    private InputForm form = new InputForm();
    @Override
    public InputForm getModel() {
        return form;
    }
}

The problem is I need to pass another form to Input_newAction. How to do this?

public class Input_newAction extends CommonAction implements ModelDriven<InputForm>, 
ModelDriven<CopyForm> {
...
}
Roman C
  • 49,761
  • 33
  • 66
  • 176
emeraldhieu
  • 9,380
  • 19
  • 81
  • 139
  • i do not think this is possible (not 100% sure). either you can have nested object with one domain object or can use simple object mapping in place of model driven. – Umesh Awasthi Jun 07 '13 at 04:59

1 Answers1

0

You cannot implement two or more specialization of the same interface.

Instead you could make an interface or abstract class for the forms that will specialize the ModelDriven and return that interface via implementing getModel() of the ModelDriven.

When the action is called you could check some condition (either parameter or method, or mapping) and return the corresponding model to fit the condition specified.

public class Input_newAction extends CommonAction implements ModelDriven<CommonForm> {
  private boolean par;
  public setPar(boolean par){
    this.par = par;
  } 

  @Override
  public CommonForm getModel() {
    if (par)
     return inputForm;  
    else
     return copyForm;
  }
}
Roman C
  • 49,761
  • 33
  • 66
  • 176