2013-04-03 93 views
0

我现在的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。这样做的全部目的是将错误消息绑定到字段。所以,我把它转换到Spring表单标签 事情是这样的:

<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标签,所以我得到错误信息“未结束的标签”。 但我需要附加那些标签,并且不想要改变原始功能。 我们有一些替代方案吗?

回答

2

而不是使用的C:如果只在禁用属性,在单选按钮标签使用它,以及

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