Re: Using ArrayList instead of String[] properties
In the logic-el:iterate you defined the bean to scope with the id attribute, but then don't reference it in the form element html-el:checkbox name=acct property=accounts indexed=true / I'd consider not storing the formbeans in a map as you don't need to get the values out with a key. I provided an example of how to do this in this thread even making an arrayList of dynaactionforms will work. cheers Mark On 12 Jan 2004, at 21:27, Wendy Smoak wrote: From: Wendy Smoak Apparently you don't have to use logic-el:iterate with html-el:checkbox indexed=true. This works: c:forEach items=${accountMap[accountForm.map.calendarYear]} var=account html-el:checkbox property=accounts indexed=true I lied, that doesn't work at all. It produces HTML like this: input type=checkbox name=org.apache.struts.taglib.html.BEAN[0].accounts value=on10_U_FADA0001 I read that indexed properties only work with logic:iterate, so I'm trying to change over from logic:forEach. Can someone help me sort this out? This works to generate HTML, but BeanUtils can't populate the ArrayList that is the 'accounts' property of accountForm because the bracketed [] indexes are missing. logic-el:iterate collection=${accountMap[accountForm.map.calendarYear]} id=acct indexId=ctr html-el:checkbox property=accounts c:out value=${acct.key}/ /html-el:checkbox ... However, if I add indexed=true like so: logic-el:iterate collection=${accountMap[accountForm.map.calendarYear]} id=acct indexId=ctr html-el:checkbox property=accounts indexed=true c:out value=${acct.key}/ /html-el:checkbox It renders this HTML: input type=checkbox name=org.apache.struts.taglib.html.BEAN[0].accounts value=on10_U_FADA0001 ??! This is my first attempt at indexed properties, which apparently I need in order to use an ArrayList. (The items in the ArrayList are just Strings, not complex objects. This isn't nested properties, it's just a bunch of checkboxes. I'm trying to use ArrayList instead of String[] to avoid out of bounds errors. String[] was working *fine* last week, until I got the bright idea to use ArrayList.) I'm getting the feeling that the things in the ArrayList property of the form have to be complex objects and not just Strings. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - 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: Using ArrayList instead of String[] properties
Hi! I was myself trying to work on a similar issue. My problem is as follows: i query db. Then store data in Araylist. How to pass this to jsp page? Any sample code great appreciation. Please urgent. Sha At 02:27 PM 1/12/2004 -0700, you wrote: From: Wendy Smoak Apparently you don't have to use logic-el:iterate with html-el:checkbox indexed=true. This works: c:forEach items=${accountMap[accountForm.map.calendarYear]} var=account html-el:checkbox property=accounts indexed=true I lied, that doesn't work at all. It produces HTML like this: input type=checkbox name=org.apache.struts.taglib.html.BEAN[0].accounts value=on10_U_FADA0001 I read that indexed properties only work with logic:iterate, so I'm trying to change over from logic:forEach. Can someone help me sort this out? This works to generate HTML, but BeanUtils can't populate the ArrayList that is the 'accounts' property of accountForm because the bracketed [] indexes are missing. logic-el:iterate collection=${accountMap[accountForm.map.calendarYear]} id=acct indexId=ctr html-el:checkbox property=accounts c:out value=${acct.key}/ /html-el:checkbox ... However, if I add indexed=true like so: logic-el:iterate collection=${accountMap[accountForm.map.calendarYear]} id=acct indexId=ctr html-el:checkbox property=accounts indexed=true c:out value=${acct.key}/ /html-el:checkbox It renders this HTML: input type=checkbox name=org.apache.struts.taglib.html.BEAN[0].accounts value=on10_U_FADA0001 ??! This is my first attempt at indexed properties, which apparently I need in order to use an ArrayList. (The items in the ArrayList are just Strings, not complex objects. This isn't nested properties, it's just a bunch of checkboxes. I'm trying to use ArrayList instead of String[] to avoid out of bounds errors. String[] was working *fine* last week, until I got the bright idea to use ArrayList.) I'm getting the feeling that the things in the ArrayList property of the form have to be complex objects and not just Strings. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To achieve all that is possible, one must attempt the impossible - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using ArrayList instead of String[] properties
what does you form bean look like (dyna or otherwise)? On 13 Jan 2004, at 12:07, shankarr wrote: Hi! I was myself trying to work on a similar issue. My problem is as follows: i query db. Then store data in Araylist. How to pass this to jsp page? Any sample code great appreciation. Please urgent. Sha At 02:27 PM 1/12/2004 -0700, you wrote: From: Wendy Smoak Apparently you don't have to use logic-el:iterate with html-el:checkbox indexed=true. This works: c:forEach items=${accountMap[accountForm.map.calendarYear]} var=account html-el:checkbox property=accounts indexed=true I lied, that doesn't work at all. It produces HTML like this: input type=checkbox name=org.apache.struts.taglib.html.BEAN[0].accounts value=on10_U_FADA0001 I read that indexed properties only work with logic:iterate, so I'm trying to change over from logic:forEach. Can someone help me sort this out? This works to generate HTML, but BeanUtils can't populate the ArrayList that is the 'accounts' property of accountForm because the bracketed [] indexes are missing. logic-el:iterate collection=${accountMap[accountForm.map.calendarYear]} id=acct indexId=ctr html-el:checkbox property=accounts c:out value=${acct.key}/ /html-el:checkbox ... However, if I add indexed=true like so: logic-el:iterate collection=${accountMap[accountForm.map.calendarYear]} id=acct indexId=ctr html-el:checkbox property=accounts indexed=true c:out value=${acct.key}/ /html-el:checkbox It renders this HTML: input type=checkbox name=org.apache.struts.taglib.html.BEAN[0].accounts value=on10_U_FADA0001 ??! This is my first attempt at indexed properties, which apparently I need in order to use an ArrayList. (The items in the ArrayList are just Strings, not complex objects. This isn't nested properties, it's just a bunch of checkboxes. I'm trying to use ArrayList instead of String[] to avoid out of bounds errors. String[] was working *fine* last week, until I got the bright idea to use ArrayList.) I'm getting the feeling that the things in the ArrayList property of the form have to be complex objects and not just Strings. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To achieve all that is possible, one must attempt the impossible - 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: Using ArrayList instead of String[] properties
Wendy, If you simply want to present a list of options to the user represented as check boxes and collect the selected options, and the selected options are just single string values, then you can do the following: Define accounts property as an java.lang.String[] and initialize it to {}. form-property name=accounts type=java.lang.String[] initial={}/ Retrieve you options and store them in an ArrayList named accountOptions and render the options like so: c:forEach var=account items=${accountOptions} html:multibox property=accountsc:out value=${account}//html:multibox /c:forEach This should generate HTML like: input type=checkbox name=accounts value=someValue/ input type=checkbox name=accounts value=someValue2/ input type=checkbox name=accounts value=someValue3/ The servlet container will collect these values and place them in a single String array under the accounts name. Struts will reset your form and them populate the accounts property of your form with the String array. Unless I've missed something, I don't see the need to using indexed properties here if the selected value is single String and order doesn't matter. robert -Original Message- From: shankarr [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 13, 2004 7:07 AM To: Struts Users Mailing List Subject: RE: Using ArrayList instead of String[] properties Hi! I was myself trying to work on a similar issue. My problem is as follows: i query db. Then store data in Araylist. How to pass this to jsp page? Any sample code great appreciation. Please urgent. Sha At 02:27 PM 1/12/2004 -0700, you wrote: From: Wendy Smoak Apparently you don't have to use logic-el:iterate with html-el:checkbox indexed=true. This works: c:forEach items=${accountMap[accountForm.map.calendarYear]} var=account html-el:checkbox property=accounts indexed=true I lied, that doesn't work at all. It produces HTML like this: input type=checkbox name=org.apache.struts.taglib.html.BEAN[0].accounts value=on10_U_FADA0001 I read that indexed properties only work with logic:iterate, so I'm trying to change over from logic:forEach. Can someone help me sort this out? This works to generate HTML, but BeanUtils can't populate the ArrayList that is the 'accounts' property of accountForm because the bracketed [] indexes are missing. logic-el:iterate collection=${accountMap[accountForm.map.calendarYear]} id=acct indexId=ctr html-el:checkbox property=accounts c:out value=${acct.key}/ /html-el:checkbox ... However, if I add indexed=true like so: logic-el:iterate collection=${accountMap[accountForm.map.calendarYear]} id=acct indexId=ctr html-el:checkbox property=accounts indexed=true c:out value=${acct.key}/ /html-el:checkbox It renders this HTML: input type=checkbox name=org.apache.struts.taglib.html.BEAN[0].accounts value=on10_U_FADA0001 ??! This is my first attempt at indexed properties, which apparently I need in order to use an ArrayList. (The items in the ArrayList are just Strings, not complex objects. This isn't nested properties, it's just a bunch of checkboxes. I'm trying to use ArrayList instead of String[] to avoid out of bounds errors. String[] was working *fine* last week, until I got the bright idea to use ArrayList.) I'm getting the feeling that the things in the ArrayList property of the form have to be complex objects and not just Strings. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To achieve all that is possible, one must attempt the impossible - 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: Using ArrayList instead of String[] properties
From: Robert Taylor [mailto:[EMAIL PROTECTED] Unless I've missed something, I don't see the need to using indexed properties here if the selected value is single String and order doesn't matter. After much consideration, neither do I! I thought ArrayList would be easier to deal with, but it turns out that String[] is the right type to use in the form bean [which has a Map because it's a DynaValidatorForm]. My entire purpose in switching to ArrayList was to avoid the inevitable out of bounds exceptions in the Action code. But that's easily done by (something like) Arrays.asList() at the top, and then myList.toArray() at the end. Another Struts learning experience. Thanks for the help! -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using ArrayList instead of String[] properties
Using arrayList as a form property works fine with action forms dyna or otherwise. In fact IMO it makes like simpler. As i recall you were trying to iterate through a map of forms not an arraylist. On 13 Jan 2004, at 14:28, Wendy Smoak wrote: From: Robert Taylor [mailto:[EMAIL PROTECTED] Unless I've missed something, I don't see the need to using indexed properties here if the selected value is single String and order doesn't matter. After much consideration, neither do I! I thought ArrayList would be easier to deal with, but it turns out that String[] is the right type to use in the form bean [which has a Map because it's a DynaValidatorForm]. My entire purpose in switching to ArrayList was to avoid the inevitable out of bounds exceptions in the Action code. But that's easily done by (something like) Arrays.asList() at the top, and then myList.toArray() at the end. Another Struts learning experience. Thanks for the help! -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - 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: Using ArrayList instead of String[] properties
From: Mark Lowe [mailto:[EMAIL PROTECTED] Using arrayList as a form property works fine with action forms dyna or otherwise. In fact IMO it makes like simpler. As i recall you were trying to iterate through a map of forms not an arraylist. The iterator goes through a Map, yes, but that Map isn't stored in the form, it's just a list of things stored in the session that the user needs to pick from. I do not need to iterate over the ArrayList stored in the DynaValidatorForm, I just wanted to store the user's choices there and manipulate them in the Action code. And I don't want them positional. If I show him six choices and he picks the first and fourth, I want an ArrayList with two items. When I try to use ArrayList with multiple checkboxes, BeanUtils complains that it can't do it: org.apache.commons.beanutils.ConversionException: Cannot assign value of type 'java.lang.String' to property 'accounts' of type 'java.util.ArrayList' I would love to be able to use ArrayList in the DynaValidatorForm, *without* indexing the property, which I don't need. But I don't know how to do the Struts tags so that BeanUtils is happy. Which is fine, really... I can deal with String[] with two extra lines of code. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using ArrayList instead of String[] properties
fair enough .. i'm having a bad day with multiple, select menus and bean utils not dealing with life every well. java.lang.IllegalArgumentException: argument type mismatch bean utils seems to be complaining that the types in my form and those in the form bean are somehow different, i cant see where. It was working, until i rearranged a few things. A few questions/suggestions in help me problem solve would be greatly appreciated if you have the time. Cheers Mark On 13 Jan 2004, at 15:50, Wendy Smoak wrote: From: Mark Lowe [mailto:[EMAIL PROTECTED] Using arrayList as a form property works fine with action forms dyna or otherwise. In fact IMO it makes like simpler. As i recall you were trying to iterate through a map of forms not an arraylist. The iterator goes through a Map, yes, but that Map isn't stored in the form, it's just a list of things stored in the session that the user needs to pick from. I do not need to iterate over the ArrayList stored in the DynaValidatorForm, I just wanted to store the user's choices there and manipulate them in the Action code. And I don't want them positional. If I show him six choices and he picks the first and fourth, I want an ArrayList with two items. When I try to use ArrayList with multiple checkboxes, BeanUtils complains that it can't do it: org.apache.commons.beanutils.ConversionException: Cannot assign value of type 'java.lang.String' to property 'accounts' of type 'java.util.ArrayList' I would love to be able to use ArrayList in the DynaValidatorForm, *without* indexing the property, which I don't need. But I don't know how to do the Struts tags so that BeanUtils is happy. Which is fine, really... I can deal with String[] with two extra lines of code. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - 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: Using ArrayList instead of String[] properties
From: Mark Lowe [mailto:[EMAIL PROTECTED] It was working, until i rearranged a few things. A few questions/suggestions in help me problem solve would be greatly appreciated if you have the time. I also don't see why BeanUtils can't handle turning multiple request parameters with the same name into an ArrayList. It *seems* like it should work. String[] works fine for me, though. I actually thought there was a one-liner to turn a String[] into an ArrayList of Strings, but I was mistaken-- Arrays.asList() only produces a fixed-length list. You can change values, but you can't add a value to the array-backed-List. My issue is probably not one that you have-- I need to accept input from three text areas and manually add the concatenated text to the String[] property. It would be nicer to do it with myList.add( stuff ), but since I can't get ArrayList to work, here's how I'm using String[] in Action code: DynaActionForm dForm = (DynaActionForm) form; String[] accounts = (String[]) dForm.get( accounts ); String fund = dForm.getString( fund ); String function = dForm.getString( function ); String costCenter = dForm.getString( costCenter ); String[] newArray = new String[ accounts.length + 1]; System.arraycopy( accounts, 0, newArray, 0, accounts.length ); newArray[ newArray.length - 1 ] = fund+_+function+_+costCenter; dForm.set( accounts , newArray ); accounts = null; return mapping.findForward( advanced ); I haven't used arrays in ages, so if someone is now ROFL at my incredibly inefficient code, please enlighten me. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Using ArrayList instead of String[] properties
For a resizable list from an array, try: List stringList = new ArrayList(Arrays.asList(stringArray)); Quoting Wendy Smoak [EMAIL PROTECTED]: From: Mark Lowe [mailto:[EMAIL PROTECTED] It was working, until i rearranged a few things. A few questions/suggestions in help me problem solve would be greatly appreciated if you have the time. I also don't see why BeanUtils can't handle turning multiple request parameters with the same name into an ArrayList. It *seems* like it should work. String[] works fine for me, though. I actually thought there was a one-liner to turn a String[] into an ArrayList of Strings, but I was mistaken-- Arrays.asList() only produces a fixed-length list. You can change values, but you can't add a value to the array-backed-List. My issue is probably not one that you have-- I need to accept input from three text areas and manually add the concatenated text to the String[] property. It would be nicer to do it with myList.add( stuff ), but since I can't get ArrayList to work, here's how I'm using String[] in Action code: DynaActionForm dForm = (DynaActionForm) form; String[] accounts = (String[]) dForm.get( accounts ); String fund = dForm.getString( fund ); String function = dForm.getString( function ); String costCenter = dForm.getString( costCenter ); String[] newArray = new String[ accounts.length + 1]; System.arraycopy( accounts, 0, newArray, 0, accounts.length ); newArray[ newArray.length - 1 ] = fund+_+function+_+costCenter; dForm.set( accounts , newArray ); accounts = null; return mapping.findForward( advanced ); I haven't used arrays in ages, so if someone is now ROFL at my incredibly inefficient code, please enlighten me. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management -- Kris Schneider mailto:[EMAIL PROTECTED] D.O.Tech http://www.dotech.com/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using ArrayList instead of String[] properties
The only issue with using arraylist as a form property is to scope to session so you can change the size when required. I tend to use them for nesting beans rather then just storing strings. My form parameters are in an arraylist. I just think beanUtils hates me or something rational like that. On 13 Jan 2004, at 17:47, Wendy Smoak wrote: From: Mark Lowe [mailto:[EMAIL PROTECTED] It was working, until i rearranged a few things. A few questions/suggestions in help me problem solve would be greatly appreciated if you have the time. I also don't see why BeanUtils can't handle turning multiple request parameters with the same name into an ArrayList. It *seems* like it should work. String[] works fine for me, though. I actually thought there was a one-liner to turn a String[] into an ArrayList of Strings, but I was mistaken-- Arrays.asList() only produces a fixed-length list. You can change values, but you can't add a value to the array-backed-List. My issue is probably not one that you have-- I need to accept input from three text areas and manually add the concatenated text to the String[] property. It would be nicer to do it with myList.add( stuff ), but since I can't get ArrayList to work, here's how I'm using String[] in Action code: DynaActionForm dForm = (DynaActionForm) form; String[] accounts = (String[]) dForm.get( accounts ); String fund = dForm.getString( fund ); String function = dForm.getString( function ); String costCenter = dForm.getString( costCenter ); String[] newArray = new String[ accounts.length + 1]; System.arraycopy( accounts, 0, newArray, 0, accounts.length ); newArray[ newArray.length - 1 ] = fund+_+function+_+costCenter; dForm.set( accounts , newArray ); accounts = null; return mapping.findForward( advanced ); I haven't used arrays in ages, so if someone is now ROFL at my incredibly inefficient code, please enlighten me. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - 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: Using ArrayList instead of String[] properties
Hi, Wendy, Just do this or whatever is similar that you like. This is what I do. public class ArrayListWrapper extends ArrayList { private ArrayListWrapper(Object [] param) { for(int i = 0; i param.length; i++) { this.add(param[i]); } } public static ArrayList getInstance(Object [] param) { return new ArrayListWrapper(param); } } At 09:47 AM 1/13/2004, Wendy Smoak wrote: From: Mark Lowe [mailto:[EMAIL PROTECTED] It was working, until i rearranged a few things. A few questions/suggestions in help me problem solve would be greatly appreciated if you have the time. I also don't see why BeanUtils can't handle turning multiple request parameters with the same name into an ArrayList. It *seems* like it should work. String[] works fine for me, though. I actually thought there was a one-liner to turn a String[] into an ArrayList of Strings, but I was mistaken-- Arrays.asList() only produces a fixed-length list. You can change values, but you can't add a value to the array-backed-List. My issue is probably not one that you have-- I need to accept input from three text areas and manually add the concatenated text to the String[] property. It would be nicer to do it with myList.add( stuff ), but since I can't get ArrayList to work, here's how I'm using String[] in Action code: DynaActionForm dForm = (DynaActionForm) form; String[] accounts = (String[]) dForm.get( accounts ); String fund = dForm.getString( fund ); String function = dForm.getString( function ); String costCenter = dForm.getString( costCenter ); String[] newArray = new String[ accounts.length + 1]; System.arraycopy( accounts, 0, newArray, 0, accounts.length ); newArray[ newArray.length - 1 ] = fund+_+function+_+costCenter; dForm.set( accounts , newArray ); accounts = null; return mapping.findForward( advanced ); I haven't used arrays in ages, so if someone is now ROFL at my incredibly inefficient code, please enlighten me. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Using ArrayList instead of String[] properties
From: Wendy Smoak Apparently you don't have to use logic-el:iterate with html-el:checkbox indexed=true. This works: c:forEach items=${accountMap[accountForm.map.calendarYear]} var=account html-el:checkbox property=accounts indexed=true I lied, that doesn't work at all. It produces HTML like this: input type=checkbox name=org.apache.struts.taglib.html.BEAN[0].accounts value=on10_U_FADA0001 I read that indexed properties only work with logic:iterate, so I'm trying to change over from logic:forEach. Can someone help me sort this out? This works to generate HTML, but BeanUtils can't populate the ArrayList that is the 'accounts' property of accountForm because the bracketed [] indexes are missing. logic-el:iterate collection=${accountMap[accountForm.map.calendarYear]} id=acct indexId=ctr html-el:checkbox property=accounts c:out value=${acct.key}/ /html-el:checkbox ... However, if I add indexed=true like so: logic-el:iterate collection=${accountMap[accountForm.map.calendarYear]} id=acct indexId=ctr html-el:checkbox property=accounts indexed=true c:out value=${acct.key}/ /html-el:checkbox It renders this HTML: input type=checkbox name=org.apache.struts.taglib.html.BEAN[0].accounts value=on10_U_FADA0001 ??! This is my first attempt at indexed properties, which apparently I need in order to use an ArrayList. (The items in the ArrayList are just Strings, not complex objects. This isn't nested properties, it's just a bunch of checkboxes. I'm trying to use ArrayList instead of String[] to avoid out of bounds errors. String[] was working *fine* last week, until I got the bright idea to use ArrayList.) I'm getting the feeling that the things in the ArrayList property of the form have to be complex objects and not just Strings. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using ArrayList instead of String[] properties
I think your multibox needs to be index=true or be a checkbox with index=true. On 9 Jan 2004, at 21:46, Wendy Smoak wrote: I have a String[] property in a DynaValidatorForm. It works fine with multiple checkboxes and accepts multiple selections. Now I need to do an advanced user interface, where the user can enter the information in text boxes and click 'Add'. Behind the scenes I need to populate that String[] property (which is named 'accounts'). I don't want to deal with checking the size of the array and the inevitable out of bounds exceptions, so I thought ArrayList would be a better choice. However, when I change to ArrayList, including struts-config.xml: form-property name=accounts type=java.util.ArrayList/ BeanUtils complains when I submit the form that has the multiple checkboxes: org.apache.commons.beanutils.ConversionException: Cannot assign value of type 'java.lang.String' to property 'accounts' of type 'java.util.ArrayList' The docs indicate that ArrayList is allowed in DynaActionForms (mine is a DynaValidatorForm): http://jakarta.apache.org/struts/userGuide/ building_controller.html#dyna _action_form_classes The multibox tag is: c:forEach items=${accountMap[accountForm.map.calendarYear]} var=account html-el:multibox property=accounts c:out value=${account.key}/ /html-el:multibox c:out value=${account.key}/nbsp; c:out value=${account.costCenterDesc}/ br/ /c:forEach Which correctly renders checkboxes such as input type=checkbox name=accounts value=55_U_ABCD123455_U_ABCD1234nbsp;Some Accountbr/ input type=checkbox name=accounts value=66_S_EFGH567866_S_EFGH5678nbsp;Some Other Accountbr/ Any idea what I'm doing wrong, or is there a better way to do this? -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - 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: Using ArrayList instead of String[] properties
From: Mark Lowe [mailto:[EMAIL PROTECTED] I think your multibox needs to be index=true or be a checkbox with index=true. Thanks for the hint. It looks like it's indexed=true and only valid on checkbox (not multibox). But the docs say indexed can only be used inside a logic:iterate, and instead I have a c:forEach loop. http://jakarta.apache.org/struts/userGuide/struts-html.html#checkbox So apparently I have to do the indexing myself... http://jakarta.apache.org/struts/faqs/indexedprops.html I have a vague memory of asking what you can do with logic-el:iterate that you cannot do with c:forEach, and an equally vague memory that this is it. Is it true that I must use logic-el:iterate instead of c:forEach, if I want indexed properties? Thanks, -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Using ArrayList instead of String[] properties
From: Wendy Smoak Is it true that I must use logic-el:iterate instead of c:forEach, if I want indexed properties? Oh, it figures. Something else was wrong, and of COURSE I discovered it right after hitting send. Apparently you don't have to use logic-el:iterate with html-el:checkbox indexed=true. This works: c:forEach items=${accountMap[accountForm.map.calendarYear]} var=account html-el:checkbox property=accounts indexed=true c:out value=${account.key}/ /html-el:checkbox c:out value=${account.key}/nbsp; c:out value=${account.costCenterDesc}/ br/ /c:forEach -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using ArrayList instead of String[] properties
I would personally suggest that you rethink your design. If you want an advanced user interface that does that, then I would use a ListHandler implementation of a ListIterator interface that is so popular with the J2EE pattern people. The ListIterator interface is something like the following: package com.michaelmcgrady.util.list; import java.util.Collection; import java.util.List; import com.michaelmcgrady.exception.ChainedException; public interface ListIterator { public void setList(List list) throws ChainedException; public Collection getList(); public intgetSize() throws ChainedException; public void setIndex(int index) throws ChainedException; public intgetCurrentIndex() throws ChainedException; public Object getCurrentElement() throws ChainedException; public List getPreviousElements(int count) throws ChainedException; public List getPreviousElements() throws ChainedException; public List getNextElements(int count) throws ChainedException; public List getNextElements() throws ChainedException; public void resetIndex() throws ChainedException; } /// ;-) This is what I use and it is lightening fast and works the way the design was promised to work. You can work out what you do with the newer c el stuff, but I have done it the following way in code I have not changed: nested:define id='list_handler' type='com.michaelmcgrady.user.ListHandler' scope='session'/ nested:root name='list_handler' logic:iterate id='users' name='list_handler' property='list' hr color='bean:write name=gui_data property=view.lgnDrkClr /' id: nbsp;bean:write name='users' property='id'/br username nbsp;bean:write name='users' property='username'/ br password nbsp;bean:write name='users' property='password'/ br name nbsp;bean:write name='users' property='name'/ br email nbsp;bean:write name='users' property='email'/ br type nbsp;bean:write name='users' property='type'/ br statusnbsp;bean:write name='users' property='status'/br time nbsp;bean:write name='users' property='time'/ br /logic:iterate /nested:root Hope this helps. Don't know anything about dynamically uploading applets, do you? I cannot seem to get that right. Regards, Michael McGrady At 01:46 PM 1/9/2004, you wrote: I have a String[] property in a DynaValidatorForm. It works fine with multiple checkboxes and accepts multiple selections. Now I need to do an advanced user interface, where the user can enter the information in text boxes and click 'Add'. Behind the scenes I need to populate that String[] property (which is named 'accounts'). I don't want to deal with checking the size of the array and the inevitable out of bounds exceptions, so I thought ArrayList would be a better choice. However, when I change to ArrayList, including struts-config.xml: form-property name=accounts type=java.util.ArrayList/ BeanUtils complains when I submit the form that has the multiple checkboxes: org.apache.commons.beanutils.ConversionException: Cannot assign value of type 'java.lang.String' to property 'accounts' of type 'java.util.ArrayList' The docs indicate that ArrayList is allowed in DynaActionForms (mine is a DynaValidatorForm): http://jakarta.apache.org/struts/userGuide/building_controller.html#dyna _action_form_classes The multibox tag is: c:forEach items=${accountMap[accountForm.map.calendarYear]} var=account html-el:multibox property=accounts c:out value=${account.key}/ /html-el:multibox c:out value=${account.key}/nbsp; c:out value=${account.costCenterDesc}/ br/ /c:forEach Which correctly renders checkboxes such as input type=checkbox name=accounts value=55_U_ABCD123455_U_ABCD1234nbsp;Some Accountbr/ input type=checkbox name=accounts value=66_S_EFGH567866_S_EFGH5678nbsp;Some Other Accountbr/ Any idea what I'm doing wrong, or is there a better way to do this? -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using ArrayList instead of String[] properties
Reckon that looks complex to me although i tend to use action forms not dynaaction forms. public class Account { private String name; private String number; private String description; ..bla bla } may as will use dynaactionform for this example as just an arraylist form-bean name=accountsForm form-property name=accounts type=java.util.ArrayList / ... in referring action DynaActionForm theForm = (DynaActionForm) form; ArrayList accountList = new ArrayList(); Account account = new Account(); account.setName(My Account); account.setDescription(Its an account); account.setNumber(782627367236); theForm.set(accounts,accountList); ... c:forEach var=account items=${accountsForm.accounts} c:out value=${account.name} / ... But probably my over simplistic view on such things. On 9 Jan 2004, at 23:47, Michael McGrady wrote: I would personally suggest that you rethink your design. If you want an advanced user interface that does that, then I would use a ListHandler implementation of a ListIterator interface that is so popular with the J2EE pattern people. The ListIterator interface is something like the following: package com.michaelmcgrady.util.list; import java.util.Collection; import java.util.List; import com.michaelmcgrady.exception.ChainedException; public interface ListIterator { public void setList(List list) throws ChainedException; public Collection getList(); public intgetSize() throws ChainedException; public void setIndex(int index) throws ChainedException; public intgetCurrentIndex() throws ChainedException; public Object getCurrentElement() throws ChainedException; public List getPreviousElements(int count) throws ChainedException; public List getPreviousElements() throws ChainedException; public List getNextElements(int count) throws ChainedException; public List getNextElements() throws ChainedException; public void resetIndex() throws ChainedException; } /// ;-) This is what I use and it is lightening fast and works the way the design was promised to work. You can work out what you do with the newer c el stuff, but I have done it the following way in code I have not changed: nested:define id='list_handler' type='com.michaelmcgrady.user.ListHandler' scope='session'/ nested:root name='list_handler' logic:iterate id='users' name='list_handler' property='list' hr color='bean:write name=gui_data property=view.lgnDrkClr /' id: nbsp;bean:write name='users' property='id'/br username nbsp;bean:write name='users' property='username'/ br password nbsp;bean:write name='users' property='password'/ br name nbsp;bean:write name='users' property='name'/ br email nbsp;bean:write name='users' property='email'/ br type nbsp;bean:write name='users' property='type'/ br statusnbsp;bean:write name='users' property='status'/br time nbsp;bean:write name='users' property='time'/ br /logic:iterate /nested:root Hope this helps. Don't know anything about dynamically uploading applets, do you? I cannot seem to get that right. Regards, Michael McGrady At 01:46 PM 1/9/2004, you wrote: I have a String[] property in a DynaValidatorForm. It works fine with multiple checkboxes and accepts multiple selections. Now I need to do an advanced user interface, where the user can enter the information in text boxes and click 'Add'. Behind the scenes I need to populate that String[] property (which is named 'accounts'). I don't want to deal with checking the size of the array and the inevitable out of bounds exceptions, so I thought ArrayList would be a better choice. However, when I change to ArrayList, including struts-config.xml: form-property name=accounts type=java.util.ArrayList/ BeanUtils complains when I submit the form that has the multiple checkboxes: org.apache.commons.beanutils.ConversionException: Cannot assign value of type 'java.lang.String' to property 'accounts' of type 'java.util.ArrayList' The docs indicate that ArrayList is allowed in DynaActionForms (mine is a DynaValidatorForm): http://jakarta.apache.org/struts/userGuide/ building_controller.html#dyna _action_form_classes The multibox tag is: c:forEach items=${accountMap[accountForm.map.calendarYear]} var=account html-el:multibox property=accounts c:out value=${account.key}/ /html-el:multibox c:out value=${account.key}/nbsp; c:out value=${account.costCenterDesc}/