Results 1 to 6 of 6

Thread: How to bind with the Radio button?

  1. #1
    Join Date
    Sep 2005
    Posts
    13

    Default How to bind with the Radio button?

    I have a class wich has a boolean field. I want to bind it with a radio button. I writ the code in my jsp file like this:
    Code:
    <spring&#58;bind path="SomeOne.gender">
           Male<input type="radio" name="gender" value="Male" > 
           Female<input type="radio" name="gender" value="Female"> 
    </spring&#58;bind>
    But it dosn't work, nothing will be shown. If I remove the spring:bind from the code, the radio button can be shown. I think I made a mistake in the code, who can tell me how to correct it? Thanks

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Could you post the HTML that's being generated. My guess is the spring:bind tags are still in there (in other words: the tag library wasn't declared in your jsp file).

    rgds,
    alef
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Sep 2005
    Posts
    13

    Default

    Thanks.
    The html is simple:
    Code:
    <html>
        <body>
        </body>
    </html>
    There's nothing else.
    In fact, I have two problems in my app.
    My app is a little bit complicated, let me use a simple example to describe the problems.
    eg: I have a list of customers, each customer has a field of gender.
    I want to generate a form automatically. The form can list all(or part) the customers with its gender field. And I want to edit each customer's gender with two radio button Male or Female. I use SimpleFormController to return the ModelAndView object.
    Here is my problems:
    1. What kind of variable should I use when I use return new ModelAndView. Return the ModelAndView( "viewName", "variableName", CustomerList ) or ModelAndView( "viewName", CustomerMap ). The CustomerMap is a map, the customer's id or name is the key, and the customer object is the value.
    2. How to bind the radio buttons with each Customer object's gender field?

    I can use ModelAndView( "viewName", "variableName", CustomerList ) to create a table(not a form), but without the <spring:bind> tag. I just use <c:forEach> to list all the customers in the CustomerList. But by now, I don't know how to bind each Cusomer with the form field.

    I don't know if I have described my questions clear. :P

    regards

  4. #4
    Join Date
    Sep 2005
    Posts
    13

    Default

    I find that the map returned throw ModelAndView can not be passed to the jsp file. So the page is just leave blank. Still looking for the reason.

  5. #5
    Join Date
    Aug 2005
    Posts
    10

    Default

    Not sure if this will help, but... If you have a boolean property, and you want to bound value to be matched, the values of the radio buttons should not be 'Male' and 'Female' but 'true' and 'false'...

  6. #6
    Join Date
    Sep 2005
    Posts
    13

    Default

    Yes, you are right. Thanks.
    Not sure if this will help, but... If you have a boolean property, and you want to bound value to be matched, the values of the radio buttons should not be 'Male' and 'Female' but 'true' and 'false'...

Similar Threads

  1. Replies: 3
    Last Post: Oct 19th, 2005, 03:32 PM
  2. Replies: 3
    Last Post: Aug 26th, 2005, 01:36 AM
  3. Button woes
    By Thomas Dudziak in forum Web Flow
    Replies: 4
    Last Post: Jul 23rd, 2005, 07:35 AM
  4. Replies: 1
    Last Post: May 16th, 2005, 08:48 PM
  5. Why radio button is not working
    By simon_ship in forum Web
    Replies: 2
    Last Post: Feb 16th, 2005, 11:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •