Hallejulah!!

Thanks Dan.

I could not get the session scope on the form bean and logic:iterate tag to
work first go so tried the LazyUtils option. Also changed from using an
array to a List. Works a treat.

My application now does the following.
1. Action reads list of data from database and displays on page. NB The
database replaces a Property file as we are moving to a clustered
environment.
2. User change values and submit.
3. Struts action class updates database.

Sue - It is toasty warm here in Oz.


-----Original Message-----
From: Daniel Bl�zquez [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 16 December 2003 7:26 PM
To: RALPH ROPER
Subject: Re: [struts-nested] BeanUtils.populate exception


Yes, solved with the help of Arron Bates (http://www.keyboardmonkey.com)

The whole thread is in this message, however, if you prefer to read it one
by one, you can search in the mail archive my name or the
subject:

[struts-nested] BeanUtils.populate exception


Important steps:
[read whole thread for more info]

 - Use List setters (instead of more problematic Object[] setters)

   public void setMonkeys(List newMonkeys){
      this.monkeys = newMonkeys;
   }

   public List getMonkeys(){
      return monkeys;
   }

- Use struts-action session scope forms to avoid using LazyLists

  Both the action that shows the form and the action that processess it have
to have session scope forms

Daniel


----- Original Message -----
From: "Arron Bates" <[EMAIL PROTECTED]>
To: "Daniel Bl�zquez" <[EMAIL PROTECTED]>
Sent: Thursday, December 04, 2003 12:49 PM
Subject: Re: Fw: [struts-nested] BeanUtils.populate exception


> Daniel,
>
> I don't know the specifics of having a long primitive as the value for
Age,
> but what a lot of people do is to have a String property handle the input
for
> the application (because it can accept no number values), to which they
> validate is a number before confinuing. One thing I do a fair bit of, is
to
> have the String property, but the rest of the application can use a
converter
> property. eg:
>
>   private String strAge = null;
>
>   public String getAge() { return strAge; }
>   public void setAge(String newAge) { this.strAge = newAge; }
>
>   public long getAgeLong() { return Long.parseLong(strAge); }
>
>
> ...this way, Struts can always set a string with the "age" property, and
my
> application can use the handier "getAgeLong" method.
>
>
> Regarding my running monkey examples, they use the session scope. Simply
> because it was more work to hook up a database etc. And, getting the
indexes
> working with the session scope was much harder. That is, until enough
people
> complained that my example didn't show how to use the request scope for
> nesting beans that I wrote the LazyList/LazyMap utilities. The examples
work
> simply because the arrays are always in memory, and Struts is nevery
trying to
> populate a zero sized array. Which is what the LazyList prevents, by
growing
> to meet the index demand.
>
>
> For your team bean, try setting your monkey's property to this...
>
>   public void setMonkeys(List newMonkeys){
>      this.monkeys = newMonkeys;
>   }
>
>   public List getMonkeys(){
>      return monkeys;
>   }
>
> ...just set and get lists. The latest Struts can handle this no problems,
and
> lets the lazy list work its magic. Otherwise you're back to array problems
again.
>
> Give that a try and see how it goes.
>
>
> Arron.
>
>
>
> > Arron:
> >
> > First of all, thank you for giving you personal email! ;o
> >
> > > What's the property that it's failing on?... is it the monkeys[i]
> > property?...
> >
> > Yes, it is the monkeys[i] property. If I delete the "age" and the select
> > "size", works fine
> >
> > > Moving to session scope would mean you don't have to use the LazyList.
The
> > > LazyList was devised to help people keep beans that use indexed
properties out
> > > of the session. But if you've put the beans into the session, then
indexed
> > > problems shouldn't happen due to pre-population.
> >
> > Sure!! but i've tried every advice i found in the mail-archive...
> > and every combinatory of those advices ;) How do you do in
> > keyboardmonkey examples for not using LazyLists?
> >
> > > Can you show me the code of the bean for this property?...
> >
> > the involved Form Bean MonkeyTeamForm
> > -----------------------------------------------------
> > public class MonkeyTeamForm extends ValidatorForm implements
Serializable{
> >
> >   private List monkeys = ListUtils.lazyList(new ArrayList(), new
> > MonkeyFactory());  private String teamName;
> >
> >   public void setMonkeys(Object[] newMonkeys){
> >
> >     // I tried too to initialize "monkeys" as a lazy list here too
> >     for (int i = 0; i < newMonkeys.length; i++){
> >       monkeys.add(newMonkeys[i]);
> >     }
> >   }
> >
> >   public Object[] getMonkeys(){
> >     return monkeys.toArray();
> >   }
> >
> >   public void setTeamName(String newTeamName){
> >     teamName = newTeamName;
> >   }
> >
> >   public String getTeamName(){
> >     return teamName;
> >   }
> >
> >   [many more getters and setters that works ok]
> >
> >   public void reset(ActionMapping mapping, HttpServletRequest
> > request){    tecnologias = ListUtils.lazyList(new ArrayList(), new
> > MonkeyFactory());  }
> >
> >   public void reset(){
> >     tecnologias = ListUtils.lazyList(new ArrayList(), new
> > MonkeyFactory());  } }
> > ----------------------------------------------------
> >
> > The monkey class (Monkey Team contains "Monkey"s)
> > ----------------------------------------------------
> > public class Monkey implements Serializable {
> >   private String name;
> >   private long age; [ITS A PROBLEM TO BE "LONG"?]
> >   private String size;
> >
> >   public void setTeamName(String newTeamName){
> >     teamName = newTeamName;
> >   }
> >   public String getTeamName(){
> >     return teamName;
> >   }
> >   public void setAge(long newAge){
> >     age = newAge;
> >   }
> >   public long getAge(){
> >     return age;
> >   }
> >   public void setSize(String newSize){
> >     size = newSize;
> >   }
> >
> >   public String getSize(){
> >     return size;
> >   }
> > }
> > ---------------------------------------------------
> >
> > The jsp form (MonkeyTeamForm) : (very similar to nested-tutorial "monkey
> > with bananas")
> > ----------------------------------------------------
> > <nested:form action="updateTeam">
> >   <nested:write property="teamName"/>
> >   [many more simple selects and texts boxes]
> >
> >   <nested:iterate property="monkeys">
> >    <nested:write property="name"/>
> >    <nested:text property="age" size="10"/>
> >
> >    <nested:select property="size">
> >     <nested:options property="../sizesList"/>
> >    </nested:select>
> >
> >   </nested:iterate>   [if I delete "age" and "size" boxes, n.p.]
> >
> > </nested:form>
> > -----------------------------------------------------
> >
> > big-big Thank you
> >
> > Daniel
> >
> > ----- Original Message -----
> > From: "Arron Bates" <[EMAIL PROTECTED]>
> > To: "Daniel Bl�zquez" <[EMAIL PROTECTED]>
> > Sent: Thursday, December 04, 2003 5:02 AM
> > Subject: Re: [struts-nested] BeanUtils.populate exception
> >
> > > Daniel,
> > >
> > > What's the property that it's failing on?... is it the monkeys[i]
> > property?...
> > > Can you show me the code of the bean for this property?...
> > >
> > > Moving to session scope would mean you don't have to use the LazyList.
The
> > > LazyList was devised to help people keep beans that use indexed
properties
> > out
> > > of the session. But if you've put the beans into the session, then
indexed
> > > problems shouldn't happen due to pre-population.
> > >
> > > This problem would still exist even if you used the indexed tags.
> > >
> > >
> > > Arron.
> > >
> > >
> > >
> > > > I have done rigth now a few more things but I still have the
problem:
> > > >
> > > > - I have set the scope of the action to "session"
> > > >
> > > > - I have implemented the reset() method, instantiating collectiong
> > > > using a LazyList
> > > >
> > > > Maybe its recommendable to switch to Indexed properties? i only
> > > > wanted to do in the same way as Arron's monkey tree -so simple, and
> > > > cute-...
> > > >
> > > > but nothing works! :(
> > > >
> > > > Any ideas please?
> > > >
> > > > ----- Original Message -----
> > > > From: "Daniel Bl�zquez" <[EMAIL PROTECTED]>
> > > > To: <[EMAIL PROTECTED]>
> > > > Sent: Tuesday, December 02, 2003 5:55 PM
> > > > Subject: [struts-nested] BeanUtils.populate exception
> > > >
> > > > > Hi,
> > > > >
> > > > > I have been dealing with struts-nested taglibs for a few days
(with
> > the
> > > > > unestimable help from Arron Bates in
http://www.keyboardmonkey.com)
> > and
> > > > with
> > > > > the great amount of messages of this topic in the mailing list.
But I
> > > > still
> > > > > have the next problem:
> > > > >
> > > > > javax.servlet.ServletException: BeanUtils.populate
> > > > >   at org.apache.struts.util.RequestUtils.populate
> > RequestUtils.java:1254)
> > > > >
> > > > > (no extra info about ArrayIndexOutOfBounds or a more detailed
> > exception)
> > > > >
> > > > > when submitting a form that uses a nested collection of objects.
Each
> > > > object
> > > > > is showing in the form a <select> and a <input text> box (as a
form
> > > > showing
> > > > > monkeys, each monkey with a box for age and a <select> for size).
> > > > >
> > > > > <nested.form action="xxxx">
> > > > >
> > > > >   <nested:iterate property="monkeys">
> > > > >
> > > > >     <nested:write property="name"/>
> > > > >     <nested:text property="age" size="10"/>
> > > > >     <nested:select property="size">
> > > > >       <nested:options property="../sizesList"/>
> > > > >     </nested:select>
> > > > >
> > > > >   </nested:iterate>
> > > > >
> > > > > </nested.form>
> > > > >
> > > > > The form also has many more properties (including checkboxes and
> > simple
> > > > > selects) but these ones work correctly.
> > > > >
> > > > > Things I have already done:
> > > > >
> > > > > -- Initialize involved property according to thread
> > > > >
> > > >
> >
http://nagoya.apache.org/eyebrowse/[EMAIL PROTECTED]
> > > > > pache.org&by=thread&from=240019
> > > > > (thanks Arron again and Brandon)
> > > > >
> > > > > -- provide setter in the form for the nested property with the
> > signature:
> > > > > public void setMonkeys(Object[] newMonkeys)
> > > > >
> > > > > -- provide setter in nested monkey object for the size
> > > > > public void setSize(String newSize)
> > > > >
> > > > > I am really frustated because 'cant see what I am doing wrong!,
any
> > help
> > > > > will be very appreciated
> > > > >
> > > > > TIA,
> > > > > Daniel

________________________________________________________
NOTICE
The information in this email and or any of the attachments may contain;
a. Confidential information of Credit Union Services Corporation (Australia) Limited 
(CUSCAL) or third parties; and or
b. Legally privileged information of CUSCAL or third parties; and or
c. Copyright material of CUSCAL or third parties.
If you are not an authorised recipient of this email, please contact CUSCAL 
immediately by return email or by telephone on 61-2-8299 9000 and delete the email 
from your system.
We do not accept any liability in connection with computer virus, data corruption, 
interruption or any damage generally as a result of transmission of this email.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to