You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Huw Jones <ja...@btclick.com> on 2003/03/13 18:10:51 UTC

ArrayList set method in nested bean- confusion

I have a nested bean where beanA (courseBean) stores an ArrayList of bean2
(event).

I can dump out the ArrayList no problem but I can't seem to make the set
method run. So here are some code snippits.

JSP

<logic:notEmpty name="courseEventForm" property="courseBean.events">
 <html:text name="courseEventForm" property='<%= "courseBean.events[" + cnt
+ "].startDate" %>' size="12" maxlength="12"/>
</logic:iterate>

So produces HTML
 <input type="text" name="courseBean.events[0].startDate" maxlength="12"
size="12" value="">
 <input type="text" name="courseBean.events[1].startDate" maxlength="12"
size="12" value="">

etc

In formbean

 public CourseEventForm () {
      this.course = new Course(this);
   }
  etc


In my Course Bean set/get methods

public Course (CourseEventForm parent) {
       this.parentBean = parent;
       this.eventList = new ArrayList();
}
public Object[] getEvents() {
     return eventList.toArray();
}

public void setEvents(Object[] newEventList) {
  this.eventList = new ArrayList();
  for (int i=0; i<newEventList.length; i++) {
      this.eventList.add(newEventList[i]);
  }
}


I'm basically trying to implement an add button which adds another instance
of an event in the form but
I get array out of bounds error. If the set method ran it should increase
the array length as it needs - I'm thinking.

Any one know what's going wrong here - do I need another method in the
Course Bean

Thanks

Huw Jones



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: ArrayList set method in nested bean- confusion

Posted by Huw Jones <ja...@btclick.com>.
yes the code was ok - in fact the issue was the fact the formBean was in
request scope in struts-config.xml - changing it to session sorted it out

-----Original Message-----
From: Mark Lowe [mailto:mlowe@officinedigitali.it]
Sent: 13 March 2003 17:15
To: Struts Users Mailing List
Subject: Re: ArrayList set method in nested bean- confusion


should be fine..  to add a new row you can do so using the set's on the
formBean in you action class...



Giovedì, 13 mar 2003, alle 18:10 Europe/Rome, Huw Jones ha scritto:

> I have a nested bean where beanA (courseBean) stores an ArrayList of
> bean2
> (event).
>
> I can dump out the ArrayList no problem but I can't seem to make the
> set
> method run. So here are some code snippits.
>
> JSP
>
> <logic:notEmpty name="courseEventForm" property="courseBean.events">
>  <html:text name="courseEventForm" property='<%= "courseBean.events["
> + cnt
> + "].startDate" %>' size="12" maxlength="12"/>
> </logic:iterate>
>
> So produces HTML
>  <input type="text" name="courseBean.events[0].startDate"
> maxlength="12"
> size="12" value="">
>  <input type="text" name="courseBean.events[1].startDate"
> maxlength="12"
> size="12" value="">
>
> etc
>
> In formbean
>
>  public CourseEventForm () {
>       this.course = new Course(this);
>    }
>   etc
>
>
> In my Course Bean set/get methods
>
> public Course (CourseEventForm parent) {
>        this.parentBean = parent;
>        this.eventList = new ArrayList();
> }
> public Object[] getEvents() {
>      return eventList.toArray();
> }
>
> public void setEvents(Object[] newEventList) {
>   this.eventList = new ArrayList();
>   for (int i=0; i<newEventList.length; i++) {
>       this.eventList.add(newEventList[i]);
>   }
> }
>
>
> I'm basically trying to implement an add button which adds another
> instance
> of an event in the form but
> I get array out of bounds error. If the set method ran it should
> increase
> the array length as it needs - I'm thinking.
>
> Any one know what's going wrong here - do I need another method in the
> Course Bean
>
> Thanks
>
> Huw Jones
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: ArrayList set method in nested bean- confusion

Posted by Mark Lowe <ml...@officinedigitali.it>.
should be fine..  to add a new row you can do so using the set's on the 
formBean in you action class...



Giovedì, 13 mar 2003, alle 18:10 Europe/Rome, Huw Jones ha scritto:

> I have a nested bean where beanA (courseBean) stores an ArrayList of 
> bean2
> (event).
>
> I can dump out the ArrayList no problem but I can't seem to make the 
> set
> method run. So here are some code snippits.
>
> JSP
>
> <logic:notEmpty name="courseEventForm" property="courseBean.events">
>  <html:text name="courseEventForm" property='<%= "courseBean.events[" 
> + cnt
> + "].startDate" %>' size="12" maxlength="12"/>
> </logic:iterate>
>
> So produces HTML
>  <input type="text" name="courseBean.events[0].startDate" 
> maxlength="12"
> size="12" value="">
>  <input type="text" name="courseBean.events[1].startDate" 
> maxlength="12"
> size="12" value="">
>
> etc
>
> In formbean
>
>  public CourseEventForm () {
>       this.course = new Course(this);
>    }
>   etc
>
>
> In my Course Bean set/get methods
>
> public Course (CourseEventForm parent) {
>        this.parentBean = parent;
>        this.eventList = new ArrayList();
> }
> public Object[] getEvents() {
>      return eventList.toArray();
> }
>
> public void setEvents(Object[] newEventList) {
>   this.eventList = new ArrayList();
>   for (int i=0; i<newEventList.length; i++) {
>       this.eventList.add(newEventList[i]);
>   }
> }
>
>
> I'm basically trying to implement an add button which adds another 
> instance
> of an event in the form but
> I get array out of bounds error. If the set method ran it should 
> increase
> the array length as it needs - I'm thinking.
>
> Any one know what's going wrong here - do I need another method in the
> Course Bean
>
> Thanks
>
> Huw Jones
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org