Form processing with inheritance -


i have model can described follows:

http://aoeu.se/so/animal-dog-cat.png

(extremely simplified. actual classes have ten-twenty more fields each.)

i have persistence worked out , i'm trying create form in users should able create objects of these classes (dogs , cats).

i follows:

http://aoeu.se/so/new-animal-form.png

(i have html , enabling / disabling of input fields implemented.)

to my question: how best implement form processing? don't see how can directly use propertymodels , such since type of model object depends on first dog/cat choice.

if wicket guarantees order in fields processed same order in appear in web page, guess create model object once animal type input processed (since it's first form component), , let remaining fields use propertymodel.

at first should think separating animal type selection rest of form you'll need discard of entries if user decides change type after inputing data. can archieved ajaxifying part of form , using onchange event clean data , switch models.

when so, might want think switching inheritance composition avoid copying data around. don't know if still compatible persistance strategy allways copy finished data persistance layer.

for example when catmodel doesn't inherit animalmodel instead contains animalmodel this:

public class catmodel {      private final animalmodel parent;     private string meowingsound;      public catmodel(animalmodel parent) {         this.parent = parent;     }      public int getnumlegs() {         return parent.getnumlegs();     }      public void setnumlegs(int numlegs) {         parent.setnumlegs(numlegs);     }      public string getmeowingsound() {         return meowingsound;     }      public void setmeowingsound(string meowingsound) {         this.meowingsound = meowingsound;     }      public animalmodel getparent() {         return parent;     }  } 

(interfaces skipped)

you take animalmodel (likewise constructed) dogmodel initialize catmodels 'inherited' data.

public class animalmodel {      private int numlegs;      public int getnumlegs() {         return numlegs;     }      public void setnumlegs(int numlegs) {         this.numlegs = numlegs;     } } 

animalmodel completeness...


Comments