struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Don Brown <donald.br...@gmail.com>
Subject Re: Struts-flow and ActionForm
Date Wed, 11 May 2005 15:23:46 GMT
This is the tricky part I haven't worked out yet with Struts Flow -
smooth ActionForm integration.  By forcing you to customize the
populate and validate methods, it does allow you to have complete
control of how your form is interacted with.  For ActionForms, the
populate would be a call to BeanUtils (see
o.a.s.c.c.PopulateActionForm or something like that) and the validate
would probably just call the form's validate method.

Unfortunately, Struts Flow can't really use the built-in Struts
population/validation because Struts gets its cue to populate/validate
from the action mapping, and with Struts Flow, an whole wizard would
have one action mapping.  You could, perhaps, name the form in your
action mapping, but turn validation off, so you might try that.

As for working with the taglibs, all they need is a bean at the
specified id.  This bean actually doesn't need to be an instance of
ActionForm and could be a simple Map or Javabean.

My usage of the Struts Flow wizard library uses an XML element (JDOM)
as my model then JXPath to set its values using xpath expressions.  I
can then use XML schema, schematron, or any other XML validation
library to validate my form.

Don

On 5/10/05, Vance Karimi <vance.karimi@enstinct.com> wrote:
> Hi list,
> 
> I picked up Struts-flow and decided to go with it basically to have
> multi-page form wizards.  Looks like a really helpful tool. Kudos.
> 
> The example uses a HashMap to model the information submitted by the forms.
> The wizard example states "To keep simple, no Struts JSP tags are used, but
> could be by wrapping model with an ActionForm".  I do use struts tags and
> ActionForms and was hoping someone would have an example or a guide.
> 
> The way I do things now is:
> 
> My struts action:
> 
> <action
>         path="/path/to/MainAction"
>         type="net.sf.struts.flow.FlowAction"
>         name="MainForm"
>         input="/path/to/APage.jsp"
>         className="net.sf.struts.flow.FlowMapping"
>         validate="false">
> 
>     <set-property property="function" value="main"/>
> 
>     <forward name="a-form"
>           path="/path/to/AAction.jspa"/>
>     <forward name="type-form"
>           path="/path/to/BAction.jspa"/>
>     <forward name="cc-form"
>           path="/path/to/CAction.jspa"/>
> </action>
> 
> My struts plugin:
> 
>   <plug-in className="net.sf.struts.flow.FlowPlugIn">
>     <set-property property="scripts" value="/WEB-INF/wizard-flow.js" />
>     <set-property property="debugger" value="false" />
>     <set-property property="reloadScripts" value="true" />
>     <set-property property="checkTime" value="1" />
>     <set-property property="timeToLive" value="600000" />
>   </plug-in>
> 
> My wizard-flow.js:
> 
> importPackage(Packages.java.util);
> context.load("/WEB-INF/wizard.js");
> 
> function main() {
>   var model = new HashMap();
> 
>   var wizard = new Wizard(model);
> 
>   wizard.populate = populate;
>   wizard.validate = validate;
> 
>   wizard.showForm("a-form", {
>                   "title" : "Event Information"
>                   });
>   wizard.showForm("b-form", {
>                   "title" : "Schedules and Type Information"
>                   });
>   wizard.showForm("c-form", {
>                   "title" : "Credit Card Information"
>                   });}
> 
> function populate() {
>   m = context.chainContext.paramValues;
>   for (i = m.keySet().iterator(); i.hasNext(); ) {
>     key = i.next();
>     this.model.put(key, m.get(key)[0]);
> 
>   }
> }
> 
> function validate() {
> }
> 
> The wizard-flow.js is no different to the example, so I store the form
> elements in the Map model. My understanding is I should use a map-backed
> ActionForm as the model rather than the HashMap. Is this correct? I tried
> that, but had no luck.
> 
> Within my Action:
> 
> public ActionForward doExecute(
>     ActionMapping mapping,
>     ActionForm form,
>     HttpServletRequest request,
>     HttpServletResponse response)
>     throws IOException, ServletException {
> 
>     ....
> 
>     Map map = (Map) request.getAttribute("form");
>     if (map.get("elementA") != null) {
>         myForm.setElementA((String) map.get("elementA"));
>     }
> 
>     ....
> }
> 
> To get the wizard working and avoid "wrapping the model with an ActionForm",
> I use the above in my Actions, but I'm not sure if this is the right way to
> do things.
> 
> I look forward to your suggestions,
> Vance
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message