【问题标题】:Nesting spring form tags with <c:if> tags使用 <c:if> 标签嵌套 spring 表单标签
【发布时间】:2013-07-06 03:57:58
【问题描述】:

我当前的 jsp 包含一些像这样的单选按钮:

<input type="radio_1" value="1" id="radio_1"
<c:if test="${account!=1}">disabled</c:if> 
<c:if test="${account==1 && radio_1=='1'}">checked</c:if>/>

我需要将它转换为 spring 框架的表单标签,以便我可以将它绑定到模型 bean。这样做的全部目的是将错误消息绑定到字段。所以我将它转换为弹簧形式标签 像这样的:

<form:radiobutton path="radio_1" value="1" 
<c:if test="${account!=1}">disabled</c:if>
<c:if test="${account==1 && radio_1=='1'}">checked</c:if>/>

但似乎我们不能像 HTML 标签那样嵌套表单标签所以我收到错误消息“未终止的标签”。 但我需要附加这些标签,并且不希望更改原始功能。 我们有其他选择吗?

【问题讨论】:

    标签: forms tags


    【解决方案1】:

    不要只在 disable 属性上使用 c:if,而是在单选按钮标签上使用它

    <c:if test="${account!=1}">
      <form:radiobutton path="radio_1" value="1" disabled/>
    </c:if>
    
    <c:if test="${account==1 && radio_1=='1'}">
      <form:radiobutton path="radio_1" value="1" checked/>
    </c:if>
    
    <c:if test="${account==1 && radio_1!='1'}">
     <form:radiobutton path="radio_1" value="1" />
    </c:if>
    

    <c:choose>
      <c:when test="${account!=1}">
          <form:radiobutton path="radio_1" value="1" disabled/>            
      </c:when>
      <c:when test="${account==1 && radio_1=='1'}">
          <form:radiobutton path="radio_1" value="1" checked/>    
      </c:when>
      <c:otherwise>
          <form:radiobutton path="radio_1" value="1" />                          
      </c:otherwise>
    </c:choose> 
    

    【讨论】:

      猜你喜欢
      • 2011-05-30
      • 1970-01-01
      • 2011-06-03
      • 2011-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      相关资源
      最近更新 更多