[Struts] Nested beans and getting the selected item value in a drop down form

J

jgalzic

I have a form with a bean that has nested beans and I'm having trouble
putting a specific value into a form's 'option' value attribute. The
final html would look
something like:

<select name = "customers">
<option value="cust1000">Jon Doe</option>
<option value="cust2000">Jeff Newworth</option>
<option value="cust3000">Amy Madigan</option>
</select>

The ActionForm contains the bean with nested beans and the error mesage
I get from Tomcat is "Cannot find bean under name customer".

My form and bean classes are defined as:

public CustomerFormBean extends ActionForm
{
CustomerBase getCustomerBase() { return customerBase; }
private CustomerBase customerBase;
}

public class CustomerBase

{
public Object[] getCustomers() { return customers.toArray(); }
private ArrayList customers;
}

public class Customer
{
public String getName() { return name; }
public String getId() { return id; }


}

My jsp code looks like this:

<nested:form action='CustomerAction.do'>
<html:select property="selectedCustomer">

<nested:nest property="customerBase">

<nested:eek:ptions collection="customers" name="customer"
property="id"/>
</nested:nest>
</html:select>

</nested:form>


What am I doing wrong here?

I'd also like to find which out the selected Index of the drop down and
send it back during the submit. How can I do that?

Thanks,
Justin
 
A

Andrew Thompson

I'd also like to find which out the selected Index of the drop down and
send it back during the submit. How can I do that?

Exactly the same way you would do it in pure HTML.
Define a <form> element. Crack how to do it in HTML
and you are 99% there.
 
R

Roedy Green

Exactly the same way you would do it in pure HTML.
Define a <form> element. Crack how to do it in HTML
and you are 99% there.

The HTML cheat sheet will explain the basics. You can figure out
most of what you need to know by using a packet sniffer and watching
what the browser does.

See http://mindprod.com/jgloss/htmlcheat.html#FORMS

http://mindprod.com/jgloss/packetsniffer.html

The CGI entry in the Java glossary and the books it recommends will
also help.
http://mindprod.com/jgloss/cgi.html
 

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