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

Discussion in 'Java' started by jgalzic@gmail.com, Oct 1, 2005.

  1. Guest

    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
     
    , Oct 1, 2005
    #1
    1. Advertising

  2. Re: [Struts] Nested beans and getting the selected item value ina drop down form

    wrote:


    > 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.
     
    Andrew Thompson, Oct 1, 2005
    #2
    1. Advertising

  3. Roedy Green Guest

    On Sat, 01 Oct 2005 20:33:51 GMT, Andrew Thompson
    <> wrote or quoted :

    >> 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.


    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
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 2, 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. Stephen Adam
    Replies:
    3
    Views:
    12,147
    Stephen Adam
    Nov 30, 2004
  2. weiwei
    Replies:
    0
    Views:
    1,047
    weiwei
    Jan 5, 2007
  3. jaysch
    Replies:
    0
    Views:
    1,259
    jaysch
    Apr 30, 2011
  4. pardesiya
    Replies:
    7
    Views:
    337
    pardesiya
    May 22, 2007
  5. Replies:
    0
    Views:
    182
Loading...

Share This Page