Re: Map backed form
Thank you Yasser. Changed the name of the properties file to use the model class name, it is in same package as the action so no change in location. But no success. After reading the link you sent, the text in the properties file should be Key_xxx & Element_xxx as you said before and should not be KeyProperty (this is for lists to identify the id inside the element itself). I have now tried the @Element on the variable rather than @TypeConversion which has to be used on setXXX method. This is working now as expected. Not sure why properties file or @TypeConversion did not work. https://struts.apache.org/core-developers/element-annotation.html Thanks for all your help. Thanks, Prasanth On 3/7/19 3:57 AM, Yasser Zamani wrote: > Hi Prasanth, > > I searched and saw it is some different for ModelDriven [1]. > > Regards. > > [1] > https://struts.apache.org/core-developers/type-conversion.html#applying-a-type-converter-to-a-bean-or-model > (Applying a Type Converter to a bean or model) > > On 3/6/2019 7:36 PM, Prasanth wrote: >> I have created the below in CompDeferralAction-conversion.properties (action >> class is CompDeferralAction). The variable name is deferralCode. But still >> struts is populating the value as Long rather >> than Integer. Am I missing anything here? >> This action is ModelDriven so the deferralCode variable is in a different >> class. >> >> Looking at the documentation seems like it should be KeyProperty, so I named >> it as such. >> KeyProperty_deferralCode=java.lang.Long >> Element_deferralCode=java.lang.Interger >> >> I have also tried the annotations >> >> @TypeConversion(rule=ConversionRule.MAP, key="java.lang.Long", >> value="java.lang.Integer") >> public void setDeferralCode(HashMap deferralCode) { >> this.deferralCode = deferralCode; >> } >> >> Thanks, >> Prasanth >> >> On 2/16/19 3:20 AM, Yasser Zamani wrote: >>> I think a file named yourActionClass-conversion.properties beside your >>> action with following contents should help [1]: >>> >>> Key_xxx=java.lang.Long >>> Element_xxx=java.lang.Double >>> >>> (where xxx is the field name of the collection property in your action or >>> object) >>> >>> Regards. >>> >>> [1] >>> https://struts.apache.org/core-developers/type-conversion.html#collection-and-map-support >>> >>>> -Original Message- >>>> From: Prasanth >>>> Sent: Friday, February 15, 2019 9:08 PM >>>> To: user@struts.apache.org >>>> Subject: Re: Map backed form >>>> >>>> Does struts follow a specific logic as to what the data type of the object >>>> would be >>>> based on user input? Meaning when is it converted to a Double vs Integer vs >>>> String? >>>> >>>> Thanks, >>>> Prasanth >>>> >>>> On 2/15/19 7:45 AM, Lukasz Lenart wrote: >>>>> pt., 15 lut 2019 o 00:17 Prasanth napisał(a): >>>>>> I have a map (Map) but based on the data entered by the >>>>>> user the value in the Map is Double or String. Example if the user >>>>>> enters a >>>> value of 10 then it is coming in as double but if the user enters 10.5 >>>> then a string >>>> is present in the value. Does Struts2 look at the data types of the key >>>> and value of >>>> the map and set the key and values in the map accordingly? >>>>> Struts is not a problem here, generic types are erased at runtime, so >>>>> basically this a Map at the end >>>>> https://docs.oracle.com/javase/tutorial/java/generics/erasure.html >>>>> >>>>>> If not, what is the best practice for the declaration of Map, is there a >>>>>> way to >>>> force Struts2 to only have Double objects as values? >>>>> I would probably use a custom type instead of Double and implement >>>>> converter for it, or even replace the Map with a List of custom >>>>> objects. >>>>> >>>>> >>>>> Regards >>> - >>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >>> For additional commands, e-mail: user-h...@struts.apache.org >>> >> > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org >
Re: Map backed form
Hi Prasanth, I searched and saw it is some different for ModelDriven [1]. Regards. [1] https://struts.apache.org/core-developers/type-conversion.html#applying-a-type-converter-to-a-bean-or-model (Applying a Type Converter to a bean or model) On 3/6/2019 7:36 PM, Prasanth wrote: > I have created the below in CompDeferralAction-conversion.properties (action > class is CompDeferralAction). The variable name is deferralCode. But still > struts is populating the value as Long rather > than Integer. Am I missing anything here? > This action is ModelDriven so the deferralCode variable is in a different > class. > > Looking at the documentation seems like it should be KeyProperty, so I named > it as such. > KeyProperty_deferralCode=java.lang.Long > Element_deferralCode=java.lang.Interger > > I have also tried the annotations > > @TypeConversion(rule=ConversionRule.MAP, key="java.lang.Long", > value="java.lang.Integer") > public void setDeferralCode(HashMap deferralCode) { > this.deferralCode = deferralCode; > } > > Thanks, > Prasanth > > On 2/16/19 3:20 AM, Yasser Zamani wrote: >> I think a file named yourActionClass-conversion.properties beside your >> action with following contents should help [1]: >> >> Key_xxx=java.lang.Long >> Element_xxx=java.lang.Double >> >> (where xxx is the field name of the collection property in your action or >> object) >> >> Regards. >> >> [1] >> https://struts.apache.org/core-developers/type-conversion.html#collection-and-map-support >> >>> -Original Message- >>> From: Prasanth >>> Sent: Friday, February 15, 2019 9:08 PM >>> To: user@struts.apache.org >>> Subject: Re: Map backed form >>> >>> Does struts follow a specific logic as to what the data type of the object >>> would be >>> based on user input? Meaning when is it converted to a Double vs Integer vs >>> String? >>> >>> Thanks, >>> Prasanth >>> >>> On 2/15/19 7:45 AM, Lukasz Lenart wrote: >>>> pt., 15 lut 2019 o 00:17 Prasanth napisał(a): >>>>> I have a map (Map) but based on the data entered by the >>>>> user the value in the Map is Double or String. Example if the user enters >>>>> a >>> value of 10 then it is coming in as double but if the user enters 10.5 then >>> a string >>> is present in the value. Does Struts2 look at the data types of the key and >>> value of >>> the map and set the key and values in the map accordingly? >>>> Struts is not a problem here, generic types are erased at runtime, so >>>> basically this a Map at the end >>>> https://docs.oracle.com/javase/tutorial/java/generics/erasure.html >>>> >>>>> If not, what is the best practice for the declaration of Map, is there a >>>>> way to >>> force Struts2 to only have Double objects as values? >>>> I would probably use a custom type instead of Double and implement >>>> converter for it, or even replace the Map with a List of custom >>>> objects. >>>> >>>> >>>> Regards >> >> - >> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >> For additional commands, e-mail: user-h...@struts.apache.org >> > >
Re: Map backed form
I have created the below in CompDeferralAction-conversion.properties (action class is CompDeferralAction). The variable name is deferralCode. But still struts is populating the value as Long rather than Integer. Am I missing anything here? This action is ModelDriven so the deferralCode variable is in a different class. Looking at the documentation seems like it should be KeyProperty, so I named it as such. KeyProperty_deferralCode=java.lang.Long Element_deferralCode=java.lang.Interger I have also tried the annotations @TypeConversion(rule=ConversionRule.MAP, key="java.lang.Long", value="java.lang.Integer") public void setDeferralCode(HashMap deferralCode) { this.deferralCode = deferralCode; } Thanks, Prasanth On 2/16/19 3:20 AM, Yasser Zamani wrote: > I think a file named yourActionClass-conversion.properties beside your action > with following contents should help [1]: > > Key_xxx=java.lang.Long > Element_xxx=java.lang.Double > > (where xxx is the field name of the collection property in your action or > object) > > Regards. > > [1] > https://struts.apache.org/core-developers/type-conversion.html#collection-and-map-support > >> -Original Message- >> From: Prasanth >> Sent: Friday, February 15, 2019 9:08 PM >> To: user@struts.apache.org >> Subject: Re: Map backed form >> >> Does struts follow a specific logic as to what the data type of the object >> would be >> based on user input? Meaning when is it converted to a Double vs Integer vs >> String? >> >> Thanks, >> Prasanth >> >> On 2/15/19 7:45 AM, Lukasz Lenart wrote: >>> pt., 15 lut 2019 o 00:17 Prasanth napisał(a): >>>> I have a map (Map) but based on the data entered by the >>>> user the value in the Map is Double or String. Example if the user enters a >> value of 10 then it is coming in as double but if the user enters 10.5 then >> a string >> is present in the value. Does Struts2 look at the data types of the key and >> value of >> the map and set the key and values in the map accordingly? >>> Struts is not a problem here, generic types are erased at runtime, so >>> basically this a Map at the end >>> https://docs.oracle.com/javase/tutorial/java/generics/erasure.html >>> >>>> If not, what is the best practice for the declaration of Map, is there a >>>> way to >> force Struts2 to only have Double objects as values? >>> I would probably use a custom type instead of Double and implement >>> converter for it, or even replace the Map with a List of custom >>> objects. >>> >>> >>> Regards > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org >
Re: Map backed form
Thank you Yasser. I will try that. On 2/16/19 3:20 AM, Yasser Zamani wrote: > I think a file named yourActionClass-conversion.properties beside your action > with following contents should help [1]: > > Key_xxx=java.lang.Long > Element_xxx=java.lang.Double > > (where xxx is the field name of the collection property in your action or > object) > > Regards. > > [1] > https://struts.apache.org/core-developers/type-conversion.html#collection-and-map-support > >> -Original Message- >> From: Prasanth >> Sent: Friday, February 15, 2019 9:08 PM >> To: user@struts.apache.org >> Subject: Re: Map backed form >> >> Does struts follow a specific logic as to what the data type of the object >> would be >> based on user input? Meaning when is it converted to a Double vs Integer vs >> String? >> >> Thanks, >> Prasanth >> >> On 2/15/19 7:45 AM, Lukasz Lenart wrote: >>> pt., 15 lut 2019 o 00:17 Prasanth napisał(a): >>>> I have a map (Map) but based on the data entered by the >>>> user the value in the Map is Double or String. Example if the user enters a >> value of 10 then it is coming in as double but if the user enters 10.5 then >> a string >> is present in the value. Does Struts2 look at the data types of the key and >> value of >> the map and set the key and values in the map accordingly? >>> Struts is not a problem here, generic types are erased at runtime, so >>> basically this a Map at the end >>> https://docs.oracle.com/javase/tutorial/java/generics/erasure.html >>> >>>> If not, what is the best practice for the declaration of Map, is there a >>>> way to >> force Struts2 to only have Double objects as values? >>> I would probably use a custom type instead of Double and implement >>> converter for it, or even replace the Map with a List of custom >>> objects. >>> >>> >>> Regards > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org >
Re: Map backed form
sob., 16 lut 2019 o 10:28 Yasser Zamani napisał(a): > > I think a file named yourActionClass-conversion.properties beside your action > with following contents should help [1]: > > Key_xxx=java.lang.Long > Element_xxx=java.lang.Double > > (where xxx is the field name of the collection property in your action or > object) Ahh right, totally forgot about that :) Regards -- Łukasz + 48 606 323 122 http://www.lenart.org.pl/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: Map backed form
I think a file named yourActionClass-conversion.properties beside your action with following contents should help [1]: Key_xxx=java.lang.Long Element_xxx=java.lang.Double (where xxx is the field name of the collection property in your action or object) Regards. [1] https://struts.apache.org/core-developers/type-conversion.html#collection-and-map-support >-Original Message- >From: Prasanth >Sent: Friday, February 15, 2019 9:08 PM >To: user@struts.apache.org >Subject: Re: Map backed form > >Does struts follow a specific logic as to what the data type of the object >would be >based on user input? Meaning when is it converted to a Double vs Integer vs >String? > >Thanks, >Prasanth > >On 2/15/19 7:45 AM, Lukasz Lenart wrote: >> pt., 15 lut 2019 o 00:17 Prasanth napisał(a): >>> I have a map (Map) but based on the data entered by the >>> user the value in the Map is Double or String. Example if the user enters a >value of 10 then it is coming in as double but if the user enters 10.5 then a >string >is present in the value. Does Struts2 look at the data types of the key and >value of >the map and set the key and values in the map accordingly? >> Struts is not a problem here, generic types are erased at runtime, so >> basically this a Map at the end >> https://docs.oracle.com/javase/tutorial/java/generics/erasure.html >> >>> If not, what is the best practice for the declaration of Map, is there a >>> way to >force Struts2 to only have Double objects as values? >> I would probably use a custom type instead of Double and implement >> converter for it, or even replace the Map with a List of custom >> objects. >> >> >> Regards
Re: Map backed form
Does struts follow a specific logic as to what the data type of the object would be based on user input? Meaning when is it converted to a Double vs Integer vs String? Thanks, Prasanth On 2/15/19 7:45 AM, Lukasz Lenart wrote: > pt., 15 lut 2019 o 00:17 Prasanth napisał(a): >> I have a map (Map) but based on the data entered by the user >> the value in the Map is Double or String. Example if the user enters a value >> of 10 then it is coming in as double but if the >> user enters 10.5 then a string is present in the value. Does Struts2 look at >> the data types of the key and value of the map and set the key and values in >> the map accordingly? > Struts is not a problem here, generic types are erased at runtime, so > basically this a Map at the end > https://docs.oracle.com/javase/tutorial/java/generics/erasure.html > >> If not, what is the best practice for the declaration of Map, is there a way >> to force Struts2 to only have Double objects as values? > I would probably use a custom type instead of Double and implement > converter for it, or even replace the Map with a List of custom > objects. > > > Regards
Re: Map backed form
pt., 15 lut 2019 o 00:17 Prasanth napisał(a): > I have a map (Map) but based on the data entered by the user > the value in the Map is Double or String. Example if the user enters a value > of 10 then it is coming in as double but if the > user enters 10.5 then a string is present in the value. Does Struts2 look at > the data types of the key and value of the map and set the key and values in > the map accordingly? Struts is not a problem here, generic types are erased at runtime, so basically this a Map at the end https://docs.oracle.com/javase/tutorial/java/generics/erasure.html > If not, what is the best practice for the declaration of Map, is there a way > to force Struts2 to only have Double objects as values? I would probably use a custom type instead of Double and implement converter for it, or even replace the Map with a List of custom objects. Regards -- Łukasz + 48 606 323 122 http://www.lenart.org.pl/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Map backed form
Hi, I have a map (Map) but based on the data entered by the user the value in the Map is Double or String. Example if the user enters a value of 10 then it is coming in as double but if the user enters 10.5 then a string is present in the value. Does Struts2 look at the data types of the key and value of the map and set the key and values in the map accordingly? If not, what is the best practice for the declaration of Map, is there a way to force Struts2 to only have Double objects as values? Thanks, Prasanth
[S2] How to use a Map backed form?
Hi all Using Map backed forms in Struts 1 was really great. I'm wondering how it works in Struts 2. Looking at the Type Conversion docs (http:// struts.apache.org/2.x/docs/type-conversion.html#TypeConversion- CollectionandMapSupport) seem to get close to explaining it, but jumps right into a complex indexed form field example. Ultimately, I can't get the Map in my Action to populate from the form correctly, and I'd like to know how to do it. I'm attempting to generate a bunch of dynamically named textfields like this: s:iterator value=%{fields} id=field s:textfield name=myField[%{field}] / /s:iterator This gives me fields that look like the following, which I expect: input type=text name=dynaField[firstField] ... / input type=text name=dynaField[secondField] ... / input type=text name=dynaField[thirdField] ... / input type=text name=dynaField[etc] ... / The Action that the form submits to looks something like this; class MyAction extends ActionSupport{ private MapString,String dynaField = new HashMapString,String(); public String execute()throws Exception{ //when I get here, the dynaField property is a valid HashMap that looks like //{null=the value of an unpredictable field} System.out.println(dynaField); return SUCCESS; } //Getter and Setter here public void setDynaField(MapString,String map){ dynaField = map; } public MapString,String getDynaField(){ return dynaField; } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
dynamic html:text property with map-backed form
My map-backed form has keys like index1, index2...indexN and i'm trying to out put hits by iterating like (according to the docos): logic:iterate name=name scope=request indexId=rId % |String name = value(foo + |rId| + );| % html:text property=%= name %/ ||/logic:iterate But my output is input type=text name=value(foo1) What am i missing? Thanks, MAnos - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamic html:text property with map-backed form
Emmanouil Batsis wrote: But my output is input type=text name=value(foo1) What am i missing? Let me rephrase that; can i output foo1 as the name attribute in the resulting HTML? Thanks, Manos - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Map-backed form property and multi-select
Hi, I'm using a map-backed property to get the data from a run-time generated form. If one of the controls in the form is a multi-select, I only get the first selected option. The form definition: form-bean name=myForm type=test.MyForm form-property name=paramValue type=java.util.Map/ ... /form-bean Setter method: public void setParamValue(String paramId, Object value) The select: html:select property=paramValue(%=paramName%) multiple=true html:options collection=entryes property=key labelProperty=value/ /html:select The setter is called only once having a String for value, even if I select multiple options. Can anyone please give me a hint? Thanks -- Radu - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Map-backed form property and multi-select
Not if it will be useful to you but when I generate dynamic forms I do the following thing: The form definition: form-bean name=myForm type=test.MyForm form-property name=paramValue type=java.lang.String[]/ ... /form-bean And then The select: html:select property=paramValue multiple=true html:options collection=entryes property=key labelProperty=value/ /html:select If option is selected String[] contains the Value else contains null. The String[] size is the select options size. I hope to have helped for you!! On Thu, 4 Nov 2004 20:22:45 +0200, Radu Badita [EMAIL PROTECTED] wrote: Hi, I'm using a map-backed property to get the data from a run-time generated form. If one of the controls in the form is a multi-select, I only get the first selected option. The form definition: form-bean name=myForm type=test.MyForm form-property name=paramValue type=java.util.Map/ ... /form-bean Setter method: public void setParamValue(String paramId, Object value) The select: html:select property=paramValue(%=paramName%) multiple=true html:options collection=entryes property=key labelProperty=value/ /html:select The setter is called only once having a String for value, even if I select multiple options. Can anyone please give me a hint? Thanks -- Radu - 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]
Map Backed Form and JavaScript
Hi, I am making use of Map backed Action form Lets say I have named the textbox field as follows html:text property=dto(name)/ How can I access the text field value from JavaScript for instance I can't do something like this. document.forms[0].dto(name).value; (but this will give a JS error) any workaround or can we use any escape sequence in JS -Hari - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Map Backed Form and JavaScript
document.forms[0]['dto(name)'].value Hariharan V wrote: Hi, I am making use of Map backed Action form Lets say I have named the textbox field as follows html:text property=dto(name)/ How can I access the text field value from JavaScript for instance I can't do something like this. document.forms[0].dto(name).value; (but this will give a JS error) any workaround or can we use any escape sequence in JS -Hari - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
multiselect with a map-backed form property
I have a form with a dynamically generated list of constraints that can be turned on or off, and each constraint has a set of values associated with it. My form has two relevant fields: private String[] selectedConstraints; private Map values; public String[] getSelectedConstraints() { return selectedConstraints; } public void setSelectedConstraints(String[] selectedConstraints) { this.selectedConstraints = selectedConstraints; } public Object getValues(String key) { return values.get(key); } public void setValues(String key, Object value) { values.put(key, value); } To keep track of which values are associated with which constraint, I use the string from the selectedConstraints array as the key into the values map. My jsp page looks like this: c:forEach var=constraint items=${constraints} trtd html:multibox property=selectedConstraints c:out value=${constraint.propertyID}/ /html:multibox c:out value=${constraint.propertyName}/ /tdtd html-el:select property=values(${constraint.propertyID}) html:optionsCollection name=constraint property=allowableValues/ /html-el:select ... The above works perfectly fine as long as only want to select a single item from the select drop-down box. The problem is some of the constraints can have multiple values, so I changed the select to a multi-select: html-el:select multiple=true property=values(${constraint.propertyID}) But then the form is only ever populated with the *first* string selected from the multiselect box. Since a map can hold a String[] as easily as a String, I'm a little confused by this behavior. I tried the following things with no luck (these changes are in the struts action that forwards to the jsp above): 1) inserting an empty String array into the values map for each key in an attempt to coerce the user of String arrays 2) inserting a wrapper class into the map for each key: public class SelectedValues { private String[] selectedValues; public String[] getSelectedValues() { return selectedValues; } public void setSelectedValues(String[] selectedValues) { this.selectedValues = selectedValues; } } and I updated my jsp to: html-el:select multiple=true property=values(${constraint.propertyID}).selectedValues but that causes the following exception: javax.servlet.ServletException: BeanUtils.populate org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254) ... root cause: java.lang.IllegalArgumentException: No bean specified org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptor(PropertyUtils.java:837) ... I can get the multiselect to work if I create a String array for each constraint, but that defeats the purpose since this is supposed to be dynamically generated. I'm out of ideas for other things to try with the map-backed approach. Can someone tell me what I'm doing wrong here? Thanks, Adam - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Map backed form with list of String Arrays
I am having a problem with a map-backed form and html:select with multiple=true. Would appreciate any help/ideas. I need to display a set of html:select lists. The number of lists is user-defined (based on database data) and each select list must allow more than one choice to be selected. I settled on using a map property in the form bean as the manual suggests. Everything works great on initial display, furthermore I am selecting all values which will be the normal use case for the user. However, upon return, only a single value is passed in. Should I be using the value attribute on the html:select tag? I cannot seem to figure out how to make it work as an array. Here are the relevant struts/JSTL tags. c:forEach items=${form1.choiceList} var=valueArray td style=text-align: center; c:set var=cList value=${Collection_charChoices[choiceArray.key]}/ html-el:select name=form1 property=choiceLists(${choiceArray.key}) size=6 multiple=true value=choiceLists($choiceArray.key) html-el:options collection=cList property=id labelProperty=name/ /html-el:select /td /c:forEach Here is a code snipped I use to inspect the map as it comes in (afer having been successfully sent out and displayed with all values selected): Set keySet = map.keySet(); Iterator ik = keySet.iterator(); while (ik.hasNext()) { Object key = (String)ik.next(); log.debug(showMap - mapKey='+key.toString()+'); Object value = map.get(key); if ( value instanceof String[] ) { String[] valArray = (String[]) value; for (int i=0;ivalArray.length;i++) log.debug(showMap - valArray[+i+]='+valArray[i]+'); } else { log.debug(showMap - value instanceof '+value.getClass().getName()+'); log.debug(showMap - value='+value.toString()+'); } } It shows a simple String object (the first choice in the options list, actually) rather than the String[] that was sent out. Thank you again - Richard - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: DynaAction or Map Backed Form?
It isn't clear what you have to work with. Is services a map of some sort, or is it a collection. Either way you should use the iterate tag in the logic tag set. If you could explain the data structure better, it would be easier to help. -Original Message- From: Amin Lalji [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 07, 2004 12:39 PM To: 'Struts Users Mailing List' Subject: RE: DynaAction or Map Backed Form? Sorry... to add... Each Service may have a unknown set of documents... E.g. Services: 001 Catering 002 Party Documents: 001 Contract 002 Deposit Should yield: input type=checkbox name=Catering[0].id value=001Contract input type=checkbox name=Catering[1].id value=002Deposit input type=checkbox name=Party[0].id value=001Contract input type=checkbox name=Party[1].id value=002Deposit Thanks, /A -Original Message- From: Amin Lalji [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 07, 2004 2:28 PM To: 'Struts Users Mailing List' Subject: DynaAction or Map Backed Form? Hello All, I have the following scenario: I need to populate a form using a runtime generated set of form properties... Essentially I have two collections I pull from a database Services (serviceID,serviceName) Documents (documentID,documentName) I want to populate a set of checkboxes for each service such that I achieve: input type=checkbox name=serviceName[0].id value=documentIDdocumentName Any ideas? Thanks, Amin - 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: DynaAction or Map Backed Form?
Im not sure how to do it with the iterate tag, I use the c:forEach tag in the jstl taglib. It goes something like this: Assume service is a bean with accessors getDocuments ( ) and getId ( ) Assume document is a bean wit accessors getId ( ) and getName ( ) c:forEach var='service' items='services' c:forEach var='document' items='service.documents' input type=checkbox name='${service.id} value='${document.id}'c:out value='${document.name}'/ c:forEach c:foreach -Original Message- From: Amin Lalji [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 07, 2004 1:26 PM To: 'Struts Users Mailing List' Subject: RE: DynaAction or Map Backed Form? Here is the Data structure: I have two tables (Services, Documents) I hit the database and pull two separate Collections. I need to iterate over both collections... here is the relationship: ServiceID ServiceName Documents DocumentID DocumentName So a service object contains a collection of documents I need to be able to output something like: input type=checkbox name=ServiceID[0].id value=DocumentIDDocumentName --- input type=checkbox name=Catering[0].id value=001Contract input type=checkbox name=Catering[1].id value=002Deposit input type=checkbox name=Party[0].id value=001Contract input type=checkbox name=Party[1].id value=002Deposit In my action, I created a DynaActionForm. I set a java.util.ArrayList property called requiredDocuments in struts-config.xml In my action I make the database calls, then I iterate the services collection creating a RequiredDocumentsBean (contains serviceID, serviceName, and documents Collection) I populate the first two properties (serviceID, and serviceName) and then iterate the documents collection setting a LabelValueBean Here is the code: -- snip -- while(sIterator.hasNext()){ // for each service... RequiredDocumentsBean rd = new RequiredDocumentsBean(); ServiceBeanLocal service = (ServiceBeanLocal)sIterator.next(); rd.setServiceId(service.getId()); rd.setServiceName(service.getServiceName()); Iterator dIterator = documents.iterator(); while(dIterator.hasNext()){ // for each available document DocumentBeanValue document = DocumentBeanValue)dIterator.next(); rd.getRequiredDocuments().add(new LabelValueBean(document.getDocumentName(),document.getId())); } requiredDocuments.add(rd); } myForm.set(allRequiredDocuments,requiredDocuments); request.setAttribute(allRequiredDocuments,requiredDocuments); -- snip -- Thanks -Original Message- From: Ray Madigan [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 07, 2004 3:09 PM To: Struts Users Mailing List Subject: RE: DynaAction or Map Backed Form? It isn't clear what you have to work with. Is services a map of some sort, or is it a collection. Either way you should use the iterate tag in the logic tag set. If you could explain the data structure better, it would be easier to help. -Original Message- From: Amin Lalji [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 07, 2004 12:39 PM To: 'Struts Users Mailing List' Subject: RE: DynaAction or Map Backed Form? Sorry... to add... Each Service may have a unknown set of documents... E.g. Services: 001 Catering 002 Party Documents: 001 Contract 002 Deposit Should yield: input type=checkbox name=Catering[0].id value=001Contract input type=checkbox name=Catering[1].id value=002Deposit input type=checkbox name=Party[0].id value=001Contract input type=checkbox name=Party[1].id value=002Deposit Thanks, /A -Original Message- From: Amin Lalji [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 07, 2004 2:28 PM To: 'Struts Users Mailing List' Subject: DynaAction or Map Backed Form? Hello All, I have the following scenario: I need to populate a form using a runtime generated set of form properties... Essentially I have two collections I pull from a database Services (serviceID,serviceName) Documents (documentID,documentName) I want to populate a set of checkboxes for each service such that I achieve: input type=checkbox name=serviceName[0].id value=documentIDdocumentName Any ideas? Thanks, Amin - 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]