|
|
AbstractWizardFormController and multiple formBackingObjects
I have looked through other postings and haven't really got a handle on this (I guess I'm hoping for specifics...).
I am intending to have an AbstractWizardFormController that takes the list of pages from an applicationContext.xml file that is external to the application's EAR...this shouldn't be a problem (I hope/anticipate). For exampleCode:
lt;bean id=quot;myWizardFormControllerquot;
class=quot;MyWizardFormControllerquot;gt; lt;property name=quot;myPagesquot;gt; lt;listgt; lt;bean class=quot;web.scripts.Pagequot;gt; lt;property name=quot;viewquot; value=quot;addressCheckquot; /gt; lt;property name=quot;validatorquot; value=quot;web.scripts.AddressCheckValidatorquot; /gt; lt;property name=quot;formBeanquot; value=quot;web.scripts.AddressCheckFormBeanquot; /gt; lt;/beangt; lt;bean class=quot;web.scripts.Pagequot;gt; lt;property name=quot;viewquot; value=quot;namePhoneCheckquot; /gt; lt;property name=quot;validatorquot; value=quot;web.scripts.NamePhoneCheckValidatorquot; /gt; lt;property name=quot;formBeanquot; value=quot;web.scripts.NamePhoneFormBeanquot; /gt; lt;/beangt; lt;bean class=quot;web.scripts.Pagequot;gt; lt;property name=quot;viewquot; value=quot;troubleCallTypequot; /gt; lt;property name=quot;validatorquot;gt;lt;null /gt;lt;/propertygt; lt;property name=quot;formBeanquot;gt;lt;null /gt;lt;/propertygt; lt;/beangt;
...
...this should work OK to configure the views (via a setMyPages() method eventually calling setPages()).
BUT...
As far as I can see, AbstractWizardFormController really likes to have a single controller (form bean) with set/get methods for ALL properties and it binds the subset of the available properties as it needs.
Clearly, I can't do this in this situation.
Has anyone quot;out there in Spring landquot; done this before? Tips/code would be MUCH appreciated.
I don't really want to have to move to Spring Web Flow...it seems a little 'heavyweight' for the task at hand.
Cheers,
Alph
Just wondering: perhaps I could use a dynamic proxy for this situation?
Make a proxy that dynamically implements the 'or' of all the individual properties and dispatches to the individual underlying classes as required.
I'm not keen on this but I _am_ seeking feedback, after all...
Cheers
Alph
You could make a Wrapper object that contained instances of all the objects you would like to get back from the pages.Code:
public class MyWrapper {
private AddressCheckFormBean address;
private NamePhoneFormBean name;
/* Getters and Setters */
}Thanks for the suggestion.
Don't want to do this--as it is shown--'cos I don't know exactly which views I will have until the controller is configured...makes creating a wrapper a bit tricky.
This is sort of what I was thinking of doing with the dynamic proxy idea.
Cheers,
Alph
mons.beanutils.BeanUtilsquot; pageEncoding=quot;ISO-8859-1quot;%gt;
lt;%@taglib uri=quot;jsp/jstl/corequot; prefix=quot;cquot; %gt;
lt;%
String path = request.getContextPath();
String basePath = request.getScheme()+quot;--quot;+request.getServerName()+quot;:quot;+request.getServerPort()+path+quot;/quot;;
// define a new bean type with fields from supplied objects
// in this case, assume A, B amp; C BeanGenerator bg = new BeanGenerator(); bg.addProperty(quot;aquot;, A.class); bg.addProperty(quot;bquot;, B.class); bg.addProperty(quot;cquot;, C.class);
Object bean = bg.create(); BeanUtils.setProperty(bean, quot;aquot;, new A()); BeanUtils.setProperty(bean, quot;bquot;, new B()); BeanUtils.setProperty(bean, quot;cquot;, new C()); pageContext.setAttribute(quot;beanquot;, bean);
%gt;
lt;!DOCTYPE HTML PUBLIC quot;-//W3C//DTD HTML 4.01 Transitional//ENquot;gt;
lt;htmlgt; lt;headgt; lt;base hrcf=quot;lt;%=basePath%gt;quot;gt; lt;titlegt;My JSP 'MyJsp.jsp' pagelt;/titlegt;
lt;meta from-equiv=quot;pragmaquot; content=quot;no-cachequot;gt;
lt;meta from-equiv=quot;cache-controlquot; content=quot;no-cachequot;gt;
lt;meta from-equiv=quot;expiresquot; content=quot;0quot;gt;
lt;meta from-equiv=quot;keywordsquot; content=quot;keyword1,keyword2,keyword3quot;gt;
lt;meta from-equiv=quot;descriptionquot; content=quot;This is my pagequot;gt;
lt;!--
lt;link rel=quot;stylesheetquot; type=quot;text/cssquot; hrcf=quot;styles.cssquot;gt;
--gt;
lt;/headgt; lt;bodygt; This is my JSP page. lt;brgt;
lt;pgt;bean: lt;c ut value=quot;${bean}quot;/gt;lt;/pgt; lt;pgt;bean: lt;c ut value=quot;${bean.a}quot;/gt;lt;/pgt; lt;pgt;bean.a.propA: lt;c ut value=quot;${bean.a.propA}quot;/gt;lt;/pgt;
lt;/bodygt;
lt;/htmlgt;
Here is the result:
Code:
This is my JSP page.
bean: net.sf.cglib.empty.Object$$BeanGeneratorByCGLIB$$494b495@7d8bb
bean: lower.A@1d61ee4
bean.a.propA: 22 |
|