Announcement Announcement Module
Collapse
No announcement yet.
How to bind with the Radio button? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Comment


        • #5
          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'...

          Comment


          • #6
            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'...

            Comment

            Working...
            X