Struts Presentation with custom objects?

S

Scott Phelps

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
 
W

Wendy Smoak

Scott Phelps said:
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
 
S

Scott Phelps

Wendy Smoak said:
Scott Phelps said:
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

Yea the reason I have that obeject is because it is directly related to how
castor pulls and pushes the object to the database.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top