RE: what setters do i implement in an indexed tag--NewBie question
John Made few changes and code worked fine. Would like to extend this so that it will work for handling Dynamic table situation-- Let me explain If u see in Action form reset method I initialized it to 5 (num="5 "for testing) so the page loads with five empty rows, But we have a requirement where the user can add more rows to the table and click submit. 1. Action form code: private ArrayList personList; public void reset(ActionMapping mapping, HttpServletRequest request){ this.personList = new ArrayList(); // String num = request.getParameter("personListLength"); String num ="5"; try { if (num != null) { int len = Integer.parseInt(num); for (int i = 0; i < len; i++) this.personList.add(new PersonBean()); } }catch (NumberFormatException e) { e.printStackTrace(); } } public PersonBean getPerson(int ndx) { return (PersonBean) personList.get(ndx); } public void setPersonList(int ndx, PersonBean p) { personList.set(ndx, p); } public ArrayList getPersonList(){ return this.personList; } 2. jsp 3.PersonBean: public class PersonBean implements Serializable { String firstName; String phoneNo; public PersonBean() { super(); } public String getFirstName() { return firstName; } public void setFirstName(String newFirstName) { firstName = newFirstName; } public String getPhoneNo() { return phoneNo; } public void setPhoneNo(String newPhoneNo) { phoneNo = newPhoneNo; } } Let me know if u need any further info. Thanks >>> [EMAIL PROTECTED] 06/12/03 01:57PM >>> I believe indexed attributes were first, then Arron contributed nested and life got easier. Stick with it and don't go backwards. -john -Original Message- From: Adam Hardy [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 11:52 PM To: Struts Users Mailing List Subject: Re: what setters do i implement in an indexed tag --NewBie question Sashi, your person bean must have getName(), setName() and getPhoneNo(), setPhoneNo(). Everybody: I haven't come across the html:taglib indexed property before. This seems to do what nested: tags do - is this functional overlap? Generally with JST taglib as well, there seems to be a wide choice of taglibs to use - is this going to consolidate at some point in struts' development? Adam Sashi Ravipati wrote: > Can some body help in as how to define get and set methods when we use indexed tags. > > eg: > > > > > > > > > > > > > > What will be the get and set methods. > > Thanks > - 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]
RE: what setters do i implement in an indexed tag --NewBie question
I believe indexed attributes were first, then Arron contributed nested and life got easier. Stick with it and don't go backwards. -john -Original Message- From: Adam Hardy [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 11:52 PM To: Struts Users Mailing List Subject: Re: what setters do i implement in an indexed tag --NewBie question Sashi, your person bean must have getName(), setName() and getPhoneNo(), setPhoneNo(). Everybody: I haven't come across the html:taglib indexed property before. This seems to do what nested: tags do - is this functional overlap? Generally with JST taglib as well, there seems to be a wide choice of taglibs to use - is this going to consolidate at some point in struts' development? Adam Sashi Ravipati wrote: > Can some body help in as how to define get and set methods when we use indexed tags. > > eg: > > > > > > > > > > > > > > What will be the get and set methods. > > Thanks > - 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]
RE: what setters do i implement in an indexed tag--NewBiequestion
John Made few changes and code worked fine. Would like to extend this so that it will work for handling Dynamic table situation-- Let me explain If u see in Action form reset method I initialized it to 5 (num="5 "for testing) so the page loads with five empty rows, But we have a requirement where the user can add more rows to the table and click submit. Action form code: private ArrayList personList; public void reset(ActionMapping mapping, HttpServletRequest request){ this.personList = new ArrayList(); // String num = request.getParameter("personListLength"); String num ="5"; try { if (num != null) { int len = Integer.parseInt(num); for (int i = 0; i < len; i++) this.personList.add(new PersonBean()); } }catch (NumberFormatException e) { e.printStackTrace(); } } .jsp public PersonBean getPerson(int ndx) { return (PersonBean) personList.get(ndx); } public void setPersonList(int ndx, PersonBean p) { personList.set(ndx, p); } public ArrayList getPersonList(){ return this.personList; } PersonBean: public class PersonBean implements Serializable { String firstName; String phoneNo; public PersonBean() { super(); } public String getFirstName() { return firstName; } public void setFirstName(String newFirstName) { firstName = newFirstName; } public String getPhoneNo() { return phoneNo; } public void setPhoneNo(String newPhoneNo) { phoneNo = newPhoneNo; } } Let me know if u need any further info. Thanks >>> [EMAIL PROTECTED] 06/11/03 06:45PM >>> Forgot to mention, I believe for the case of indexing using logic:iterate your id must match your property. So in your example set id="personList" Now if you switch over to nested:iterate, the whole id thing goes away and the property and type attributes are sufficient. -john -Original Message- From: John Greenhill [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 3:37 PM To: Struts Users Mailing List Subject: RE: what setters do i implement in an indexed tag --NewBiequestion Assuming you're NOT using the lazy initialization, you could do it like this... 1) your iterate will need to specify the type of the nested class: mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 1:19 PM To: [EMAIL PROTECTED] Subject: what setters do i implement in an indexed tag --NewBiequestion Can some body help in as how to define get and set methods when we use indexed tags. eg: What will be the get and set methods. Thanks - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: what setters do i implement in an indexed tag --NewBiequestion
I would have a extend ActionForm have a getPersonList which returns a collection of Person objects which does not extend the ActionForm struts-config has wrote: > John > > Thanks for all the code u sent. I have started > working on it, and I had > few questions (PLS bear with me if they look > stupid). > > 1. PersonForm (which extends ActionForm) will have > get and set methods > for Name and Phone Number? This PersonForm is also > initialized in > Struts-Config.xml > > 2. IS myFormBean another bean which extends > ActionForm ? Do I need to > set this also in my Struts-Config.xml > > Thanks > > > > >>> [EMAIL PROTECTED] 06/11/03 06:45PM > >>> > Forgot to mention, I believe for the case of > indexing using > logic:iterate your id must match your property. So > in your example set > id="personList" > > Now if you switch over to nested:iterate, the whole > id thing goes away > and the property and type attributes are sufficient. > > -john > > -Original Message- > From: John Greenhill > [mailto:[EMAIL PROTECTED] > Sent: Wednesday, June 11, 2003 3:37 PM > To: Struts Users Mailing List > Subject: RE: what setters do i implement in an > indexed tag > --NewBiequestion > > > Assuming you're NOT using the lazy initialization, > you could do it like > this... > > > > 1) your iterate will need to specify the type of the > nested class: > > property="personList" > type="com.mydom.myproject.struts.Person> > > Where the Person class has just the standard > accessors for name and > phoneNo. > > > 2) Your myFormBean will have the special accessors > for indexing: > > // SPECIAL ACCESSORS FOR INDEXING NEEDED > public Person getPersonList(int ndx) { > return (PersonForm) personList.get(ndx); > } > public void setPersonList(int ndx, PersonForm p) > { > personList.set(ndx, p); > } > > > 3) Assuming you don't already know the size of your > personList, your > reset method > will initialize it and create the empty Person > objects to fill with the > data: > > public void reset(ActionMapping mapping, > HttpServletRequest request) > { > > this.personList = new ArrayList(); > > String num = > request.getParameter("personListLength"); > try { > if (num != null) { > int len = Integer.parseInt(num); > for (int i = 0; i < len; i++) > this.personList.add(new > PersonForm()); > } > } catch (NumberFormatException e) { > //... > } > } > > This assumes the prep action that entered the jsp > figured out the size > of the list > and set it into a hidden in the jsp in a field named > personListLength. > > -john > > -Original Message- > From: Sashi Ravipati [mailto:[EMAIL PROTECTED] > Sent: Wednesday, June 11, 2003 1:19 PM > To: [EMAIL PROTECTED] > Subject: what setters do i implement in an indexed > tag --NewBiequestion > > > Can some body help in as how to define get and set > methods when we use > indexed tags. > > eg: > > property="personList"> > > > >indexed="true"/> > > >indexed="true"/> > > > > > What will be the get and set methods. > > Thanks > > - > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > __ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: what setters do i implement in an indexed tag--NewBiequestion
John Thanks for all the code u sent. I have started working on it, and I had few questions (PLS bear with me if they look stupid). 1. PersonForm (which extends ActionForm) will have get and set methods for Name and Phone Number? This PersonForm is also initialized in Struts-Config.xml 2. IS myFormBean another bean which extends ActionForm ? Do I need to set this also in my Struts-Config.xml Thanks >>> [EMAIL PROTECTED] 06/11/03 06:45PM >>> Forgot to mention, I believe for the case of indexing using logic:iterate your id must match your property. So in your example set id="personList" Now if you switch over to nested:iterate, the whole id thing goes away and the property and type attributes are sufficient. -john -Original Message- From: John Greenhill [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 3:37 PM To: Struts Users Mailing List Subject: RE: what setters do i implement in an indexed tag --NewBiequestion Assuming you're NOT using the lazy initialization, you could do it like this... 1) your iterate will need to specify the type of the nested class: mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 1:19 PM To: [EMAIL PROTECTED] Subject: what setters do i implement in an indexed tag --NewBiequestion Can some body help in as how to define get and set methods when we use indexed tags. eg: What will be the get and set methods. Thanks - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: what setters do i implement in an indexed tag --NewBie question
Sashi, your person bean must have getName(), setName() and getPhoneNo(), setPhoneNo(). Everybody: I haven't come across the html:taglib indexed property before. This seems to do what nested: tags do - is this functional overlap? Generally with JST taglib as well, there seems to be a wide choice of taglibs to use - is this going to consolidate at some point in struts' development? Adam Sashi Ravipati wrote: Can some body help in as how to define get and set methods when we use indexed tags. eg: What will be the get and set methods. Thanks - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: what setters do i implement in an indexed tag --NewBiequestion
Forgot to mention, I believe for the case of indexing using logic:iterate your id must match your property. So in your example set id="personList" Now if you switch over to nested:iterate, the whole id thing goes away and the property and type attributes are sufficient. -john -Original Message- From: John Greenhill [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 3:37 PM To: Struts Users Mailing List Subject: RE: what setters do i implement in an indexed tag --NewBiequestion Assuming you're NOT using the lazy initialization, you could do it like this... 1) your iterate will need to specify the type of the nested class: mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 1:19 PM To: [EMAIL PROTECTED] Subject: what setters do i implement in an indexed tag --NewBiequestion Can some body help in as how to define get and set methods when we use indexed tags. eg: What will be the get and set methods. Thanks - 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]
RE: what setters do i implement in an indexed tag --NewBiequestion
Assuming you're NOT using the lazy initialization, you could do it like this... 1) your iterate will need to specify the type of the nested class: mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 1:19 PM To: [EMAIL PROTECTED] Subject: what setters do i implement in an indexed tag --NewBiequestion Can some body help in as how to define get and set methods when we use indexed tags. eg: What will be the get and set methods. Thanks - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: what setters do i implement in an indexed tag ?
I'm following closely Dave's example code and almost have it working, except that on post of the JSP form the parameter's values (which are correct) are not stored in the Formbean's list. So seem to have had the same problem and solved it. However, I fail to see what the difference between your 'hacked' version and Dave's original code is. Please enlighten me. TIA Marcel > -Oorspronkelijk bericht- > Van: Warwick Boote [mailto:[EMAIL PROTECTED]] > Verzonden: woensdag 25 juli 2001 17:13 > Aan: [EMAIL PROTECTED] > Onderwerp: RE: what setters do i implement in an indexed tag ? > > > Here is a hacked version of the code posted by David Hay previously. The > code here will compile and run - a Vector is populated then displayed. > After a post, the vector is retrieved from the form and then System.out is > used to show its size. > > This should help others that are having problems with indexed > tags. You'll > need to point your browser to somthing that looks like > http://localhost/struts/ShowParameters.do once you've copied all the files > into the correct locations. > > There were two issues with the way i was trying to do it, firstly > it seems that unless the scope of the form is set to session (or > not specified) it doesn't work and secondly because i was using a > different id for the name in the logic:iterate / html:text tags > (when i set them to > "parameter" it worked). > > property="parameterList"> >indexed="true"/> > > > > type="com.eurobenefits.dta.presentation.FieldsMapAction" >scope="session" >name="FieldsMapForm" >validate="false"> > path="/DefineFieldMappings.jsp"/> > > > Waz. > =) > > -Original Message- > From: Warwick Boote [mailto:[EMAIL PROTECTED]] > Sent: 24 July 2001 14:09 > To: [EMAIL PROTECTED] > Subject: what setters do i implement in an indexed tag ? > > > I've created a page using indexed tags (neat stuff!). > Here is what is currently working for me: > o If i populate the form's vector, values from that vector are > displayed in > the jsp > Here is what it not working: > o when the form is posted back, the vector is null (in the struts > perform() > method) > I suspect i haven't implemented some sort of setter within the form but i > can't find an example as to what method should be implemented. I've tried > ArrayList and using parameterList instead with no different result. > Thanks, > Waz. > =) > Here are some code snippits for help: > ---jsp--- > property="fieldMappings"> > > > ---Form--- > public class FieldsMapForm extends ActionForm { > private String fileColCount; > private java.util.Vector fieldMappings = new java.util.Vector(); > private String action; > public String getFileColCount() { > return fileColCount; > } > public void setFileColCount(String newFileColCount) { > fileColCount = newFileColCount; > } > public void setFieldMappings(java.util.Vector newFieldMappings) { > fieldMappings = newFieldMappings; > } > public java.util.Vector getFieldMappings() { > return fieldMappings; > } > public FieldMapping getParameter(int index) { > return (FieldMapping)fieldMappings.elementAt(index); > } > public void setAction(String newAction) { > action = newAction; > } > public String getAction() { > return action; > } > public void reset(ActionMapping mapping, HttpServletRequest request) { > fileColCount = null; > fieldMappings = new java.util.Vector(); > action = null; > } > } > ---The vector contains these:--- > public class FieldMapping implements Serializable { > private Integer fieldNumber; > private String attributeCode; > public void setFieldNumber(Integer newFieldNumber) { > fieldNumber = newFieldNumber; > } > public Integer getFieldNumber() { > return fieldNumber; > } > public void setAttributeCode(String newAttributeCode) { > attributeCode = newAttributeCode; > } > public String getAttributeCode() { > return attributeCode; > } > } > <> > >
RE: what setters do i implement in an indexed tag ?
Here is a hacked version of the code posted by David Hay previously. The code here will compile and run - a Vector is populated then displayed. After a post, the vector is retrieved from the form and then System.out is used to show its size. This should help others that are having problems with indexed tags. You'll need to point your browser to somthing that looks like http://localhost/struts/ShowParameters.do once you've copied all the files into the correct locations. There were two issues with the way i was trying to do it, firstly it seems that unless the scope of the form is set to session (or not specified) it doesn't work and secondly because i was using a different id for the name in the logic:iterate / html:text tags (when i set them to "parameter" it worked). Waz. =) -Original Message- From: Warwick Boote [mailto:[EMAIL PROTECTED]] Sent: 24 July 2001 14:09 To: [EMAIL PROTECTED] Subject: what setters do i implement in an indexed tag ? I've created a page using indexed tags (neat stuff!). Here is what is currently working for me: o If i populate the form's vector, values from that vector are displayed in the jsp Here is what it not working: o when the form is posted back, the vector is null (in the struts perform() method) I suspect i haven't implemented some sort of setter within the form but i can't find an example as to what method should be implemented. I've tried ArrayList and using parameterList instead with no different result. Thanks, Waz. =) Here are some code snippits for help: ---jsp--- ---Form--- public class FieldsMapForm extends ActionForm { private String fileColCount; private java.util.Vector fieldMappings = new java.util.Vector(); private String action; public String getFileColCount() { return fileColCount; } public void setFileColCount(String newFileColCount) { fileColCount = newFileColCount; } public void setFieldMappings(java.util.Vector newFieldMappings) { fieldMappings = newFieldMappings; } public java.util.Vector getFieldMappings() { return fieldMappings; } public FieldMapping getParameter(int index) { return (FieldMapping)fieldMappings.elementAt(index); } public void setAction(String newAction) { action = newAction; } public String getAction() { return action; } public void reset(ActionMapping mapping, HttpServletRequest request) { fileColCount = null; fieldMappings = new java.util.Vector(); action = null; } } ---The vector contains these:--- public class FieldMapping implements Serializable { private Integer fieldNumber; private String attributeCode; public void setFieldNumber(Integer newFieldNumber) { fieldNumber = newFieldNumber; } public Integer getFieldNumber() { return fieldNumber; } public void setAttributeCode(String newAttributeCode) { attributeCode = newAttributeCode; } public String getAttributeCode() { return attributeCode; } } <> indexed_eg_rwb.zip
Re: what setters do i implement in an indexed tag ?
Hal, Thanks, your post is what I needed. However, I believe there is a bug in your post. In the following code snippet: if (index > interestRates.size()-1) { interestRates.add(index,new InterestRateJBean()); } using the add to insert a "slot" at an indexed location may cause other locations in the ArrayList to be shifted over. This may be a problem since there is no guarantee that the indexed properties are processed in order -- I found that some of my attributes became scrambled e.g., attribute for row 2 updated in row 1. I replaced this code with the code below and everything appeared to work correctly.: int count = Index - this.interestRates.size() + 1; for (int i = 0; i < count; i++) { this.interestRates.add(new InterestRateJBean()); } Basically, if I get an index of 5 then I make sure there are 6 (5 + 1) slots in the ArrayList. Hope this helps. Stephen - Original Message - From: "Deadman, Hal" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, July 24, 2001 12:59 PM Subject: RE: what setters do i implement in an indexed tag ? | Ignore my previous post because I was mistaken. You don't need a setXYZ(int | index, XYZ x) method because struts will call the "public XYZ getXYZ(index | i)" method and then call the appropriate set method on the bean that is | returned. This worked for me (with last nights CVS): | | | | | | | /td> | | | | which generates field names like "interestRate[0].monthId" | | so struts will call form.getInterestRate(0).setMonthId(somevalue) | | I had this in my form class: | ArrayList interestRates; // initialized in constructor and reset() | | public InterestRateJBean getInterestRate(int index) | { | if (index > interestRates.size()-1) | { | interestRates.add(index,new InterestRateJBean()); | } | return (InterestRateJBean) interestRates.get(index); | } | | Again, I just got this to work so I may be missing something. | | Hal | | -Original Message- | From: Deadman, Hal | Sent: Tuesday, July 24, 2001 11:03 AM | To: [EMAIL PROTECTED] | Subject: RE: what setters do i implement in an indexed tag ? | | | In the indexed tags write up at | http://www.husted.com/about/struts/indexed-tags.htm, it only mentions the | two types of get methods required in the action form. It doesn't mention the | setters that are required. It looks like the getParameterList() method is | only used by the iterate tag. To populate the form on submit the only setter | needed is: | | public void setParameter(int index, Parameter p){...}; | | In your case that means: | | public void setParameter(int index, FieldMapping f) {...}; | | You probably don't need: | public void setFieldMappings(java.util.Vector newFieldMappings) { | fieldMappings = newFieldMappings; | } | unless you use it in your action to populate the form object before | displaying the form jsp. | | I am about to try this myself so this is just a guess. | | Hal | | -Original Message- | From: Warwick Boote [mailto:[EMAIL PROTECTED]] | Sent: Tuesday, July 24, 2001 9:09 AM | To: [EMAIL PROTECTED] | Subject: what setters do i implement in an indexed tag ? | | | I've created a page using indexed tags (neat stuff!). | Here is what is currently working for me: | o If i populate the form's vector, values from that vector are displayed in | the jsp | Here is what it not working: | o when the form is posted back, the vector is null (in the struts perform() | method) | I suspect i haven't implemented some sort of setter within the form but i | can't find an example as to what method should be implemented. I've tried | ArrayList and using parameterList instead with no different result. | Thanks, | Waz. | =) | Here are some code snippits for help: | ---jsp--- | | | | ---Form--- | public class FieldsMapForm extends ActionForm { | private String fileColCount; | private java.util.Vector fieldMappings = new java.util.Vector(); | private String action; | public String getFileColCount() { | return fileColCount; | } | public void setFileColCount(String newFileColCount) { | fileColCount = newFileColCount; | } | public void setFieldMappings(java.util.Vector newFieldMappings) { | fieldMappings = newFieldMappings; | } | public java.util.Vector getFieldMappings() { | return fieldMappings; | } | public FieldMapping getParameter(int index) { | return (FieldMapping)fieldMappings.elementAt(index); | } | public void setAction(String newAction) { | action = newAction; | } | public String getAction() { | return action; | } | public void reset(ActionMapping mapping, HttpServletRequest request) { | fileColCount = null; | fieldMappings = new java.util.Vector(); | action = null; | } | } | ---The vector contains these:--- | public class FieldMapping implements Serializable { | private Integer fieldNumber; | private String attributeCode; | p
RE: what setters do i implement in an indexed tag ?
aliright - i'll check that out, anyone else reading this thread - there is a .zip file attached in the message: http://www.mail-archive.com/struts-user@jakarta.apache.org/msg12084.html Waz. =) -Original Message- From: Torsten Terp [mailto:[EMAIL PROTECTED]] Sent: 24 July 2001 17:57 To: [EMAIL PROTECTED] Subject: RE: what setters do i implement in an indexed tag ? Hi, You need 3 methods, a getter and a setter for the Vector (or other arraytype object) and a getter for single object in your arraytype object, i.e., getObject(int inx){ return myVector.elementAt(inx) } Just like on the webpage mentioned. the setters needed should be defined on the object your are returning in the getObject method. That is, what happens when the form fild data is passed to the form object is: getObject(inx).setProperty(someProperty). Dave Hay posted a very usefull example (source) in a post with subject: Re: Long Story short, posted on 2001.07.19!! You should check that out! ^terp -Original Message- From: Deadman, Hal [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 24, 2001 5:03 PM To: [EMAIL PROTECTED] Subject: RE: what setters do i implement in an indexed tag ? In the indexed tags write up at http://www.husted.com/about/struts/indexed-tags.htm, it only mentions the two types of get methods required in the action form. It doesn't mention the setters that are required. It looks like the getParameterList() method is only used by the iterate tag. To populate the form on submit the only setter needed is: public void setParameter(int index, Parameter p){...}; In your case that means: public void setParameter(int index, FieldMapping f) {...}; You probably don't need: public void setFieldMappings(java.util.Vector newFieldMappings) { fieldMappings = newFieldMappings; } unless you use it in your action to populate the form object before displaying the form jsp. I am about to try this myself so this is just a guess. Hal -Original Message- From: Warwick Boote [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 24, 2001 9:09 AM To: [EMAIL PROTECTED] Subject: what setters do i implement in an indexed tag ? I've created a page using indexed tags (neat stuff!). Here is what is currently working for me: o If i populate the form's vector, values from that vector are displayed in the jsp Here is what it not working: o when the form is posted back, the vector is null (in the struts perform() method) I suspect i haven't implemented some sort of setter within the form but i can't find an example as to what method should be implemented. I've tried ArrayList and using parameterList instead with no different result. Thanks, Waz. =) Here are some code snippits for help: ---jsp--- ---Form--- public class FieldsMapForm extends ActionForm { private String fileColCount; private java.util.Vector fieldMappings = new java.util.Vector(); private String action; public String getFileColCount() { return fileColCount; } public void setFileColCount(String newFileColCount) { fileColCount = newFileColCount; } public void setFieldMappings(java.util.Vector newFieldMappings) { fieldMappings = newFieldMappings; } public java.util.Vector getFieldMappings() { return fieldMappings; } public FieldMapping getParameter(int index) { return (FieldMapping)fieldMappings.elementAt(index); } public void setAction(String newAction) { action = newAction; } public String getAction() { return action; } public void reset(ActionMapping mapping, HttpServletRequest request) { fileColCount = null; fieldMappings = new java.util.Vector(); action = null; } } ---The vector contains these:--- public class FieldMapping implements Serializable { private Integer fieldNumber; private String attributeCode; public void setFieldNumber(Integer newFieldNumber) { fieldNumber = newFieldNumber; } public Integer getFieldNumber() { return fieldNumber; } public void setAttributeCode(String newAttributeCode) { attributeCode = newAttributeCode; } public String getAttributeCode() { return attributeCode; } }
RE: what setters do i implement in an indexed tag ?
Hi, You need 3 methods, a getter and a setter for the Vector (or other arraytype object) and a getter for single object in your arraytype object, i.e., getObject(int inx){ return myVector.elementAt(inx) } Just like on the webpage mentioned. the setters needed should be defined on the object your are returning in the getObject method. That is, what happens when the form fild data is passed to the form object is: getObject(inx).setProperty(someProperty). Dave Hay posted a very usefull example (source) in a post with subject: Re: Long Story short, posted on 2001.07.19!! You should check that out! ^terp -Original Message- From: Deadman, Hal [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 24, 2001 5:03 PM To: [EMAIL PROTECTED] Subject: RE: what setters do i implement in an indexed tag ? In the indexed tags write up at http://www.husted.com/about/struts/indexed-tags.htm, it only mentions the two types of get methods required in the action form. It doesn't mention the setters that are required. It looks like the getParameterList() method is only used by the iterate tag. To populate the form on submit the only setter needed is: public void setParameter(int index, Parameter p){...}; In your case that means: public void setParameter(int index, FieldMapping f) {...}; You probably don't need: public void setFieldMappings(java.util.Vector newFieldMappings) { fieldMappings = newFieldMappings; } unless you use it in your action to populate the form object before displaying the form jsp. I am about to try this myself so this is just a guess. Hal -Original Message- From: Warwick Boote [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 24, 2001 9:09 AM To: [EMAIL PROTECTED] Subject: what setters do i implement in an indexed tag ? I've created a page using indexed tags (neat stuff!). Here is what is currently working for me: o If i populate the form's vector, values from that vector are displayed in the jsp Here is what it not working: o when the form is posted back, the vector is null (in the struts perform() method) I suspect i haven't implemented some sort of setter within the form but i can't find an example as to what method should be implemented. I've tried ArrayList and using parameterList instead with no different result. Thanks, Waz. =) Here are some code snippits for help: ---jsp--- ---Form--- public class FieldsMapForm extends ActionForm { private String fileColCount; private java.util.Vector fieldMappings = new java.util.Vector(); private String action; public String getFileColCount() { return fileColCount; } public void setFileColCount(String newFileColCount) { fileColCount = newFileColCount; } public void setFieldMappings(java.util.Vector newFieldMappings) { fieldMappings = newFieldMappings; } public java.util.Vector getFieldMappings() { return fieldMappings; } public FieldMapping getParameter(int index) { return (FieldMapping)fieldMappings.elementAt(index); } public void setAction(String newAction) { action = newAction; } public String getAction() { return action; } public void reset(ActionMapping mapping, HttpServletRequest request) { fileColCount = null; fieldMappings = new java.util.Vector(); action = null; } } ---The vector contains these:--- public class FieldMapping implements Serializable { private Integer fieldNumber; private String attributeCode; public void setFieldNumber(Integer newFieldNumber) { fieldNumber = newFieldNumber; } public Integer getFieldNumber() { return fieldNumber; } public void setAttributeCode(String newAttributeCode) { attributeCode = newAttributeCode; } public String getAttributeCode() { return attributeCode; } }
RE: what setters do i implement in an indexed tag ?
Ignore my previous post because I was mistaken. You don't need a setXYZ(int index, XYZ x) method because struts will call the "public XYZ getXYZ(index i)" method and then call the appropriate set method on the bean that is returned. This worked for me (with last nights CVS): /td> which generates field names like "interestRate[0].monthId" so struts will call form.getInterestRate(0).setMonthId(somevalue) I had this in my form class: ArrayList interestRates; // initialized in constructor and reset() public InterestRateJBean getInterestRate(int index) { if (index > interestRates.size()-1) { interestRates.add(index,new InterestRateJBean()); } return (InterestRateJBean) interestRates.get(index); } Again, I just got this to work so I may be missing something. Hal -Original Message- From: Deadman, Hal Sent: Tuesday, July 24, 2001 11:03 AM To: [EMAIL PROTECTED] Subject: RE: what setters do i implement in an indexed tag ? In the indexed tags write up at http://www.husted.com/about/struts/indexed-tags.htm, it only mentions the two types of get methods required in the action form. It doesn't mention the setters that are required. It looks like the getParameterList() method is only used by the iterate tag. To populate the form on submit the only setter needed is: public void setParameter(int index, Parameter p){...}; In your case that means: public void setParameter(int index, FieldMapping f) {...}; You probably don't need: public void setFieldMappings(java.util.Vector newFieldMappings) { fieldMappings = newFieldMappings; } unless you use it in your action to populate the form object before displaying the form jsp. I am about to try this myself so this is just a guess. Hal -Original Message- From: Warwick Boote [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 24, 2001 9:09 AM To: [EMAIL PROTECTED] Subject: what setters do i implement in an indexed tag ? I've created a page using indexed tags (neat stuff!). Here is what is currently working for me: o If i populate the form's vector, values from that vector are displayed in the jsp Here is what it not working: o when the form is posted back, the vector is null (in the struts perform() method) I suspect i haven't implemented some sort of setter within the form but i can't find an example as to what method should be implemented. I've tried ArrayList and using parameterList instead with no different result. Thanks, Waz. =) Here are some code snippits for help: ---jsp--- ---Form--- public class FieldsMapForm extends ActionForm { private String fileColCount; private java.util.Vector fieldMappings = new java.util.Vector(); private String action; public String getFileColCount() { return fileColCount; } public void setFileColCount(String newFileColCount) { fileColCount = newFileColCount; } public void setFieldMappings(java.util.Vector newFieldMappings) { fieldMappings = newFieldMappings; } public java.util.Vector getFieldMappings() { return fieldMappings; } public FieldMapping getParameter(int index) { return (FieldMapping)fieldMappings.elementAt(index); } public void setAction(String newAction) { action = newAction; } public String getAction() { return action; } public void reset(ActionMapping mapping, HttpServletRequest request) { fileColCount = null; fieldMappings = new java.util.Vector(); action = null; } } ---The vector contains these:--- public class FieldMapping implements Serializable { private Integer fieldNumber; private String attributeCode; public void setFieldNumber(Integer newFieldNumber) { fieldNumber = newFieldNumber; } public Integer getFieldNumber() { return fieldNumber; } public void setAttributeCode(String newAttributeCode) { attributeCode = newAttributeCode; } public String getAttributeCode() { return attributeCode; } }
RE: what setters do i implement in an indexed tag ?
In the indexed tags write up at http://www.husted.com/about/struts/indexed-tags.htm, it only mentions the two types of get methods required in the action form. It doesn't mention the setters that are required. It looks like the getParameterList() method is only used by the iterate tag. To populate the form on submit the only setter needed is: public void setParameter(int index, Parameter p){...}; In your case that means: public void setParameter(int index, FieldMapping f) {...}; You probably don't need: public void setFieldMappings(java.util.Vector newFieldMappings) { fieldMappings = newFieldMappings; } unless you use it in your action to populate the form object before displaying the form jsp. I am about to try this myself so this is just a guess. Hal -Original Message- From: Warwick Boote [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 24, 2001 9:09 AM To: [EMAIL PROTECTED] Subject: what setters do i implement in an indexed tag ? I've created a page using indexed tags (neat stuff!). Here is what is currently working for me: o If i populate the form's vector, values from that vector are displayed in the jsp Here is what it not working: o when the form is posted back, the vector is null (in the struts perform() method) I suspect i haven't implemented some sort of setter within the form but i can't find an example as to what method should be implemented. I've tried ArrayList and using parameterList instead with no different result. Thanks, Waz. =) Here are some code snippits for help: ---jsp--- ---Form--- public class FieldsMapForm extends ActionForm { private String fileColCount; private java.util.Vector fieldMappings = new java.util.Vector(); private String action; public String getFileColCount() { return fileColCount; } public void setFileColCount(String newFileColCount) { fileColCount = newFileColCount; } public void setFieldMappings(java.util.Vector newFieldMappings) { fieldMappings = newFieldMappings; } public java.util.Vector getFieldMappings() { return fieldMappings; } public FieldMapping getParameter(int index) { return (FieldMapping)fieldMappings.elementAt(index); } public void setAction(String newAction) { action = newAction; } public String getAction() { return action; } public void reset(ActionMapping mapping, HttpServletRequest request) { fileColCount = null; fieldMappings = new java.util.Vector(); action = null; } } ---The vector contains these:--- public class FieldMapping implements Serializable { private Integer fieldNumber; private String attributeCode; public void setFieldNumber(Integer newFieldNumber) { fieldNumber = newFieldNumber; } public Integer getFieldNumber() { return fieldNumber; } public void setAttributeCode(String newAttributeCode) { attributeCode = newAttributeCode; } public String getAttributeCode() { return attributeCode; } }