• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Populate data into Bean nested in ActionForm

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I�m having problems populating the data into a JavaBean nested inside an ActionForm.

The form bean:


The �Customer� JavaBean:


I can access these fields in my JSP pages fine (using struts nested tags), but how do I populate the �customerNumber� via the �CustomerForm� � this is probably quite simple, but it is totally evading me!

My submit function looks like:


The Action Class looks like:


I can display the �select� button fine, along with the customer numbers, addresses etc, but I want to pass the customerNumber into the next form; all my attempts show the �CustomerForm to be null, but I can see the customerNumber in the parameter printout:


Any help would be most appreciated.

Many thanks
As
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, your CustomerForm must Extend ActionForm if you expect Struts to populate it.

Secondly, this page obviously displays a number of customers on a single page. This is fine for output only, but when you want to input customer data from one or more of the customers, you must tell struts which customer you're working with. As you've coded it now, there's no way of telling.

I'd suggest reading this link on using indexed properties in Struts. By following the principles it outlines, you will hopefully be able to reconstruct your CustomerForm bean to handle multiple customers, and code the JSP to tell which customer you're operating on at any given time.

Try refactoring your application to conform to the principles in the link, and if you still have problems, let us know, and we'll help you solve the problems.

Also, Property names should always start with a lower-case letter, so "Customer.xxxx" is not going to work. It has to be "customer.xxxx"

One other note: When you're first starting to use indexed properties, it's much easier to put your ActionForm in session scope. As you get more used to them, you can try putting them in request scope and using "lazy initialization" to recreate the list of beans.
[ June 12, 2006: Message edited by: Merrill Higginson ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic