Announcement Announcement Module
Collapse
No announcement yet.
binding object properties to radio buttons Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • binding object properties to radio buttons

    In my application JSP page, I have bound numerous JSP components to Java object properties using spring bind tag. The one I am having difficulty with is radio buttons.

    By debugging my custom controller, I have found that when my jsp form is submitted, the request parameters does not contains the 'reportSeverity' parameter (bound to the radio button) and therefore database value for the 'severity' column is not updated.

    I manually updated the 'severity' column data in the database to "I". Now, when the jsp is rendered, the correct radio button appears selected.

    So my question is why is the value not bound on a submit. What am I doing wrong

    My jsp is as follows:
    <%@ include file="/WEB-INF/jsp/include.jsp" %>

    <b>Severity</b><br>
    <table border="1" width="100%" rules="rows">
    <tr>
    <td width="15%">

    <spring:bind path="command.reportSeverity">
    <input name="severity" type="radio" value="N"
    <c:if test="${status.value == 'N'}">checked</c:if>
    <c:if test="${!empty readOnly}">readonly</c:if>
    >Critical
    </spring:bind>


    </td>
    <td>
    <%@ include file="/WEB-INF/jsp/severity_text_critical.jsp" %>
    </td>
    </tr>

    <tr>
    <td>

    <spring:bind path="command.reportSeverity">
    <input name="severity" type="radio" value="I"
    <c:if test="${status.value == 'I'}">checked</c:if>
    <c:if test="${!empty readOnly}">readonly</c:if>
    >Normal
    </spring:bind>


    </td>
    <td>
    <%@ include file="/WEB-INF/jsp/severity_text_normal.jsp" %>
    </td>
    </tr>
    </table>

  • #2
    I realized what my mistake was.

    The name on the input tag has to match the name of the property of the object.

    It started working once I changed my spring bind tag to be:

    <spring:bind path="command.reportSeverity">
    <input name="<c: out value="${status.expression}"/>" type="radio" value="N"
    <c:if test="${status.value == 'N'}">checked</c:if>
    <c:if test="${!empty readOnly}">readonly</c:if>
    >Critical
    </spring:bind>

    Comment


    • #3
      spring:bind to radio buttons

      Thanks for answering your own question. I am also having difficulty binding to a radio button on a JSP page. Could you please include the object structure (Class showing the bindable property) that that Spring is binding to? I am still unsure of the bind path and input name values in my case. Alternately, I can submit a new post with my own details, but it seems like you already have a working example. Thanks.

      Comment

      Working...
      X