RE: OptionsCollectionTag with ActionForm and a collection attribute
Collections are more convenient to use than arrays (of course, disagreement on this is allowed :) and they integrate more easily to the rest of the codebase, which uses collections everywhere. Multiple values can be selected (multiple="true"), so the selected options would be a collection. In this example, I would expect it to be a collection of Choice objectsalthough a collection of Strings (as a collection of parameters) or a collection of Integers (collection of Choice.ids) I would also understand, too. Even the struts examples (struts-exercise-taglib.war) use only arrays to model the selected options. This seems odd, since it would be logical to allow selected options to be stored in a collection, since all available options are stored in a collection. Plus, it seems to work to one way but not the other (JSP gets populated ok, problems occur only when submitting the form). Oh well, it seems that struts documentation http://struts.apache.org/userGuide/struts-html.html#select states that "multiple="true" IS selected - The corresponding property should be an array of any supported data type." so I think I am out of luck here. Funny though that it works halfway... From: <[EMAIL PROTECTED]> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Subject: RE: OptionsCollectionTag with ActionForm and a collection attribute Date: Tue, 10 Aug 2004 12:29:59 +0530 Why do you want to store it in a collection ?? The selected option would be a String right ?? -Original Message- From: Janne Mattila [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 10, 2004 11:54 AM To: [EMAIL PROTECTED] Subject: RE: OptionsCollectionTag with ActionForm and a collection attribute No takers on this? If I am renderin a select box in JSP with selectTag and optionsCollectionTag, can my form bean store the selected options in a collection? (instead of an array, which seems to work fine) >From: "Janne Mattila" <[EMAIL PROTECTED]> >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> >To: [EMAIL PROTECTED] >Subject: OptionsCollectionTag with ActionForm and a collection >attribute >Date: Mon, 09 Aug 2004 09:54:57 + > >I am just studying the basic things about Struts, and have some trouble >getting selectTag and optionsCollectionTag work as I would expect. >Intention is to have two properties in a form: allChoices, that is a >collection holding all possible choices for the select tag, and >selectedChoicesCollection, that contains the currently selected ones. Each >choice is modelled by a class Choice, that contains two attributes, id for >identifying the selection and name, which is displaed to the user. >SelectedChoicesCollection contains only the values of the Choices (as >having it contain Choice objects did not seem to work at all). > >I have to actions, SimpleGetAction and SimpleSaveAction. User starts by >calling a URL which maps to SimpleGetAction. This action populates the form >object and moves on to the JSP page. This part works out as I excpect, and >the correct choice(s) is highlighted. When user submits the form, >SimpleSaveAction gets called - except that BeanUtils.populate throws an >exception before action gets it's turn: > >12:34:46,268 INFO [STDOUT] DEBUG >[org.apache.struts.util.RequestUtils][1799] Get module name for path >/SaveSimpleTest.do >12:34:46,268 INFO [STDOUT] DEBUG >[org.apache.struts.util.RequestUtils][1821] Module name found: default >12:34:46,268 INFO [STDOUT] DEBUG >[org.apache.struts.action.RequestProcessor][225] Processing a 'POST' for >path '/SaveSimpleTest' >12:34:46,268 INFO [STDOUT] DEBUG >[org.apache.struts.util.RequestUtils][764] Looking for ActionForm bean >instance in scope 'request' under attribute key 'simp >eForm' >12:34:46,268 INFO [STDOUT] DEBUG >[org.apache.struts.util.RequestUtils][839] Creating new ActionForm >instance of type 'jannen.form.SimpleTestForm' >12:34:46,268 INFO [STDOUT] DEBUG >[org.apache.struts.util.RequestUtils][844] --> jannen.form.SimpleTestForm >selectedChoicesArray: selectedChoicesCollection: >3] >12:34:46,308 INFO [STDOUT] DEBUG >[org.apache.struts.action.RequestProcessor][372] Storing ActionForm bean >instance in scope 'request' under attribute key 'si >pleForm' >12:34:46,388 INFO [STDOUT] DEBUG >[org.apache.struts.action.RequestProcessor][813] Populating bean >properties from this request >12:34:46,388 ERROR [Engine] StandardWrapperValve[action]: Servlet.service() >for servlet action threw exception >javax.servlet.ServletException: BeanUtils.populate >at >org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254) >at >o
RE: OptionsCollectionTag with ActionForm and a collection attribute
Why do you want to store it in a collection ?? The selected option would be a String right ?? -Original Message- From: Janne Mattila [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 10, 2004 11:54 AM To: [EMAIL PROTECTED] Subject: RE: OptionsCollectionTag with ActionForm and a collection attribute No takers on this? If I am renderin a select box in JSP with selectTag and optionsCollectionTag, can my form bean store the selected options in a collection? (instead of an array, which seems to work fine) >From: "Janne Mattila" <[EMAIL PROTECTED]> >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> >To: [EMAIL PROTECTED] >Subject: OptionsCollectionTag with ActionForm and a collection >attribute >Date: Mon, 09 Aug 2004 09:54:57 + > >I am just studying the basic things about Struts, and have some trouble >getting selectTag and optionsCollectionTag work as I would expect. >Intention is to have two properties in a form: allChoices, that is a >collection holding all possible choices for the select tag, and >selectedChoicesCollection, that contains the currently selected ones. Each >choice is modelled by a class Choice, that contains two attributes, id for >identifying the selection and name, which is displaed to the user. >SelectedChoicesCollection contains only the values of the Choices (as >having it contain Choice objects did not seem to work at all). > >I have to actions, SimpleGetAction and SimpleSaveAction. User starts by >calling a URL which maps to SimpleGetAction. This action populates the form >object and moves on to the JSP page. This part works out as I excpect, and >the correct choice(s) is highlighted. When user submits the form, >SimpleSaveAction gets called - except that BeanUtils.populate throws an >exception before action gets it's turn: > >12:34:46,268 INFO [STDOUT] DEBUG >[org.apache.struts.util.RequestUtils][1799] Get module name for path >/SaveSimpleTest.do >12:34:46,268 INFO [STDOUT] DEBUG >[org.apache.struts.util.RequestUtils][1821] Module name found: default >12:34:46,268 INFO [STDOUT] DEBUG >[org.apache.struts.action.RequestProcessor][225] Processing a 'POST' for >path '/SaveSimpleTest' >12:34:46,268 INFO [STDOUT] DEBUG >[org.apache.struts.util.RequestUtils][764] Looking for ActionForm bean >instance in scope 'request' under attribute key 'simp >eForm' >12:34:46,268 INFO [STDOUT] DEBUG >[org.apache.struts.util.RequestUtils][839] Creating new ActionForm >instance of type 'jannen.form.SimpleTestForm' >12:34:46,268 INFO [STDOUT] DEBUG >[org.apache.struts.util.RequestUtils][844] --> jannen.form.SimpleTestForm >selectedChoicesArray: selectedChoicesCollection: >3] >12:34:46,308 INFO [STDOUT] DEBUG >[org.apache.struts.action.RequestProcessor][372] Storing ActionForm bean >instance in scope 'request' under attribute key 'si >pleForm' >12:34:46,388 INFO [STDOUT] DEBUG >[org.apache.struts.action.RequestProcessor][813] Populating bean >properties from this request >12:34:46,388 ERROR [Engine] StandardWrapperValve[action]: Servlet.service() >for servlet action threw exception >javax.servlet.ServletException: BeanUtils.populate >at >org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254) >at >org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessorjava:821) >at >org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254) >at >org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) >at >org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525) >at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) >at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) >at >org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) >at >org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) >at >org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) >at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) >at >org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) >at >org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) >at >org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) >at >org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) >at >org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm
RE: OptionsCollectionTag with ActionForm and a collection attribute
No takers on this? If I am renderin a select box in JSP with selectTag and optionsCollectionTag, can my form bean store the selected options in a collection? (instead of an array, which seems to work fine) From: "Janne Mattila" <[EMAIL PROTECTED]> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Subject: OptionsCollectionTag with ActionForm and a collection attribute Date: Mon, 09 Aug 2004 09:54:57 + I am just studying the basic things about Struts, and have some trouble getting selectTag and optionsCollectionTag work as I would expect. Intention is to have two properties in a form: allChoices, that is a collection holding all possible choices for the select tag, and selectedChoicesCollection, that contains the currently selected ones. Each choice is modelled by a class Choice, that contains two attributes, id for identifying the selection and name, which is displaed to the user. SelectedChoicesCollection contains only the values of the Choices (as having it contain Choice objects did not seem to work at all). I have to actions, SimpleGetAction and SimpleSaveAction. User starts by calling a URL which maps to SimpleGetAction. This action populates the form object and moves on to the JSP page. This part works out as I excpect, and the correct choice(s) is highlighted. When user submits the form, SimpleSaveAction gets called - except that BeanUtils.populate throws an exception before action gets it's turn: 12:34:46,268 INFO [STDOUT] DEBUG [org.apache.struts.util.RequestUtils][1799] Get module name for path /SaveSimpleTest.do 12:34:46,268 INFO [STDOUT] DEBUG [org.apache.struts.util.RequestUtils][1821] Module name found: default 12:34:46,268 INFO [STDOUT] DEBUG [org.apache.struts.action.RequestProcessor][225] Processing a 'POST' for path '/SaveSimpleTest' 12:34:46,268 INFO [STDOUT] DEBUG [org.apache.struts.util.RequestUtils][764] Looking for ActionForm bean instance in scope 'request' under attribute key 'simp eForm' 12:34:46,268 INFO [STDOUT] DEBUG [org.apache.struts.util.RequestUtils][839] Creating new ActionForm instance of type 'jannen.form.SimpleTestForm' 12:34:46,268 INFO [STDOUT] DEBUG [org.apache.struts.util.RequestUtils][844] --> jannen.form.SimpleTestForm selectedChoicesArray: selectedChoicesCollection: 3] 12:34:46,308 INFO [STDOUT] DEBUG [org.apache.struts.action.RequestProcessor][372] Storing ActionForm bean instance in scope 'request' under attribute key 'si pleForm' 12:34:46,388 INFO [STDOUT] DEBUG [org.apache.struts.action.RequestProcessor][813] Populating bean properties from this request 12:34:46,388 ERROR [Engine] StandardWrapperValve[action]: Servlet.service() for servlet action threw exception javax.servlet.ServletException: BeanUtils.populate at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254) at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:220) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.jboss.web.tomcat.tc4.statistics.ContainerStatsValve.invoke(ContainerStatsValve.java:76) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)