Re: [S2] Beans list in Dynamic form and ParametersInterceptor problem
Hi. I've solved the problem. And the solution was... reading the documentation with great attention!!! In particular, from http://struts.apache.org/2.0.11/docs/type-conversion.html, the paragraph Relationship to Parameter Names: 1 - Use JavaBeans! The framework can only create objects if the objects obey the JavaBean specification and provide no-arg constructions, as well as getters and setters where appropriate 2 - Remember that person.name will call getPerson().setName(), but if in order for the framework to create the Person object for you, a setPerson must also exist So: in the bean class, I've added a no-arg constructor; in the action class, I've added a property Song and a setSong method. And now I'm able to fill the list of beans modified from the form in the jsp, and use it in the action. I summerize all for future benefits. -Problem: submit a dynamic form created with a list of beans and use these beans in the action. -BEAN Provide a no-arg constructor and getters and setters for all properties. public class Song implements Serializable { private String SongId; private String StartDate; private String EndDate; private String StatusLoad; private String StatusSellable; public Song(){} public String getStartDate() {return StartDate;} public void setStartDate(String startDate) {StartDate = startDate;} public String getEndDate() {return EndDate;} public void setEndDate(String endDate) {EndDate = endDate;} public String getStatusLoad() {return StatusLoad;} public void setStatusLoad(String statusLoad) {StatusLoad = statusLoad;} public String getStatusSellable() {return StatusSellable;} public void setStatusSellable(String statusSellable) {StatusSellable = statusSellable;} public String getSongId() {return SongId;} public void setSongId(String songId) {SongId = songId;} } -ACTION Provide the beans list property with get and set, and a bean property with set. public class ResubmitAction extends BaseAction { private ListSong songs = new ArrayList(); private Song song = null; public String resubmitCatalog() { ... //use the beans list coming from the form if (this.songs != null) { log.debug(song list size +songs.size()); Iterator iter = this.songs.iterator(); while (iter.hasNext()) { Song tmp = (Song) iter.next(); if (tmp != null) { log.debug(--\n+tmp.toString()+\n--); } } } } public ListSong getSongs() {return songs;} public void setSongs(ListSong songs) {this.songs = songs;} public void setSong(Song song) {this.song = song;} } -CONVERSION PROPERTIES FILE Create a ActionName-conversion.properties file in the same path of the action, so in my case ResubmitAction-conversion.properties where ResubmitAction.class is located. Element_songs=console.beans.Song CreateIfNull_songs=true In the first version of the file there was also the line KeyProperty_songs=SongId but this is useless because in the jsp I don't use the unique id of the bean for iteration throw the list. -JSP Create the form using iterator tag and use stat.index to reference the current iteration index. Pay attention to the ognl expression. s:iterator id=Song value=songs status=stat tr td s:hidden name=songs[%{#stat.index}].songId/ /td /tr tr td class=txtBoldSTART DATE/td tdjscalendar:jscalendar format=%d.%m.%Y name=songs[%{#stat.index}].startDate //td /tr tr td class=txtBoldEND DATE/td tdjscalendar:jscalendar format=%d.%m.%Y name=songs[%{#stat.index}].endDate//td /tr tr td class=txtBoldSTATUS LOAD/td tds:textfield theme=simple name=songs[%{#stat.index}].statusLoad //td /tr tr td class=txtBoldSTATUS SELLABLE/td tds:textfield theme=simple name=songs[%{#stat.index}].statusSellable //td /tr /s:iterator and the resulting html is (the beans list has 2 elements): input type=hidden id=ResubmitCatalog_songs_0__songId value=9121587 name=songs[0].songId/ input type=text id=ResubmitCatalog_songs_0__startDate value=29.11.2007 name=songs[0].startDate/ input type=text id=ResubmitCatalog_songs_0__endDate value=29.11.2007 name=songs[0].endDate/ input type=text id=ResubmitCatalog_songs_0__statusLoad value=Publish name=songs[0].statusLoad/ input type=text id=ResubmitCatalog_songs_0__statusSellable value=1 name=songs[0].statusSellable/ input type=hidden id=ResubmitCatalog_songs_1__songId value=9121591 name=songs[1].songId/ input type=text id=ResubmitCatalog_songs_1__startDate value=29.11.2007 name=songs[1].startDate/ input type=text id=ResubmitCatalog_songs_1__endDate value=29.11.2007 name=songs[1].endDate/ input
Re: [S2] Beans list in Dynamic form and ParametersInterceptor problem
The problem looks to be that you're using the song ID as a list index: s:iterator id=Song value=songs tr tds:hidden name=songs[%{#Song.SongId}].SongId ... If the value of SongId for the first item in the list is 658, on submit Struts will try and put that song's data at index 658 in the list...! What you probably want is: s:iterator id=Song value=songs status=stat tr tds:hidden name=songs[%{#stat.index}].SongId ... (where status.index references the current iteration index). HTH, L. totojack wrote: Hi. I'm having problem in submitting a dynamic form created with a list of beans. I'm able to build the jsp with the form and (it seems...) to pass parameters to action, but I'm not able to get the correct list of beans after submitting the form. I've tried with a list of 2 beans. Something really strange happens: the list in the action is not null (ok, this shouldn't be strange, if I've done all correctly) and has a size equals to the id of a bean (and this is really strange, maybe there's something wrong?...). Due to the list size, at the end of the action there is also OutOfMemoryError (Java heap space). So, is it an ognl expression problem? I've tried many version but without success. name=#Song[SongId].startDate name=%{#Song[SongId]}.endDate name=songs[SongId].statusLoad name=songs[#Song.SongId].statusSellable name=%{songs[#Song.SongId]}.endDate name=%{#songs[Song.SongId]}.statusLoad I'm using struts 2.0.11. Some code: -ACTION public class ResubmitAction extends BaseAction { private ListSong songs = new ArrayList(); public String resubmitCatalog() { ... if(songs != null) { log.debug(song size +songs.size()); } } public ListSong getSongs() {return songs;} public void setSongs(ListSong songs) {this.songs = songs;} } -BEAN public class Song implements Serializable { private String SongId; ... private String StartDate; private String EndDate; private String StatusLoad; private String StatusSellable; ... public String getStartDate() {return StartDate;} public void setStartDate(String startDate) {StartDate = startDate;} public String getEndDate() {return EndDate;} public void setEndDate(String endDate) {EndDate = endDate;} public String getStatusLoad() {return StatusLoad;} public void setStatusLoad(String statusLoad) {StatusLoad = statusLoad;} public String getStatusSellable() {return StatusSellable;} public void setStatusSellable(String statusSellable) {StatusSellable = statusSellable;} public String getSongId() {return SongId;} public void setSongId(String songId) {SongId = songId;} } -CONVERSION PROP ResubmitAction-Conversion.properties (in the same path of ResubmitAction.java) KeyProperty_songs=SongId Element_songs=console.beans.Song CreateIfNull_songs=true -JSP s:iterator id=Song value=songs tr tds:hidden name=songs[%{#Song.SongId}].SongId value=%{#Song.SongId}//td /tr tr td class=txtBoldSTART DATE/td tds:textfield theme=simple name=songs[%{#Song.SongId}].startDate //td /tr tr td class=txtBoldEND DATE/td tds:textfield theme=simple name=songs[%{#Song.SongId}].endDate//td /tr tr td class=txtBoldSTATUS LOAD/td tds:textfield theme=simple name=songs[%{#Song.SongId}].statusLoad //td /tr tr td class=txtBoldSTATUS SELLABLE/td tds:textfield theme=simple name=songs[%{#Song.SongId}].statusSellable //td /tr /s:iterator and the HTML is: input type=hidden id=ResubmitCatalog_songs_9121587__SongId value=9121587 name=songs[9121587].SongId/ input type=text id=ResubmitCatalog_songs_9121587__startDate value= name=songs[9121587].startDate/ input type=text id=ResubmitCatalog_songs_9121587__endDate value= name=songs[9121587].endDate/ input type=text id=ResubmitCatalog_songs_9121587__statusLoad value= name=songs[9121587].statusLoad/ input type=text id=ResubmitCatalog_songs_9121587__statusSellable value= name=songs[9121587].statusSellable/ and another group of input with the second id 9121591 -LOG DEBUG (interceptor.ParametersInterceptor:148) - Setting params (...) songs[9121591].startDate = [ XXX ] songs[9121587].endDate = [ XXX ] songs[9121591].statusLoad = [ XXX ] songs[9121587].statusSellable = [ XXX ] songs[9121587].SongId = [ 9121587 ] songs[9121591].endDate = [ XXX ] songs[9121587].startDate = [ XXX ] songs[9121591].SongId = [ 9121591 ] songs[9121591].statusSellable = [ XXX ] songs[9121587].statusLoad = [ XXX ] ERROR (interceptor.ParametersInterceptor:204) - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'songs[9121587].SongId' on 'class it.telecomitalia.orchestrator.console.actions.ResubmitAction: Error setting expression 'songs[9121587].SongId' with value '[Ljava.lang.String;@3ed81c' ERROR (interceptor.ParametersInterceptor:204) - ParametersInterceptor - [setParameters]: Unexpected
Re: [S2] Beans list in Dynamic form and ParametersInterceptor problem
The problem of songs list size is solved using #stat.index. But not the parameters error. The list size now is 1, but the element inside is null. So, it can't create song beans and put it into the list. In the conversion props file the Element_songs is correctly set to the Song bean class. The KeyProperty is useless now using the iterator index? Here some logs: DEBUG (interceptor.ParametersInterceptor:148) - Setting params songs[1].endDate = [ 01.01.2099 ] [ ] songs[0].endDate = [ 01.01.2099 ] songs[0].statusLoad = [ Publish ] songs[0].statusSellable = [ 1 ] songs[1].songId = [ 9121591 ] songs[1].statusLoad = [ Publish ] songs[1].statusSellable = [ 1 ] songs[0].songId = [ 9121587 ] songs[0].startDate = [ 29.11.2007 ] songs[1].startDate = [ 29.11.2007 ] ERROR (interceptor.ParametersInterceptor:204) - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'songs[0].endDate' on 'class it.telecomitalia.orchestrator.console.actions.ResubmitAction: Error setting expression 'songs[0].endDate' with value '[Ljava.lang.String;@16825b5' (...) Reading the manual at http://struts.apache.org/2.0.11/docs/type-conversion.html it says: Notice the () notation! Do not use [] notation, which is for Maps only! but changing the notation from songs[%{#stat.index}].property to songs(%{#stat.index}).property in the jsp, the form isn't populated. -- View this message in context: http://www.nabble.com/-S2--Beans-list-in-Dynamic-form-and-ParametersInterceptor-problem-tp15016850p15022328.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [S2] Beans list in Dynamic form and ParametersInterceptor problem
Does this stack trace begin with a java.lang.OutOfMemoryError as well? Have you tried increasing the heap space size for your Web Server? Just a thought . . . Regards, David Hernandez -Original Message- From: totojack [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 22, 2008 11:35 AM To: user@struts.apache.org Subject: Re: [S2] Beans list in Dynamic form and ParametersInterceptor problem The problem of songs list size is solved using #stat.index. But not the parameters error. The list size now is 1, but the element inside is null. So, it can't create song beans and put it into the list. In the conversion props file the Element_songs is correctly set to the Song bean class. The KeyProperty is useless now using the iterator index? Here some logs: DEBUG (interceptor.ParametersInterceptor:148) - Setting params songs[1].endDate = [ 01.01.2099 ] [ ] songs[0].endDate = [ 01.01.2099 ] songs[0].statusLoad = [ Publish ] songs[0].statusSellable = [ 1 ] songs[1].songId = [ 9121591 ] songs[1].statusLoad = [ Publish ] songs[1].statusSellable = [ 1 ] songs[0].songId = [ 9121587 ] songs[0].startDate = [ 29.11.2007 ] songs[1].startDate = [ 29.11.2007 ] ERROR (interceptor.ParametersInterceptor:204) - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'songs[0].endDate' on 'class it.telecomitalia.orchestrator.console.actions.ResubmitAction: Error setting expression 'songs[0].endDate' with value '[Ljava.lang.String;@16825b5' (...) Reading the manual at http://struts.apache.org/2.0.11/docs/type-conversion.html it says: Notice the () notation! Do not use [] notation, which is for Maps only! but changing the notation from songs[%{#stat.index}].property to songs(%{#stat.index}).property in the jsp, the form isn't populated. -- View this message in context: http://www.nabble.com/-S2--Beans-list-in-Dynamic-form-and-ParametersInte rceptor-problem-tp15016850p15022328.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. IRS Circular 230 Disclosure: Please be advised that any discussion of U.S. tax matters contained within this communication (including any attachments) is not intended or written to be used and cannot be used for the purpose of (i) avoiding U.S. tax related penalties or (ii) promoting, marketing or recommending to another party any transaction or matter addressed herein. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [S2] Beans list in Dynamic form and ParametersInterceptor problem
Hi totojack- I think you're right that the key property is useless now that you're using the positional index to access your list elements. Also, the type conversion page says that using the unique id indexed approach won't allow for automatic creation of instances. The docs say the following: Unlike Map and List element properties, if fooCollection(22) does not exist, it will not be created. If you would like it created, use the notation fooCollection.makeNew[index] where index is an integer 0, 1, and so on. I haven't been able to get makeNew to work and no one on the list responded to a previous question on it so I'm assuming that the feature is deprecated and the documentation is out of date. Which is really a shame since positional indexing of a list comes with some risks that accessing elements by unique id does not. You can write some hacks to get around this, but they lack the elegance that a web framework that really understood collections could have provided. totojack wrote: The problem of songs list size is solved using #stat.index. But not the parameters error. The list size now is 1, but the element inside is null. So, it can't create song beans and put it into the list. In the conversion props file the Element_songs is correctly set to the Song bean class. The KeyProperty is useless now using the iterator index? Here some logs: DEBUG (interceptor.ParametersInterceptor:148) - Setting params songs[1].endDate = [ 01.01.2099 ] [ ] songs[0].endDate = [ 01.01.2099 ] songs[0].statusLoad = [ Publish ] songs[0].statusSellable = [ 1 ] songs[1].songId = [ 9121591 ] songs[1].statusLoad = [ Publish ] songs[1].statusSellable = [ 1 ] songs[0].songId = [ 9121587 ] songs[0].startDate = [ 29.11.2007 ] songs[1].startDate = [ 29.11.2007 ] ERROR (interceptor.ParametersInterceptor:204) - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'songs[0].endDate' on 'class it.telecomitalia.orchestrator.console.actions.ResubmitAction: Error setting expression 'songs[0].endDate' with value '[Ljava.lang.String;@16825b5' (...) Reading the manual at http://struts.apache.org/2.0.11/docs/type-conversion.html it says: Notice the () notation! Do not use [] notation, which is for Maps only! but changing the notation from songs[%{#stat.index}].property to songs(%{#stat.index}).property in the jsp, the form isn't populated. -- View this message in context: http://www.nabble.com/-S2--Beans-list-in-Dynamic-form-and-ParametersInterceptor-problem-tp15016850p15024812.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [S2] Beans list in Dynamic form and ParametersInterceptor problem
Hi David, the OutOfMemoryError was solved using %{#stat.index} in the inputs, as suggested by Laurie Harper. You're right about the web server heap space, but the cause of the error was obviously my wrong ognl expression. Does this stack trace begin with a java.lang.OutOfMemoryError as well? Have you tried increasing the heap space size for your Web Server? Just a thought . . . Regards, David Hernandez -- View this message in context: http://www.nabble.com/-S2--Beans-list-in-Dynamic-form-and-ParametersInterceptor-problem-tp15016850p15027374.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]