I'm working with a JSF 2.x web application, where we need to support multiple versions of a web form. We now have 2 versions of the form -- form 1 being the original form, and Form 2 having a few new elements and rearranged elements.
My issue is this. In some of the backing beans (which are ManagedBeans), some routines need to do different things based on the Form Number. For instance:
@ManagedBean(name="projectInfoBean")
@SessionScoped
class ProjectInfoBean {
private int hasFlagChanged() {
if(formVersion == 1)
return hasFlagChanged_form1();
else
return hasFlagChanged_form2();
}
}
where hasFlagChanged_form1() and hasFlagChanged_form2() are two similar but different algorithms. hasFlagChanged() is called as part of a Save routine.
Now, we're already considering more changes in the form, so we'd have a new Form Version 3.
Is there a better way to do this kind of thing? Other than a giant if-statement. I was wondering about using the Template Method design pattern, or perhaps Strategy pattern, since the algorithms vary based on the Form Version Number.
What confuses me is how to use design patterns like Template Method, within a JSF ManagedBean like the above example?
What other suggestions might people have?
Thanks
Chris
Aucun commentaire:
Enregistrer un commentaire