You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <ma...@reumann.net> on 2002/07/17 17:24:10 UTC

Re[3]: getting nested tags to work with DynaActionForm???

Craig and company,

I'll comment some more below but I want to first explain what needs to
be set up and handled. I have an ArrayList of beans. Each bean in this
ArrayList also contains an ArrayList of String object. On my JSP I'm
using the nested tag (new to using it- bannana stuff very helpful
Arron) to create the dynamically created form. ( Picture a JSP that
was to display a dynamic list of cars and for each car there would be
list of particular styles you could pick from).

On Tuesday, July 16, 2002, 10:45:11 PM, Craig wrote:

CRM> If you're using request scope beans, a new instance gets created on every
CRM> request.  And I will bet that you probably have an initialization of this
CRM> array happening in your constructor, or in an initialization expression,
CRM> right?

     Yes, I believe so. A DTO is populated with the ArrayList of beans
     and then the DTO is converted to the DynaActionForm which is set
     into request scope. (The nested tag and display of the
     information on the page is working beautifully..problem is upon
     submission).


>>        What if the information in an ArrayList of beans that you want in a
>>        DynaActionForm is to first be populated by some database info.
>>        Do you need to first initialize it like a above to a bunch of
>>        nulls? If so what if the list size fluctuates (hence use of
>>        ArrayList) how do you know how many to initialize the ArrayList
>>        with?
>>

CRM> That's definitely a place where loading the arrays in the reset() method
CRM> makes sense.

     Ok, well what I've done is added this to the base class that my
     DynaActionForm (actually DynaValidatorForm) extends (Roman on
     this list was helping me with this) (20 is just an arbitrary
     number greater than the amount that would be displayed on the
     form):

public class UserDynaForm extends DynaValidatorForm {
    public void reset( ActionMapping mapping, HttpServletRequest request ) {
        ArrayList applicationGroups = new ArrayList();
        for (int i=0; i < 20; i++) {
            ApplicationGroupBean b = new ApplicationGroupBean();
            b.setRoles( new ArrayList() );
            applicationGroups.add(b);
        }
        set("applicationGroups", applicationGroups);
    }
}     

I then still have in my struts-config, for this form:
<form-bean name="userForm"
            dynamic="true"
            type="corporate.userAdmin.UserDynaForm">:
            <form-property name="applicationGroups" type="java.util.ArrayList"/>
            ....

The page will display the initial information fine. When I submit now,
however, the problem is it's trying to submit nulls. It's as if it
doesn't pick up what was selected on the JSP and this reset is wiping
out what was selected?

I'm sure I'm missing something simple so sorry for my ignorance. I
guess what is so odd is that when I switch to using a standard
ActionForm I don't have to override the reset and the page submits
fine.

Thanks for the help.

-- 

Rick
mailto:maillist@reumann.net


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re[4]: getting nested tags to work with DynaActionForm???

Posted by Rick Reumann <ma...@reumann.net>.
Actually I just realized part of the problem below is/was is that even
using the standard ActionForm I can't seem to get the nested ArrayList
stuff to take upon submission unless I give the form session scope.

I'm sure this question has been answered before so I'll look in the
archives ( although I must admit the searching ability on the archives
for this struts list is not the greatest )

If someone does have comments don't hesitate to send them.
Thanks
Rick

On Wednesday, July 17, 2002, 11:24:10 AM, Rick wrote:

RR> Craig and company,

RR> I'll comment some more below but I want to first explain what needs to
RR> be set up and handled. I have an ArrayList of beans. Each bean in this
RR> ArrayList also contains an ArrayList of String object. On my JSP I'm
RR> using the nested tag (new to using it- bannana stuff very helpful
RR> Arron) to create the dynamically created form. ( Picture a JSP that
RR> was to display a dynamic list of cars and for each car there would be
RR> list of particular styles you could pick from).

RR> On Tuesday, July 16, 2002, 10:45:11 PM, Craig wrote:

CRM>> If you're using request scope beans, a new instance gets created on every
CRM>> request.  And I will bet that you probably have an initialization of this
CRM>> array happening in your constructor, or in an initialization expression,
CRM>> right?

RR>      Yes, I believe so. A DTO is populated with the ArrayList of beans
RR>      and then the DTO is converted to the DynaActionForm which is set
RR>      into request scope. (The nested tag and display of the
RR>      information on the page is working beautifully..problem is upon
RR>      submission).


>>>        What if the information in an ArrayList of beans that you want in a
>>>        DynaActionForm is to first be populated by some database info.
>>>        Do you need to first initialize it like a above to a bunch of
>>>        nulls? If so what if the list size fluctuates (hence use of
>>>        ArrayList) how do you know how many to initialize the ArrayList
>>>        with?
>>>

CRM>> That's definitely a place where loading the arrays in the reset() method
CRM>> makes sense.

RR>      Ok, well what I've done is added this to the base class that my
RR>      DynaActionForm (actually DynaValidatorForm) extends (Roman on
RR>      this list was helping me with this) (20 is just an arbitrary
RR>      number greater than the amount that would be displayed on the
RR>      form):

RR> public class UserDynaForm extends DynaValidatorForm {
RR>     public void reset( ActionMapping mapping, HttpServletRequest request ) {
RR>         ArrayList applicationGroups = new ArrayList();
RR>         for (int i=0; i < 20; i++) {
RR>             ApplicationGroupBean b = new ApplicationGroupBean();
RR>             b.setRoles( new ArrayList() );
RR>             applicationGroups.add(b);
RR>         }
RR>         set("applicationGroups", applicationGroups);
RR>     }
RR> }     

RR> I then still have in my struts-config, for this form:
RR> <form-bean name="userForm"
RR>             dynamic="true"
RR>             type="corporate.userAdmin.UserDynaForm">:
RR>             <form-property name="applicationGroups" type="java.util.ArrayList"/>
RR>             ....

RR> The page will display the initial information fine. When I submit now,
RR> however, the problem is it's trying to submit nulls. It's as if it
RR> doesn't pick up what was selected on the JSP and this reset is wiping
RR> out what was selected?

RR> I'm sure I'm missing something simple so sorry for my ignorance. I
RR> guess what is so odd is that when I switch to using a standard
RR> ActionForm I don't have to override the reset and the page submits
RR> fine.

RR> Thanks for the help.


-- 

Rick
mailto:maillist@reumann.net


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>