Struts Presentation with custom objects?

Discussion in 'Java' started by Scott Phelps, Jun 15, 2005.

  1. Scott Phelps

    Scott Phelps Guest

    If I have a vector of custom objects... how can I make struts auto populate
    those objects with checkboxes?

    ie

    class myObject{
    Integer id;
    checked boolean;
    }



    class myActionForm{
    Vector myList = new Vector();
    }


    myList will contain mulitable myObjects.... or am I approaching this wrong?

    Thanks
    Scott Phelps, Jun 15, 2005
    #1
    1. Advertising

  2. Scott Phelps

    Wendy Smoak Guest

    "Scott Phelps" <> wrote

    > If I have a vector of custom objects... how can I make struts auto

    populate
    > those objects with checkboxes?
    >
    > myList will contain mulitable myObjects.... or am I approaching this

    wrong?
    >


    Both your form and your object need to be JavaBeans. Struts uses BeanUtils
    to populate the form, and it expects to see properly named get/set methods.

    Make sure you understand how checkboxes work from an HTML perspective--
    unchecked checkboxes are NOT successful form elements and will not be
    present in the request. If your form is in session scope, you'll need to
    manually reset the checkboxes to false/off.

    If all you're trying to do is get a list of IDs, a String[] will work fine.
    (The boolean is implied... true if the ID is in the array, false if not.)

    If you really need that object (maybe it has other properties?) then take a
    look at indexed properties.
    http://struts.apache.org/faqs/indexedprops.html

    --
    Wendy Smoak
    Wendy Smoak, Jun 15, 2005
    #2
    1. Advertising

  3. Scott Phelps

    Scott Phelps Guest

    "Wendy Smoak" <> wrote in message
    news:d8phio$d54$...
    > "Scott Phelps" <> wrote
    >
    >> If I have a vector of custom objects... how can I make struts auto

    > populate
    >> those objects with checkboxes?
    >>
    >> myList will contain mulitable myObjects.... or am I approaching this

    > wrong?
    >>

    >
    > Both your form and your object need to be JavaBeans. Struts uses
    > BeanUtils
    > to populate the form, and it expects to see properly named get/set
    > methods.
    >
    > Make sure you understand how checkboxes work from an HTML perspective--
    > unchecked checkboxes are NOT successful form elements and will not be
    > present in the request. If your form is in session scope, you'll need to
    > manually reset the checkboxes to false/off.
    >
    > If all you're trying to do is get a list of IDs, a String[] will work
    > fine.
    > (The boolean is implied... true if the ID is in the array, false if not.)
    >
    > If you really need that object (maybe it has other properties?) then take
    > a
    > look at indexed properties.
    > http://struts.apache.org/faqs/indexedprops.html
    >
    > --
    > Wendy Smoak
    >


    Yea the reason I have that obeject is because it is directly related to how
    castor pulls and pushes the object to the database.
    Scott Phelps, Jun 15, 2005
    #3
    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. Katie Wright
    Replies:
    8
    Views:
    4,200
    Andrea Desole
    Jan 7, 2005
  2. Jason Us
    Replies:
    0
    Views:
    966
    Jason Us
    Oct 4, 2003
  3. dan
    Replies:
    25
    Views:
    1,312
    Uncle Bob (Robert C. Martin)
    Oct 28, 2003
  4. Universe
    Replies:
    1
    Views:
    468
    Universe
    Oct 24, 2003
  5. 7stud
    Replies:
    11
    Views:
    667
    Dennis Lee Bieber
    Mar 20, 2007
Loading...

Share This Page