Ian Beaumont <[EMAIL PROTECTED]> writes:

> This means that in the action for the "select item" I need to get
> hold of the form bean for the next page I'm going to so I can
> populate it.

You'll need to pass the ID of the selected item to the action.  So
your "selection view" will have something like this in it:

<logic:iterate id="item" name="formBeanName" property="items">
  <html:link page="/edit.do" paramId="id" paramName="item">
    <bean:write name="item">
  </html:link>
</logic:iterate>

> 1. How do I get hold of the form bean?  Do I create it myself?

No.  The struts controller will create it and pass it to the perform
method of an instance of the class identified by the "type" attribute
in the "/edit" action in struts-config.  That perform method will get
the "id" parameter from the request, get the item's values from
somewhere and populate the formbean.

> 2. This all relies on me knowing the mappings of what page I'm going
> to go to next so I can populate the form bean.  This defeats the
> object of having the struts-XML file.

Not exactly.  You do have to know which "action" you're going to next,
but struts-config allows you to change which classes and views are
used to perform that action.  And your action class obviously needs to
know what kind of formbean to expect so that it can downcast it
appropriately, but there's nothing stopping you from casting it to an
interface or abstract class which the classes specified in
struts-config must implement.  You may need that level of "polymorphic
flexibility" in your app, but from my experience you won't.

> Below is the text from a previous email I sent.  The only reply I
> got was the example didn't show 'best practises'.  In which case,
> what is the best practise.

The example accounts for a missing "name" attribute in the
corresponding action element in struts-config.  The best practice is
to include a "name" attribute in struts-config so that your action
doesn't have to do that.

-- Jim

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to