Results 1 to 4 of 4

Thread: Radiobutton with multiple conditions

  1. #1

    Default Radiobutton with multiple conditions

    I have a question concerning the form-tag. I have a few radio buttons and I want one to be checked. The problem is that value isn't enough, because 1 radio button must be checked when there 2 conditions are met.

    1 radiobutton must be selected when the value is equal to a certain value and a boolean in the pageScope is true.

    Is there a way to do this?

    Something like this:
    Code:
    <form:radiobutton disabled="true" path="known" value="??? || ???" />

  2. #2
    Join Date
    Apr 2008
    Location
    Singapore
    Posts
    83

    Default

    I think you can't do it with in the <form:radiobutton /> tag.

    you will have to set the value for the property known in your formBackingObject method.

    lets say you have the following in your view.

    Code:
    <form:radiobutton disabled="true" path="known" value="foo" />
    to make the radio button appear as selected what you have to do is
    Code:
    yourCommandObject.setKnown("foo");
    in your formBackingObject method.

    so when the property known has the value "foo" it will automatically be selected in your view.

    hope this helps you

  3. #3

    Default

    Bleh, I was hoping for a different solution. I'll have to try another solution for this.

  4. #4
    Join Date
    Apr 2008
    Location
    Singapore
    Posts
    83

    Lightbulb

    well there's another way of doing it. It's without the <form:radiobutton> tag, by using <spring:bind> tag

    Code:
    <spring:bind path="known">
         <input name="${status.expression}" type="radio" value="foo"  <c:if test="${status.value == 'foo'}"> selected</c:if> >
    </spring:bind>
    since you want to check for some other conditions you can try something like:

    Code:
    <spring:bind path="known">
         <c:if test="${status.value=='foo' && myBoolean }">
              <c:set var="selected" value="true"/>
         </c:if>
    
         <input name="${status.expression}" type="radio" value="foo"  <c:if test="${selected}"> checked</c:if> >
    </spring:bind>
    hope this might help you

Posting Permissions

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