struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vance Karimi" <vance.kar...@enstinct.com>
Subject Struts-flow and ActionForm
Date Wed, 11 May 2005 03:08:10 GMT
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


Mime
View raw message