Struts 2: Returning a list to a s:select

Discussion in 'Java' started by Rich, Jul 4, 2007.

  1. Rich

    Rich Guest

    I am trying to populate a s:select drop down using a list. I am new
    to all of this so I am having some trouble.

    There is a example for populating a select using a list on this page:

    http://struts.apache.org/2.0.8/docs/select.html

    I was wondering what:

    list="petDao.pets"
    listKey="id"
    listValue="name"

    are referring to?

    Is petDao a java bean? Is it an action? How do you set it up on the
    page? What is pets? Does it refer to petDao.getPets? what does it
    return? What do id and name refer to? Does getPets return a list of
    objects that contain the fields name and id which have the getters and
    setters for those fields?

    Sorry if this is posted in the wrong forum. This is the only group I
    found when I searched for struts 2.
    Rich, Jul 4, 2007
    #1
    1. Advertising

  2. Rich wrote:

    > Is petDao a java bean?


    Probably a DAO (Data Access Object), producing a Collection from a database.

    Is it an action?

    No.

    How do you set it up on the page?

    It's presumably imported as a bean, e.g. with <jsp:useBean .../>

    Note this is not a particularly good way of doing it in anything other
    than a sample. The view is accessing the model directly in MVC parlance.
    Read up on MVC.

    What is pets?

    It's shorthand for the getPets() method in petDAO.

    Does it refer to petDao.getPets?

    Yes. You are one step ahead of me.

    what does it return?

    A Collection of Pets.

    What do id and name refer to?

    ID is what gets returned in the POST when you've selected that element
    and submitted the form. Name is what is displayed for that element.

    Does getPets return a list of objects that contain the fields name and
    id which have the getters and
    setters for those fields?

    Yes.

    Why do you ask so many questions?

    A. I'm learning Struts. It's my job. :)

    --
    Regards,

    Richard
    Richard Senior, Jul 7, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    11
    Views:
    661
    Christos Georgiou
    May 2, 2006
  2. Shane Geiger
    Replies:
    4
    Views:
    381
    bullockbefriending bard
    Mar 25, 2007
  3. Pranjal Jain
    Replies:
    3
    Views:
    156
    saras
    Apr 10, 2008
  4. Dan Thomas
    Replies:
    0
    Views:
    273
    Dan Thomas
    Feb 2, 2011
  5. palmiere
    Replies:
    1
    Views:
    396
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page