Hi,

I resolved the same problem in two different ways:

1) I just instantiate the desired action form (new MyActionForm()), fill it up
   and store it as an attribute in the request or session.
   --> works but had some quirks...

2) Just define the action as if it would be called from a jsp that could 
   populate the action form. Meaning define the action-mapping with the action-form
   parameters. Be sure to specify validate=false! Struts will now instantiate the
   action form and try to populate it (not finding any parameters...) and then you 
   can populate it in your action and forward to the desired jsp.
   --> works

sample action-mapping:
-----
    <!-- show a validated entry form: this one is called using GET from a menu -->
    <action    path="/intializeValidated"
               type="com.csg.cs.jst.strutssample.control.ValidatedAction"
               name="validatedForm"
               input="/validated.jsp"     <!-- must be here, but is not relevant -->
               validate="false"
               scope="session"
               parameter="initialize">
      <forward name="show"              path="/validated.jsp"/>
    </action>

    <!-- evaluate validated-entry form action: this one processes, what above creates 
-->
    <action    path="/evaluateValidated"
               type="com.csg.cs.jst.strutssample.control.ValidatedAction"
               name="validatedForm"
               input="/validated.jsp"
               validate="true"
               scope="session"
               parameter="evaluate">
      <forward name="success"              path="/validated.jsp"/>
      <forward name="errors"               path="/validated.jsp"/>
    </action>
-----

hope this helps
Alexander Jesse

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 24, 2001 2:59 AM
To: [EMAIL PROTECTED]
Subject: Creating your own ActionForm inside of an Action


Hi everyone,

I have a situation in which I would like to do the following:

1) I'm at a jsp page, let's call it "a.jsp".  It has one link that looks
like:
        
        <html:link page="/mainMenu.do?action=customer"> Customer
</html:link>

2) My mainMenu action in struts-config.xml looks like (name="..." is
left out on purpose):

  <action       path="/mainMenu"
                type="net.alfa.china.menus.MainMenuAction">
        <forward name="customer" path="/customer_main.jsp"/>
        <forward name="order" path="/order_main.jsp"/>
        <forward name="purchase" path="/purchase_main.jsp" />
        <forward name="inventory" path="/inventory_main.jsp" />
  </action>


3) Inside of perform in MainMenuAction, I would like to create my own
form bean of type ActionForm.  I am then going to load a customer from
my db (through a business logic bean), and set the fields in the
ActionForm.  I'm hoping to use that ActionForm to populate a form in
"customer_main.jsp" when we finally forward there.  That form is defined
using <html:form>.

I'm basically wondering what the mechanism is that struts uses to
populate a <html:form> with an ActionForm.  I'm coming from a page
without a form (a.jsp), would like to be able to create an ActionForm in
perform(), stick it in the request, and when I forward to my
customer_main.jsp, have struts populate the form there with what's in
the ActionForm.

I've tried quite a few different approaches and can't seem to make it
work.  Is this possible?  Any suggestions?

Thanks,

Tony Li

Reply via email to