hi shirish,
great conceipt and many thanks for example and explanation, my fog seems to thin out 
slowly.
one question remains: as soon as a new form is created, then, i assume, the user's 
inputs are lost. so how do you get hold of the user's input? usually one feeds the 
input data back into a database. with simple beans i copy the formdata to a new 
instantiated dto-bean within my action class and pass the dto-bean to my 
business-layer. but dealing with nested beans, where and how?
sorry for pestering
and thanks a lot in advance
martin 


---------- Urspruengliche Nachricht ------------------------------
Von: <[EMAIL PROTECTED]>
Antworten an: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Datum:  Tue, 20 Jan 2004 13:54:30 +0100

>yes:-))
>And I am sure most of the people do have the same.I mean tieing the nested properties 
>to the session scope does take away a lot of flexibility.
>
>Anyhow just try my sample code...It should demonstrate the concept.
>
>regards,
>Shirish
>
>-----Original Message-----
>From: Mark Lowe [mailto:[EMAIL PROTECTED]
>Sent: Tuesday, January 20, 2004 1:44 PM
>To: Struts Users Mailing List
>Subject: Re: getting data from form with nested beans
>
>
>So you've had forms, with indexed properties with dynamic sizes working  
>when scoping to request?
>
>
>On 20 Jan 2004, at 11:45, <[EMAIL PROTECTED]> wrote:
>
>> Hi,
>> Is it flaming or what?I thought we were trying to solve each others  
>> problems.Still a last try.
>> We have a complete application(3 modules/4000 classes/15 companies  
>> live as of date) which uses all form beans just in request scope.And  
>> all over the place we have used form beans in request scope.And the  
>> application is well and running.
>>
>> If you go t through my mail, you will understand why it will mail.SO  
>> please read the mail carefully.
>> I will try to explain it again.
>>
>> When the form is submitted(the user presses submit button on  
>> screen),the corresponding action will be called by struts.At the same  
>> time, it will look for a actionForm from the mapping.As the scope is  
>> specified as request, a new form will be created.And if you have  
>> looked at my example carefully, you will see that the nested bean list  
>> is created when the form is created.But this nested list is empty.Now  
>> when struts autopopulation tries to populate a nested bean, it should   
>> find that the nested bean list is empty.But the lazy initialization  
>> mechanism in the indexed getter will take care that the list has  
>> enough of beans.See the code below.
>> ****************33
>>  //give indexed access to the beans
>>>>>
>>>>> public Employee getEmployee(int index){
>>>>>
>>>>> //very imp
>>>>>
>>>>> //when a jsp is submited , then while auto populating the form,this
>>>>> will
>>>>> ensure
>>>>> that
>>>>>
>>>>> // the  form is populated properly.
>>>>>
>>>>> while(index >= beanList.size()){
>>>>>
>>>>> beanList.add(new Employee());
>>>>>
>>>>> }
>> ***************************************
>>
>> And as explained in jsp part, as long as the property references are  
>> created properly, this will work.And with struts1.1 nested tags, you  
>> don't have to even use the script<%%> to create property is jsp.
>>
>> Hope this clarifies it.If not, try to run my example code.
>>
>> regards,
>> Shirish
>>
>> -----Original Message-----
>> From: Mark Lowe [mailto:[EMAIL PROTECTED]
>> Sent: Tuesday, January 20, 2004 12:28 PM
>> To: Struts Users Mailing List
>> Subject: Re: getting data from form with nested beans
>>
>>
>> Oh yeah .. by working i mean when you submit..
>>
>>
>> On 20 Jan 2004, at 11:25, Mark Lowe wrote:
>>
>>> .. Show us all an example of a form with a dynamic size for a form
>>> property thats scoped to the request then big shot..
>>>
>>> Come on lets see it!!!
>>>
>>>
>>> On 20 Jan 2004, at 10:45, <[EMAIL PROTECTED]> wrote:
>>>
>>>> The scope of form has nothing to do with usage of nested beans.And
>>>> using session scope shoudl be avaided as far as possible as teh form
>>>> will stay in session  till it is explicitely removed from there..
>>>>
>>>> The <% %> business is for the scripts so that the nested property
>>>> reference can be created.But with struts1.1 , with the usage of
>>>> nested tags, oyu can get rid of that scriptlet code.See nested tags
>>>> for how to do that.I have myself never used nested tags.
>>>>
>>>>
>>>> -----Original Message-----
>>>> From: Mark Lowe [mailto:[EMAIL PROTECTED]
>>>> Sent: Tuesday, January 20, 2004 11:05 AM
>>>> To: Struts Users Mailing List
>>>> Subject: Re: getting data from form with nested beans
>>>>
>>>>
>>>> What's with all the <% %> business? Things to watch out for, method
>>>> names and the object cast to the jsp need to match names (e.g.
>>>> foo.getEmployee() and ${foo.employee}). The form must be scoped to
>>>> session if you are dynamically changing the size of the  indexed
>>>> property.
>>>>
>>>> <html:text name="bean" property="property" indexed="true" />
>>>>
>>>> A better example would be a form bean with a getEmployees() method  
>>>> and
>>>> a setEmployee rather than getBeanList or whatever it was.
>>>>
>>>>
>>>> public Object[] getEmployees() {
>>>>    return emplyeeList.toArray();
>>>> }
>>>>
>>>> public void setEmployees(ArrayList employeeList) {
>>>>    this.employeeList = employeeList;
>>>> }
>>>>
>>>> public Employee getEmployee(int i) {
>>>>    return (Employee) employeeList.get(i);
>>>> }
>>>>
>>>> public void setEmployee(int i,Employee employee) {
>>>>    this.employeeList.add(i,employee);
>>>> }
>>>>
>>>>
>>>> ..
>>>>
>>>> public class Employee {
>>>>    private String name;
>>>>
>>>>    public String getName() {
>>>>            return name;
>>>>    }
>>>>    etc
>>>> }
>>>>
>>>> ..
>>>>
>>>> <logic:iterate id="employee" name="employeeForm"  
>>>> property="employees">
>>>>
>>>>    <html:"text name="employee" property="name" indexed="true" />
>>>>
>>>> </logic:iterate>
>>>>
>>>> or
>>>>
>>>> <c:forEach var="employee" items="${employeeForm.employees}">
>>>>    ..
>>>>
>>>>
>>>>
>>>> On 20 Jan 2004, at 08:56, <[EMAIL PROTECTED]> wrote:
>>>>
>>>>> I am resending my earlier mail on this user list..Go through the
>>>>> sample code
>>>>> and
>>>>> ask me if u don't understand something.
>>>>>
>>>>> The important portions are commented.Especially look at the jsps
>>>>> property
>>>>> how
>>>>> it is set and also the form bean.The property syntax I have used was
>>>>> for struts 1.0 ..But with struts 1.1 , you can have a better cleaner
>>>>> syntax using nested tags.But I have not used it...This works for 1.1
>>>>> as well..
>>>>>
>>>>> ********************************************************
>>>>>
>>>>> //Form Class
>>>>>
>>>>> import java.util.ArrayList;
>>>>>
>>>>> import java.util.List;
>>>>>
>>>>> import org.apache.struts.action.ActionForm;
>>>>>
>>>>> public class ExampleListForm extends ActionForm {
>>>>>
>>>>> //A list of Emp beans
>>>>>
>>>>> private List beanList = new ArrayList();
>>>>>
>>>>> public List getBeanList(){
>>>>>
>>>>> return beanList;
>>>>>
>>>>> }
>>>>>
>>>>> public void setBeanList(List list){
>>>>>
>>>>> beanList = list;
>>>>>
>>>>> }
>>>>>
>>>>> //very imp.
>>>>>
>>>>> //give indexed access to the beans
>>>>>
>>>>> public Employee getEmployee(int index){
>>>>>
>>>>> //very imp
>>>>>
>>>>> //when a jsp is submited , then while auto populating the form,this
>>>>> will
>>>>> ensure
>>>>> that
>>>>>
>>>>> // the  form is populated properly.
>>>>>
>>>>> while(index >= beanList.size()){
>>>>>
>>>>> beanList.add(new Employee());
>>>>>
>>>>> }
>>>>>
>>>>> return (Employee)beanList.get(index);
>>>>>
>>>>> }
>>>>>
>>>>> public void setEmployee(int index,Employee emp){
>>>>>
>>>>> beanList.set(index,emp);
>>>>>
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>> ***********************************************
>>>>>
>>>>> Bean class
>>>>>
>>>>> public class Employee {
>>>>>
>>>>> private String name;
>>>>>
>>>>> private String salary;
>>>>>
>>>>> /**
>>>>>
>>>>> * Returns the name.
>>>>>
>>>>> * @return String
>>>>>
>>>>> */
>>>>>
>>>>> public String getName() {
>>>>>
>>>>> return name;
>>>>>
>>>>> }
>>>>>
>>>>> /**
>>>>>
>>>>> * Returns the salary.
>>>>>
>>>>> * @return String
>>>>>
>>>>> */
>>>>>
>>>>> public String getSalary() {
>>>>>
>>>>> return salary;
>>>>>
>>>>> }
>>>>>
>>>>> /**
>>>>>
>>>>> * Sets the name.
>>>>>
>>>>> * @param name The name to set
>>>>>
>>>>> */
>>>>>
>>>>> public void setName(String name) {
>>>>>
>>>>> this.name = name;
>>>>>
>>>>> }
>>>>>
>>>>> /**
>>>>>
>>>>> * Sets the salary.
>>>>>
>>>>> * @param salary The salary to set
>>>>>
>>>>> */
>>>>>
>>>>> public void setSalary(String salary) {
>>>>>
>>>>> this.salary = salary;
>>>>>
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>> ****************************************
>>>>>
>>>>> JSP
>>>>>
>>>>> <%@ page language="java"%>
>>>>>
>>>>> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
>>>>>
>>>>> <html:html>
>>>>>
>>>>> <html:form action="/" >
>>>>>
>>>>> <logic:iterate id="bean" name="exampleListForm" property="beanList"
>>>>> indexId="i"/>
>>>>>
>>>>> <html:text name="exampleListForm"  property="<%=\"employee[\" + i
>>>>> \"].name\"%>">
>>>>>
>>>>> <html:text name="exampleListForm"  property="<%=\"employee[\" + i
>>>>> \"].salary\"%>">
>>>>>
>>>>> </logic:iterate>
>>>>>
>>>>> </html:form>
>>>>>
>>>>> </html:html>
>>>>>
>>>>> Explanation:
>>>>>
>>>>> See how the property is constructed.
>>>>>
>>>>> <html:text name="exampleListForm"  property="<%=\"employee[\" + i
>>>>> \"].name\"%>">
>>>>>
>>>>> So this will result in a parameter name employee[i].name in the http
>>>>> request.So
>>>>> when the jsp is rendered, this will be interpreted as
>>>>>
>>>>> getEmployee[i].getName().And when the jsp is submitted , the same
>>>>> will
>>>>> be
>>>>> interpreted as getEmployee[i].setName().And this will result in auto
>>>>> population
>>>>> of data in the form as u can see.
>>>>>
>>>>> So check the indexed properties on the form as well.(Especially the
>>>>> getEmployee(index i) proeprty with while loop.)
>>>>>
>>>>> Hope this helps.
>>>>>
>>>>>
>>>>>
>>>>> regards,
>>>>>
>>>>> Shirish.
>>>>>
>>>>>
>>>>> -----Original Message-----
>>>>> From: Mark Lowe [mailto:[EMAIL PROTECTED]
>>>>> Sent: Monday, January 19, 2004 6:18 PM
>>>>> To: Struts Users Mailing List
>>>>> Subject: Re: getting data from form with nested beans
>>>>>
>>>>>
>>>>> Dunno what that thread on lazy lists was but nesting beans should
>>>>> work
>>>>> fine, but you will need to scope any property that you want a  
>>>>> dynamic
>>>>> size to session.
>>>>>
>>>>> Shouldn't be anymore complicated than that.
>>>>>
>>>>>
>>>>> On 19 Jan 2004, at 16:01, Martin Sturzenegger wrote:
>>>>>
>>>>>> hi,
>>>>>> concerning nested properties, i found so many questions, hints etc.
>>>>>> in
>>>>>> the archive but nothing that really helped all the way...i'm still
>>>>>> confused (or even more now...)
>>>>>> i still don't understand how struts handles input from a form that
>>>>>> holds an iteration of nested beans.
>>>>>> is the following correct?
>>>>>> as soon as the user submits the form, the actionform-bean, holding
>>>>>> the
>>>>>> nested beans with the user's changes, gets transmitted.
>>>>>> is it so, that before the action-class is called, the form-bean's
>>>>>> reset() method is called, and all nested beans are set to null by
>>>>>> default?
>>>>>> so do i have to override the reset() method?
>>>>>> what do i iterate over in the reset() method to get the user's
>>>>>> inputs?
>>>>>> how do i limit the iteration?
>>>>>> does the validate() method gets called before the reset method?.
>>>>>>
>>>>>> i've seen examples, where a dto-class is instanciated within the
>>>>>> reset() method.
>>>>>> is this the way to do it?
>>>>>> do i have to access these dto-beans in the action class?
>>>>>>
>>>>>> could somebody give me a little example of a reset()-method, just  
>>>>>> to
>>>>>> show how the user's input can be gathered and then stored away?
>>>>>>
>>>>>> and.. what are lazy lists? i wasn't able to find a definition....
>>>>>>
>>>>>> sorry about it but
>>>>>>
>>>>>> regards from an utterly confused martin
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> ---------- Urspruengliche Nachricht ------------------------------
>>>>>> Von: <[EMAIL PROTECTED]>
>>>>>> Datum:  Mon, 19 Jan 2004 10:52:10 +0100
>>>>>>
>>>>>>> You ahve a fixed length or Empty list in the form.So when the auto
>>>>>>> population tries to populate the nested bean for the list which is
>>>>>>> empty/fixed size,you get this exception.
>>>>>>> Try to use lazy list or search the archive for nested property
>>>>>>> usage...There are many examples which will demonatrate how to use
>>>>>>> it.
>>>>>>>
>>>>>>> HTH.
>>>>>>> regards,
>>>>>>> Shirish
>>>>>>>
>>>>>>> -----Original Message-----
>>>>>>> From: Martin Sturzenegger
>>>>>>> [mailto:[EMAIL PROTECTED]
>>>>>>> Sent: Monday, January 19, 2004 10:46 AM
>>>>>>> To: Struts Users Mailing List; [EMAIL PROTECTED]; Struts
>>>>>>> Users
>>>>>>> Mailing List
>>>>>>> Subject: Re: Including one JSP in another
>>>>>>>
>>>>>>>
>>>>>>> i try to receive user-input from a form using a list of nested
>>>>>>> beans.
>>>>>>> after hitting submit i get an ArrayIndexOutOfBoundsException
>>>>>>> can somebody give me a hint?
>>>>>>> many thanks
>>>>>>> martin
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> stacktrace:
>>>>>>>
>>>>>>> java.lang.ArrayIndexOutOfBoundsException
>>>>>>>         java.lang.reflect.Array.get(Native Method)
>>>>>>>         
>>>>>>> org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(Prop 
>>>>>>> e
>>>>>>> rt
>>>>>>> y
>>>>>>> Utils.java:525)
>>>>>>>         
>>>>>>> org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(Prop 
>>>>>>> e
>>>>>>> rt
>>>>>>> y
>>>>>>> Utils.java:428)
>>>>>>>         
>>>>>>> org.apache.commons.beanutils.PropertyUtils.getNestedProperty(Prope 
>>>>>>> r
>>>>>>> ty
>>>>>>> U
>>>>>>> tils.java:770)
>>>>>>>         
>>>>>>> org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUti 
>>>>>>> l
>>>>>>> s.
>>>>>>> j
>>>>>>> ava:801)
>>>>>>>          
>>>>>>> org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:
>>>>>>> 881)
>>>>>>>         org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:
>>>>>>> 808)
>>>>>>>         org.apache.struts.util.RequestUtils.populate(RequestUtils.java:
>>>>>>> 1252)
>>>>>>>         
>>>>>>> org.apache.struts.action.RequestProcessor.processPopulate(RequestP 
>>>>>>> r
>>>>>>> oc
>>>>>>> e
>>>>>>> ssor.java:821)
>>>>>>>         
>>>>>>> org.apache.struts.action.RequestProcessor.process(RequestProcessor 
>>>>>>> .
>>>>>>> ja
>>>>>>> v
>>>>>>> a:254)
>>>>>>>          
>>>>>>> org.apache.struts.action.ActionServlet.process(ActionServlet.java:
>>>>>>> 1482)
>>>>>>>         org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:
>>>>>>> 525)
>>>>>>>         javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
>>>>>>>         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Confidentiality Notice
>>>>>>>>>>>
>>>>>>>>>>> The information contained in this electronic message and any
>>>>>>>> attachments
>>>>>>>>>>> to this message are intended
>>>>>>>>>>> for the exclusive use of the addressee(s) and may contain
>>>>>>>>>>> confidential
>>>>>>>>>>> or privileged information. If
>>>>>>>>>>> you are not the intended recipient, please notify the sender  
>>>>>>>>>>> at
>>>>>>>>>>> Wipro
>>>>>>>> or
>>>>>>>>>>> [EMAIL PROTECTED] immediately
>>>>>>>>>>> and destroy all copies of this message and any attachments.
>>>>>>>>>>>
>>>>>>>>>>> -------------------------------------------------------------- 
>>>>>>>>>>> -
>>>>>>>>>>> --
>>>>>>>>>>> -
>>>>>>>>>>> ---
>>>>>>>>>>> To unsubscribe, e-mail:
>>>>>>>>>>> [EMAIL PROTECTED]
>>>>>>>>>>> For additional commands, e-mail:
>>>>>>>>>>> [EMAIL PROTECTED]
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Confidentiality Notice
>>>>>>>>>>>
>>>>>>>>>>> The information contained in this electronic message and any
>>>>>>>> attachments
>>>>>>>>>> to this message are intended
>>>>>>>>>>> for the exclusive use of the addressee(s) and may contain
>>>>>>>>>>> confidential
>>>>>>>>> or
>>>>>>>>>> privileged information. If
>>>>>>>>>>> you are not the intended recipient, please notify the sender  
>>>>>>>>>>> at
>>>>>>>>>>> Wipro
>>>>>>>> or
>>>>>>>>>> [EMAIL PROTECTED] immediately
>>>>>>>>>>> and destroy all copies of this message and any attachments.
>>>>>>>>>>>
>>>>>>>>>>> -------------------------------------------------------------- 
>>>>>>>>>>> -
>>>>>>>>>>> --
>>>>>>>>>>> -
>>>>>>>>>>> ---
>>>>>>>>>>> To unsubscribe, e-mail:
>>>>>>>>>>> [EMAIL PROTECTED]
>>>>>>>>>>> For additional commands, e-mail:
>>>>>>>>>>> [EMAIL PROTECTED]
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --------------------------------------------------------------- 
>>>>>>>>>> -
>>>>>>>>>> --
>>>>>>>>>> -
>>>>>>>>>> --
>>>>>>>>>> To unsubscribe, e-mail:
>>>>>>>>>> [EMAIL PROTECTED]
>>>>>>>>>> For additional commands, e-mail:
>>>>>>>>>> [EMAIL PROTECTED]
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ---------------------------------------------------------------- 
>>>>>>>>> -
>>>>>>>>> --
>>>>>>>>> -
>>>>>>>>> -
>>>>>>>>> To unsubscribe, e-mail:
>>>>>>>>> [EMAIL PROTECTED]
>>>>>>>>> For additional commands, e-mail:
>>>>>>>>> [EMAIL PROTECTED]
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> ----------------------------------------------------------------- 
>>>>>>>> -
>>>>>>>> --
>>>>>>>> -
>>>>>>>> To unsubscribe, e-mail:  
>>>>>>>> [EMAIL PROTECTED]
>>>>>>>> For additional commands, e-mail:
>>>>>>>> [EMAIL PROTECTED]
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ------------------------------------------------------------------ 
>>>>>>> -
>>>>>>> --
>>>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>>>>> For additional commands, e-mail:
>>>>>>> [EMAIL PROTECTED]
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> ------------------------------------------------------------------- 
>>>>>> -
>>>>>> -
>>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>>>> For additional commands, e-mail:  
>>>>>> [EMAIL PROTECTED]
>>>>>>
>>>>>
>>>>>
>>>>> -------------------------------------------------------------------- 
>>>>> -
>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>>
>>>>>
>>>>> -------------------------------------------------------------------- 
>>>>> -
>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
 
                 

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

Reply via email to